diff options
author | Eric Hayes <eric@erichayes.net> | 2016-04-02 22:00:06 -0700 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-07-19 18:51:09 +0200 |
commit | c266c7fa18848586cd6ee903cc4c4d4f9049100e (patch) | |
tree | 8fa8d0b2dca828bec6af0ad49855cbb4e69a9e30 /lib/banzai | |
parent | 81e57e783e8882de21d27d9191c09404ed7faca3 (diff) | |
download | gitlab-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')
-rw-r--r-- | lib/banzai/filter/video_link_filter.rb | 42 | ||||
-rw-r--r-- | lib/banzai/pipeline/gfm_pipeline.rb | 1 |
2 files changed, 43 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 diff --git a/lib/banzai/pipeline/gfm_pipeline.rb b/lib/banzai/pipeline/gfm_pipeline.rb index b27ecf3c923..d9edca7046c 100644 --- a/lib/banzai/pipeline/gfm_pipeline.rb +++ b/lib/banzai/pipeline/gfm_pipeline.rb @@ -8,6 +8,7 @@ module Banzai Filter::UploadLinkFilter, Filter::ImageLinkFilter, + Filter::VideoLinkFilter, Filter::EmojiFilter, Filter::TableOfContentsFilter, Filter::AutolinkFilter, |