Skip to content
Browse files

v0.0.1

  • Loading branch information...
0 parents commit be7c22b4ec72fe7c616cb6a33e2ba0627e567af5 @stereobooster committed Sep 28, 2012
Showing with 64 additions and 0 deletions.
  1. +5 −0 Gemfile
  2. +19 −0 Readme.md
  3. +40 −0 _plugins/jekyll_oembed.rb
5 Gemfile
@@ -0,0 +1,5 @@
+source :rubygems
+
+gem "jekyll"
+
+gem "oembed"
19 Readme.md
@@ -0,0 +1,19 @@
+# oEmbed plugin for jekyll. Simple liquid tag
+
+## Example
+```liquid
+ {% oembed http://vimeo.com/2696386 width=960 %}
+```
+
+## Usage
+ - put `jekyll_oembed.rb` in plugins folder
+ - add gems to `Gemfile`
+ - install gems: `bundle`
+ - regenerate all content: `bundle exec jekyll`
+
+## Resources
+ - [oEmbed providers](http://www.oembed.com/#section7.1)
+
+## TODO
+ - add more providers. For now there are only youtube and vimeo
+ - add support of passing API key for embedly
40 _plugins/jekyll_oembed.rb
@@ -0,0 +1,40 @@
+# jekyll_oembed 0.0.1
+# https://github.com/stereobooster/jekyll_oembed
+
+begin
+ require 'oembed'
+ require 'shellwords'
+
+ module Jekyll
+ class OEmbedTag < Liquid::Tag
+
+ def initialize(tag_name, text, tokens)
+ super
+ @params = text.shellsplit
+ @url = @params.shift
+ @params = Hash[*@params.map{|val| val.split('=')}.flatten]
+ end
+
+ def render(context)
+ OEmbed::Providers.register(OEmbed::Providers::Youtube)
+ OEmbed::Providers.register(OEmbed::Providers::Vimeo)
+ begin
+ resource = OEmbed::Providers.get(@url, @params)
+ # TODO: cache results
+ # resource.type
+ # resource.provider.name
+ # resource.video?
+ # resource.thumbnail_url
+ resource.html
+ rescue OEmbed::NotFound
+ warn "No embeddable content at #{@url}"
+ "<a href='#{@url}'>#{@url}</a>"
+ end
+ end
+ end
+ end
+
+ Liquid::Template.register_tag('oembed', Jekyll::OEmbedTag)
+rescue LoadError
+ warn "Install oembed gem: gem install oembed or add it to Gemfile"
+end

0 comments on commit be7c22b

Please sign in to comment.
Something went wrong with that request. Please try again.