Class: Jekyll::Spaceship::VideoProcessor
- Defined in:
- lib/jekyll-spaceship/processors/video-processor.rb
Constant Summary
Constants inherited from Processor
Processor::DEFAULT_PRIORITY, Processor::PRIORITY_MAP
Instance Attribute Summary
Attributes inherited from Processor
#config, #exclusions, #handled, #logger, #page, #priority, #registers
Instance Method Summary collapse
-
#handle_dailymotion(content) ⇒ Object
Examples:  .
-
#handle_normal_video(content) ⇒ Object
Examples:   .
- #handle_video(content, data) ⇒ Object
-
#handle_vimeo(content) ⇒ Object
Examples:  .
-
#handle_youtube(content) ⇒ Object
Examples:   .
- #on_handle_markdown(content) ⇒ Object
Methods inherited from Processor
#after_exclude, config, #converter, #dispatch, escape_html, exclude, #ext, #filename, #initialize, #initialize_exclusions, #initialize_priority, #initialize_register, #name, #on_handle_html, #on_handle_html_block, #on_handled, #output_ext, #pre_exclude, priority, #process?, register
Constructor Details
This class inherits a constructor from Jekyll::Spaceship::Processor
Instance Method Details
#handle_dailymotion(content) ⇒ Object
Examples:  
51 52 53 54 55 56 57 |
# File 'lib/jekyll-spaceship/processors/video-processor.rb', line 51 def handle_dailymotion(content) handle_video(content, { host: '(https?:)?\\/\\/.*dai.?ly.*', id: '(?<=video\\/|\\/)([a-zA-Z0-9\\_\\-]+)', iframe_url: "https://www.dailymotion.com/embed/video/" }) end |
#handle_normal_video(content) ⇒ Object
Examples:   
18 19 20 21 22 23 |
# File 'lib/jekyll-spaceship/processors/video-processor.rb', line 18 def handle_normal_video(content) handle_video(content, { host: '(https?:)?\\/\\/.*\\/', id: '(.+?\\.(avi|mp4|webm|ogg|ogv|flv|mkv|mov|wmv|3gp|rmvb|asf))', }) end |
#handle_video(content, data) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/jekyll-spaceship/processors/video-processor.rb', line 59 def handle_video(content, data) host = data[:host] return content if content.sub(/#{host}/, '').nil? iframe_url = data[:iframe_url] id = data[:id] url = "(#{host}#{id}\\S*)" title = '("(.*)".*){0,1}' # pre-handle reference-style links regex = /(\[(.*)\]:\s*(#{url}\s*#{title}))/ content.scan regex do |match_data| match = match_data[0] ref_name = match_data[1] ref_value = match_data[2] content = content.gsub(match, '') .gsub(/\!\[(.*)\]\s*\[#{ref_name}\]/, "") end # handle inline-style links regex = /(\!\[(.*)\]\(.*#{url}\s*#{title}\))/ content.scan regex do |match_data| url = match_data[2] id = match_data[4] title = match_data[6] qs = url.match(/(?<=\?)(\S*?)$/) qs = Hash[URI.decode_www_form(qs.to_s)].reject do |k, v| next true if v == id or v == '' end css_id = qs['id'] || "video-#{id}" css_class = qs['class'] || 'video' width = qs['width'] || data[:width] || "100%" height = qs['height'] || data[:height] || 350 frameborder = qs['frameborder'] || 0 style = qs['style'] || 'max-width: 600px' allow = qs['allow'] || "encrypted-media; picture-in-picture" url = URI(iframe_url ? "#{iframe_url}#{id}" : url).tap do |v| v.query = URI.encode_www_form(qs) if qs.size > 0 end html = "<iframe"\ " id=\"#{css_id}\""\ " class=\"#{css_class}\""\ " src=\"#{url}\""\ " title=\"#{title}\""\ " width=\"#{width}\""\ " height=\"#{height}\""\ " style=\"#{style}\""\ " allow=\"#{allow}\""\ " frameborder=\"#{frameborder}\""\ " allowfullscreen>" \ "</iframe>" content = content.gsub(match_data[0], html) self.handled = true end content end |
#handle_vimeo(content) ⇒ Object
Examples:  
40 41 42 43 44 45 46 |
# File 'lib/jekyll-spaceship/processors/video-processor.rb', line 40 def handle_vimeo(content) handle_video(content, { host: '(https?:)?\\/\\/vimeo\\.com\\/', id: '([0-9]+)', iframe_url: "https://player.vimeo.com/video/" }) end |
#handle_youtube(content) ⇒ Object
Examples:   
29 30 31 32 33 34 35 |
# File 'lib/jekyll-spaceship/processors/video-processor.rb', line 29 def handle_youtube(content) handle_video(content, { host: '(https?:)?\\/\\/.*youtu.*', id: '(?<=\\?v\\=|embed\\/|\\.be\\/)([a-zA-Z0-9\\_\\-]+)', iframe_url: "https://www.youtube.com/embed/" }) end |
#on_handle_markdown(content) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/jekyll-spaceship/processors/video-processor.rb', line 7 def on_handle_markdown(content) content = handle_normal_video(content) content = handle_youtube(content) content = handle_vimeo(content) content = handle_dailymotion(content) end |