-
-
Save slava-vishnyakov/4010922 to your computer and use it in GitHub Desktop.
Octopress Youtube plugin...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example: | |
# {% youtube http://www.youtube.com/watch?v=Awf45u6zrP0 %} | |
require 'cgi' | |
require 'uri' | |
module Jekyll | |
class Youtube < Liquid::Tag | |
@width = 640 | |
@height = 390 | |
def initialize(name, id, tokens) | |
super | |
if id.to_s.start_with? 'http' | |
@id = CGI.parse(URI.parse(id.to_s).query)['v'][0] | |
else | |
@id = id | |
end | |
end | |
def render(context) | |
%(<iframe width="#{@width}" height="#{@height}" src="http://www.youtube.com/embed/#{@id}" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>) | |
end | |
end | |
end | |
Liquid::Template.register_tag('youtube', Jekyll::Youtube) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! I will use in my Octopress blog.