diff options
author | Rémy Coutable <remy@rymai.me> | 2016-07-08 19:55:49 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-07-19 19:51:09 +0300 |
commit | 29ea8d09e05d749f0b6a784311aea942f7d2d0f1 (patch) | |
tree | 9326f19dc1a67b3345f2c128f0b1118760fdb094 /lib/banzai | |
parent | 356b2d2bd782289b6130a22531523562514aa7f6 (diff) |
Remove duplication, useless rescue, and avoid using ActionView
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib/banzai')
-rw-r--r-- | lib/banzai/filter/video_link_filter.rb | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/lib/banzai/filter/video_link_filter.rb b/lib/banzai/filter/video_link_filter.rb index 0ae885708f7..a8316e72a68 100644 --- a/lib/banzai/filter/video_link_filter.rb +++ b/lib/banzai/filter/video_link_filter.rb @@ -7,13 +7,9 @@ module Banzai 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 + el.replace(video_tag(doc, el)) if video?(el) end doc @@ -22,19 +18,18 @@ module Banzai private def video?(element) - EXTENSIONS.include? File.extname(element.attribute('src').value) + extension = File.extname(element.attribute('src').value).delete('.') + UploaderHelper::VIDEO_EXT.include?(extension) 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) + def video_node(doc, element) + doc.document.create_element( + 'video', + src: element.attribute('src').value, + class: 'video-js', + controls: true) end end |