From c266c7fa18848586cd6ee903cc4c4d4f9049100e Mon Sep 17 00:00:00 2001 From: Eric Hayes Date: Sat, 2 Apr 2016 22:00:06 -0700 Subject: First support of videos in issues, MRs and notes * Registered video MIME types * Currently supporting browser-supported formats with extensions that match the mime type --- lib/banzai/filter/video_link_filter.rb | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lib/banzai/filter/video_link_filter.rb (limited to 'lib/banzai/filter') diff --git a/lib/banzai/filter/video_link_filter.rb b/lib/banzai/filter/video_link_filter.rb new file mode 100644 index 00000000000..0ae885708f7 --- /dev/null +++ b/lib/banzai/filter/video_link_filter.rb @@ -0,0 +1,42 @@ +module Banzai + module Filter + + # HTML Filter that handles video uploads. + + class VideoLinkFilter < HTML::Pipeline::Filter + include ActionView::Helpers::TagHelper + include ActionView::Context + + EXTENSIONS = %w(.mov .mp4 .ogg .webm .flv) + + def call + doc.search('img').each do |el| + if video?(el) + el.replace video_node(el) + end + end + + doc + end + + private + + def video?(element) + EXTENSIONS.include? File.extname(element.attribute('src').value) + end + + # Return a video tag Nokogiri node + # + def video_node(element) + vtag = content_tag(:video, "", { + src: element.attribute('src').value, + class: 'video-js', preload: 'auto', + controls: true + }) + + Nokogiri::HTML::DocumentFragment.parse(vtag) + end + end + + end +end -- cgit v1.2.1