From 6f99277ebedccf350465cccd6c25674eb1fade51 Mon Sep 17 00:00:00 2001 From: magdev Date: Tue, 12 Dec 2023 01:53:22 +0100 Subject: [PATCH] added video embedd macro --- init.rb | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/init.rb b/init.rb index 23323ac..044b7ee 100644 --- a/init.rb +++ b/init.rb @@ -26,3 +26,43 @@ Redmine::Plugin.register :baupm_core do 'baupm_enable_webapp' => '1' }, :partial => 'settings/baupm_settings' end + +Redmine::WikiFormatting::Macros.register do + desc <<-DESCRIPTION + Embed video attachments + + {{video(attachment.mp4)}} show video with default size 640x360 + {{video(attachment.mp4, width=480, height=320)}} show video with size 480x320 + DESCRIPTION + + macro :video do |obj, args| + @width = args[1].gsub(/\D/,'') if args[1] + @height = args[2].gsub(/\D/,'') if args[2] + @width ||= 640 + @height ||= 360 + attachment = obj.attachments.find_by_filename(args[0]) if obj.respond_to?('attachments') + + if attachment + file_url = url_for( + :only_path => false, + :controller => 'attachments', + :action => 'download', + :id => attachment, + :filename => attachment.filename + ) +out = < + + Your browser does not support the video tag. + +END + else + file_url = args[0].gsub(/<.*?>/, '').gsub(/<.*>/,'') +out = < +END + end + + out.html_safe + end +end