Class: Jekyll::OEmbedPlugin
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::OEmbedPlugin
- Defined in:
- lib/jekyll_oembed.rb
Instance Method Summary collapse
- #error_message(url) ⇒ Object
- #html_output(result) ⇒ Object
-
#initialize(tag_name, text, tokens) ⇒ OEmbedPlugin
constructor
A new instance of OEmbedPlugin.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, text, tokens) ⇒ OEmbedPlugin
22 23 24 25 |
# File 'lib/jekyll_oembed.rb', line 22 def initialize(tag_name, text, tokens) super @text = text end |
Instance Method Details
#error_message(url) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/jekyll_oembed.rb', line 47 def (url) # Silent error. This seems preferable to a hard fail # because a user could make a URL private anytime. puts "OEmbedError: The url, #{url}, is not available as an oembed. " \ 'Consider using an HTML embed instead.'.red end |
#html_output(result) ⇒ Object
42 43 44 45 |
# File 'lib/jekyll_oembed.rb', line 42 def html_output(result) "<div class=\"embed-container #{result.fields['type']} " \ "#{result.fields['provider']}\">#{result.html}</div>" end |
#render(context) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/jekyll_oembed.rb', line 27 def render(context) # Pipe param through liquid to make additional replacements possible url = Liquid::Template.parse(@text).render context url = url.strip! || url.strip begin # OEmbed look up result = ::OEmbed::Providers.get(url) html_output(result) rescue (url) '' end end |