Skip to content

Commit 9a6592b

Browse files
authored
Merge pull request #48 from FloWalchs/develop
2 parents 8974f4b + 858739c commit 9a6592b

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

lib/wiki_extensions_div_macro.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ module WikiExtensionsDivMacro
1919
Redmine::WikiFormatting::Macros.register do
2020
desc "Displays a <pre><div id=" + '"id_name"' + " class=" + '"' + 'class_name' + '"></pre>' + "\n\n" +
2121
" !{{div_start_tag(id_name)}}" + "'\n" +
22-
" !{{div_start_tag(id_name, class_name)}}"
22+
" !{{div_start_tag(id_name, class_name)}}"+ "'\n" +
23+
" !{{div_start_tag(id_name, class_name, style=background-color: green;)}}"
2324
macro :div_start_tag do |obj, args|
25+
args, options = extract_macro_options(args, :style)
26+
style = options[:style]
2427
o = '<div>' if args.length == 0
2528
o = '<div id="' + h(args[0].strip) + '">' if args.length == 1
2629
o = '<div id="' + h(args[0].strip) + '" class="' + h(args[1].strip) + '">' if args.length == 2
30+
o = o[0...-1] + ' style="' + h(style) + '">' if style
2731
o.html_safe
2832
end
2933
end
@@ -38,4 +42,3 @@ module WikiExtensionsDivMacro
3842
end
3943
end
4044
end
41-

lib/wiki_extensions_video_macro.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Wiki Extensions plugin for Redmine
2+
# Copyright (C) 2009-2013 Haruyuki Iida
3+
#
4+
# This program is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU General Public License
6+
# as published by the Free Software Foundation; either version 2
7+
# of the License, or (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
18+
module WikiExtensionsVideoMacro
19+
Redmine::WikiFormatting::Macros.register do
20+
desc "Embed video content directly into a webpage \n" +
21+
"with the video html tag \n\n" +
22+
" {{video_tag(source)}}" + "\n" +
23+
" {{video_tag(source, [width, height])}}" + "\n" +
24+
" {{video_tag(source, [width, height, controls autoplay muted loop preload='none' poster='..'])}}\n\n" +
25+
" Parameters:\n" +
26+
" source string: id of attachment or http link (required)\n" +
27+
" width int: sets the widht dimensions of the video player\n" +
28+
" height int: sets the height dimensions\n" +
29+
" parm string: all the different kind of parameters controls are set by default\n\n" +
30+
" Examples:\n" +
31+
" {{video_tag(20)}}\n" +
32+
" ...video empeded tag to the attachment nr 20 with a control pannel, max dimensions widht/resolution \n" +
33+
" {{video_tag(https://samplelib.com/lib/preview/mp4/sample-5s.mp4, 320, 240, controls autoplay muted)}}\n" +
34+
" ...video empeded from a http link, dimension 320x240, with control pannel in autoplay mode and muted"
35+
macro :video_tag do |obj, args|
36+
return nil if args.empty?
37+
38+
attachment = Attachment.find_by(id: h(args[0].strip))
39+
attachment_path = !attachment ? h(args[0].strip) : url_for(controller: 'attachments', action: 'download', id: attachment.id, filename: attachment.filename)
40+
41+
# video html tag
42+
o = '<video src="' + attachment_path + '"'
43+
o += ' width="' + h(args[1].strip) + '"' if args.length >= 2
44+
o += ' height="' + h(args[2].strip) + '"' if args.length >= 3
45+
o += args.length >= 4 ? ' ' + h(args[3].strip) : ' controls'
46+
o += '>'
47+
48+
o.html_safe
49+
end
50+
end
51+
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Wiki Extensions plugin for Redmine
2+
# Copyright (C) 2009-2010 Haruyuki Iida
3+
#
4+
# This program is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU General Public License
6+
# as published by the Free Software Foundation; either version 2
7+
# of the License, or (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
18+
require File.expand_path('../test_helper', __dir__)
19+
20+
class WikiExtensionsMacroVideoTest < ActiveSupport::TestCase
21+
include ApplicationHelper
22+
include ActionDispatch::Assertions::SelectorAssertions
23+
include ERB::Util
24+
25+
def test_video_tag_macro
26+
with_settings :text_formatting => 'textile' do
27+
result = textilizable("{{video_tag(https://samplelib.com/lib/preview/mp4/sample-5s.mp4, 320, 240, controls autoplay muted)}}")
28+
29+
assert_select_in result, 'video[src="https://samplelib.com/lib/preview/mp4/sample-5s.mp4"]'
30+
assert_select_in result, 'video[width="320"]'
31+
assert_select_in result, 'video[height="240"]'
32+
assert_select_in result, 'video[controls]'
33+
assert_select_in result, 'video[autoplay]'
34+
assert_select_in result, 'video[muted]'
35+
end
36+
end
37+
end

0 commit comments

Comments
 (0)