|
| 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 |
0 commit comments