You've already forked baupm-core
added video embedd macro
This commit is contained in:
40
init.rb
40
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 = <<END
|
||||
<video width="#{@width}" height="#{@height}" playsinline controls class="embedded-video">
|
||||
<source src="#{file_url}">
|
||||
Your browser does not support the video tag.
|
||||
</video>
|
||||
END
|
||||
else
|
||||
file_url = args[0].gsub(/<.*?>/, '').gsub(/<.*>/,'')
|
||||
out = <<END
|
||||
<iframe width="#{@width}" height="#{@height}" src="#{file_url}" class="embedded-video"></iframe>
|
||||
END
|
||||
end
|
||||
|
||||
out.html_safe
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user