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
Class Method Summary collapse
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, #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
Class Method Details
.config ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/jekyll-spaceship/processors/video-processor.rb', line 7 def self.config { 'default' => { 'id' => 'video-{id}', 'class' => 'video', 'width' => '100%', 'height' => 350, 'border' => 0, 'style' => 'max-width: 600px', 'allow' => 'encrypted-media; picture-in-picture', } } end |
Instance Method Details
#handle_dailymotion(content) ⇒ Object
Examples:  
65 66 67 68 69 70 71 |
# File 'lib/jekyll-spaceship/processors/video-processor.rb', line 65 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:   
32 33 34 35 36 37 |
# File 'lib/jekyll-spaceship/processors/video-processor.rb', line 32 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
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/jekyll-spaceship/processors/video-processor.rb', line 73 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 default = self.config['default'] css_id = qs['id'] || default['id'] css_class = qs['class'] || default['class'] width = qs['width'] || data[:width] || default['width'] height = qs['height'] || data[:height] || default['height'] frameborder = qs['frameborder'] || default['border'] style = qs['style'] || default['style'] allow = qs['allow'] || default['allow'] css_id = css_id.gsub('{id}', id) css_class = css_class.gsub('{id}', id) 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:  
54 55 56 57 58 59 60 |
# File 'lib/jekyll-spaceship/processors/video-processor.rb', line 54 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:   
43 44 45 46 47 48 49 |
# File 'lib/jekyll-spaceship/processors/video-processor.rb', line 43 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
21 22 23 24 25 26 |
# File 'lib/jekyll-spaceship/processors/video-processor.rb', line 21 def on_handle_markdown(content) content = handle_normal_video(content) content = handle_youtube(content) content = handle_vimeo(content) content = handle_dailymotion(content) end |