Class: YouTubeEmbed
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- YouTubeEmbed
- Defined in:
- lib/jekyll-html5-youtube.rb
Instance Method Summary collapse
-
#initialize(tagName, text, tokens) ⇒ YouTubeEmbed
constructor
A new instance of YouTubeEmbed.
- #render(context) ⇒ Object
Constructor Details
#initialize(tagName, text, tokens) ⇒ YouTubeEmbed
Returns a new instance of YouTubeEmbed.
6 7 8 9 |
# File 'lib/jekyll-html5-youtube.rb', line 6 def initialize(tagName, text, tokens) super @text = text end |
Instance Method Details
#render(context) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jekyll-html5-youtube.rb', line 11 def render(context) youtube_url = "#{context[@text.strip]}" if youtube_url[/youtu\.be\/([^*]*)/] @youtube_id = $1 else youtube_url[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\*]*).*/] @youtube_id = $5 end includes_path = File.join Dir.pwd, "_includes", "youtube.html" if File.exist?(includes_path) includes = File.read includes_path site = context.registers[:site] includes = (Liquid::Template.parse includes).render site.site_payload.merge!({"youtube_id" => @youtube_id}) else %Q{<div class='embed-container'>\n<object data="https://www.youtube.com/embed/#{ @youtube_id }"></object>\n</div>} end end |