diff --git a/app/uploaders/uploader_helper.rb b/app/uploaders/uploader_helper.rb index 6d510fe7ddecf073eef6c0ee4eda68e71d8ce9b8..703f78209138d068be0ce79ec23967dae9cf39f0 100644 --- a/app/uploaders/uploader_helper.rb +++ b/app/uploaders/uploader_helper.rb @@ -1,18 +1,19 @@ # Extra methods for uploader module UploaderHelper - IMAGE_EXT = %w(png jpg jpeg gif bmp tiff) - VIDEO_EXT = %w(mov mp4 ogg webm flv) + IMAGE_EXT = %w[png jpg jpeg gif bmp tiff] + # We recommend using the .mp4 format over .mov. Videos in .mov format can + # still be used but you really need to make sure they are served with the + # proper MIME type video/mp4 and not video/quicktime or your videos won’t play + # on IE ≥ 9. + # http://archive.sublimevideo.info/20150912/docs.sublimevideo.net/troubleshooting.html + VIDEO_EXT = %w[mp4 m4v mov webm ogv] def image? extension_match?(IMAGE_EXT) - rescue - false end def video? extension_match?(VIDEO_EXT) - rescue - false end def image_or_video? @@ -20,13 +21,15 @@ module UploaderHelper end def extension_match?(extensions) - if file.respond_to?(:extension) - extensions.include?(file.extension.downcase) - else - # Not all CarrierWave storages respond to :extension - ext = file.path.split('.').last.downcase - extensions.include?(ext) - end + extension = + if file.respond_to?(:extension) + file.extension + else + # Not all CarrierWave storages respond to :extension + File.extname(file.path).delete('.') + end + + extensions.include?(extension.downcase) end def file_storage? diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 4c6de622f17aedc9a91774a9ea9d672e2cffbdeb..cd449b65818fe54a8259e6568f09b64e6c308068 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -9,8 +9,6 @@ Mime::Type.register_alias "text/plain", :patch Mime::Type.register_alias "text/html", :markdown Mime::Type.register_alias "text/html", :md +Mime::Type.register "video/mp4", :mp4, [], [:m4v, :mov] Mime::Type.register "video/webm", :webm -Mime::Type.register "video/ogg", :ogg -Mime::Type.register "video/ogg", :ogv -Mime::Type.register "video/mp4", :mp4 -Mime::Type.register "video/mp4", :m4v +Mime::Type.register "video/ogg", :ogv, [], [:ogg] diff --git a/lib/banzai/filter/video_link_filter.rb b/lib/banzai/filter/video_link_filter.rb index 0ae885708f7098eeca3a226985381fdb524d398a..a8316e72a68d7a9f22ca09e7f50282f61861d1c0 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