summaryrefslogtreecommitdiff
path: root/lib/banzai/filter
diff options
context:
space:
mode:
authorEric Hayes <eric@erichayes.net>2016-04-02 22:00:06 -0700
committerRémy Coutable <remy@rymai.me>2016-07-19 18:51:09 +0200
commitc266c7fa18848586cd6ee903cc4c4d4f9049100e (patch)
tree8fa8d0b2dca828bec6af0ad49855cbb4e69a9e30 /lib/banzai/filter
parent81e57e783e8882de21d27d9191c09404ed7faca3 (diff)
downloadgitlab-ce-c266c7fa18848586cd6ee903cc4c4d4f9049100e.tar.gz
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
Diffstat (limited to 'lib/banzai/filter')
-rw-r--r--lib/banzai/filter/video_link_filter.rb42
1 files changed, 42 insertions, 0 deletions
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