Skip to content

Instantly share code, notes, and snippets.

@milesegan
Created June 27, 2011 08:02
Show Gist options
  • Save milesegan/1048471 to your computer and use it in GitHub Desktop.
Save milesegan/1048471 to your computer and use it in GitHub Desktop.
embed_youtube tag plugin for Jekyll
# Provides an "embed_youtube" tag for Jekyll's Liquid templates.
# Much cleaner than pasting in <object> tags.
require 'uri'
module Jekyll
class EmbedYouTubeTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
parts = text.split.collect { |i| i.strip }
@url = URI.escape(parts.shift)
@width = URI.escape(parts.shift || "640")
@height = URI.escape(parts.shift || "390")
end
def render(context)
html=<<HTML
<object style="height: #{@height}px; width: #{@width}px">
<param name="movie" value="#{@url}">
<param name="allowFullScreen" value="true">
<param name="allowScriptAccess" value="always">
<embed src="#{@url}"
type="application/x-shockwave-flash"
allowfullscreen="true"
allowScriptAccess="always"
width="#{@width}"
height="#{@height}">
</object>
HTML
html.gsub("\n", "")
end
end
end
Liquid::Template.register_tag('embed_youtube', Jekyll::EmbedYouTubeTag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment