Permalink
Browse files

Preparation for gem release

  • Loading branch information...
stereobooster committed Mar 4, 2013
1 parent 385f54c commit dbc345587f0450b36d0b990281df8dd768c7bb3a
Showing with 82 additions and 47 deletions.
  1. +44 −4 Readme.md
  2. +6 −4 jekyll_oembed.gemspec
  3. +32 −39 lib/jekyll_oembed.rb
View
@@ -4,16 +4,56 @@
```liquid
{% oembed http://vimeo.com/2696386 width=960 %}
```
+## Installation
+
+### Bundler
+Add this line to your application's `Gemfile`:
+```ruby
+gem 'jekyll-oembed'
+```
+
+And then execute:
+```bash
+$ bundle
+```
+
+### Standalone
+Execute:
+```bash
+$ gem install jekyll-oembed
+```
## Usage
- - add `gem 'jekyll_oembed'` to your Gemfile
- - add `require 'jekyll_oembed'` to the file `_plugins/ext.rb`
- - install gems: `bundle`
- - regenerate all content: `bundle exec jekyll`
+### With Bundler (recomended)
+Create the following plugin in your projects _plugins directory.
+
+```ruby
+# _plugins/bundler.rb
+require "rubygems"
+require "bundler/setup"
+Bundler.require(:default)
+```
+
+This will automatically require all of the gems specified in your Gemfile.
+
+### Standalone
+Create the following plugin in your projects _plugins directory.
+
+```ruby
+# _plugins/jekyll-oembed-plugin.rb
+require 'jekyll-oembed'
+```
## Resources
- [oEmbed providers](http://www.oembed.com/#section7.1)
## TODO
- add support of passing API key for embedly
- cache results (or not?)
+
+## Contributing
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Added some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
View
@@ -3,10 +3,10 @@ lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
Gem::Specification.new do |gem|
- gem.name = "jekyll_oembed"
+ gem.name = "jekyll-oembed"
gem.version = '0.0.1'
gem.authors = ["stereobooster"]
- gem.email = ["stereobooster@github.com"]
+ gem.email = ["stereobooster@gmail.com"]
gem.description = %q{Provides an oembed liquid tag for Jekyll}
gem.summary = %q{Provides an oembed liquid tag for Jekyll}
gem.homepage = "https://github.com/stereobooster/jekyll_oembed"
@@ -16,7 +16,9 @@ Gem::Specification.new do |gem|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
- gem.add_dependency("jekyll")
- gem.add_dependency("ruby-oembed", "0.8.8")
+ gem.add_dependency "jekyll"
+ gem.add_dependency "ruby-oembed", "0.8.8"
+
+ gem.add_development_dependency "rake"
end
View
@@ -1,48 +1,41 @@
-# jekyll_oembed 0.0.3
-# https://github.com/stereobooster/jekyll_oembed
+require 'oembed'
+require 'shellwords'
-begin
- require 'oembed'
- require 'shellwords'
+OEmbed::Providers.register_all
- OEmbed::Providers.register_all
+module Jekyll
+ class OEmbedTag < Liquid::Tag
- module Jekyll
- class OEmbedTag < Liquid::Tag
+ def initialize(tag_name, text, tokens)
+ super
+ @text = text
+ end
- def initialize(tag_name, text, tokens)
- super
- @text = text
- end
+ def render(context)
+ text = Liquid::Template.parse(@text).render context
+
+ params = text.shellsplit
+ url = params.shift
+ params = Hash[*params.map{|val| val.split('=')}.flatten]
+
+ resource = OEmbed::Providers.get(url, params)
+ html = resource.html
- def render(context)
- text = Liquid::Template.parse(@text).render context
-
- params = text.shellsplit
- url = params.shift
- params = Hash[*params.map{|val| val.split('=')}.flatten]
-
- resource = OEmbed::Providers.get(url, params)
- html = resource.html
-
- if url =~ /:\/\/(www.youtube.com|youtu.be)\//
- %w{width height}.each do |name|
- if params[name]
- html.gsub! Regexp.new(name+'="\\d+'), name+'="'+params[name]
- end
- end
- end
-
- # resource.video?, resource.thumbnail_url
- "<div class='oembed #{resource.type}'>#{html}</div>"
- rescue OEmbed::NotFound
- warn "No embeddable content at #{url}"
- "<a href='#{url}'>#{url}</a>"
+ if url =~ /:\/\/(www.youtube.com|youtu.be)\//
+ %w{width height}.each do |name|
+ if params[name]
+ html.gsub! Regexp.new(name+'="\\d+'), name+'="'+params[name]
+ end
+ end
end
+
+ # resource.video?, resource.thumbnail_url
+ "<div class='oembed #{resource.type}'>#{html}</div>"
+ rescue OEmbed::NotFound
+ warn "No embeddable content at #{url}"
+ "<a href='#{url}'>#{url}</a>"
end
end
-
- Liquid::Template.register_tag('oembed', Jekyll::OEmbedTag)
-rescue LoadError
- warn "Install oembed gem: gem install oembed or add it to Gemfile"
end
+
+Liquid::Template.register_tag('oembed', Jekyll::OEmbedTag)

0 comments on commit dbc3455

Please sign in to comment.