Skip to content

Instantly share code, notes, and snippets.

@notionparallax
Forked from joelverhagen/README.md
Last active August 29, 2015 14:17
Show Gist options
  • Save notionparallax/d48c356473373c281e55 to your computer and use it in GitHub Desktop.
Save notionparallax/d48c356473373c281e55 to your computer and use it in GitHub Desktop.

This is a plugin meant for Jekyll.

It's a fork of joelverhagen's youtube plugin. This version is for bootstrap responsive embed.

Width and height don't really mean anything as they are overridden by the bootstrap aspect ratio class name.

Example use:

Easily embed a YouTube video. Just drop this file in your _plugins directory.

{% youtube oHg5SJYRHA0 %}

or

{% vimeo 9468855 %}
class Vimeo < Liquid::Tag
Syntax = /^\s*([^\s]+)(\s+(\d+)\s+(\d+)\s*)?/
def initialize(tagName, markup, tokens)
super
if markup =~ Syntax then
@id = $1
else
raise "No Vimeo ID provided in the \"vimeo\" tag"
end
end
def render(context)
"<div class=\"embed-responsive embed-responsive-4by3\">
<iframe class=\"embed-responsive-item\" src=\"https://player.vimeo.com/video/9468855\" frameborder=\"0\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div>"
end
Liquid::Template.register_tag "vimeo", self
end
class YouTube < Liquid::Tag
Syntax = /^\s*([^\s]+)(\s+(\d+)\s+(\d+)\s*)?/
def initialize(tagName, markup, tokens)
super
if markup =~ Syntax then
@id = $1
if $2.nil? then
@width = 560
@height = 420
else
@width = $2.to_i
@height = $3.to_i
end
else
raise "No YouTube ID provided in the \"youtube\" tag"
end
end
def render(context)
# "<iframe width=\"#{@width}\" height=\"#{@height}\" src=\"http://www.youtube.com/embed/#{@id}\" frameborder=\"0\"allowfullscreen></iframe>"
"<div class=\"embed-responsive embed-responsive-4by3\">
<iframe class=\"embed-responsive-item\" width=\"#{@width}\" height=\"#{@height}\" src=\"http://www.youtube.com/embed/#{@id}?color=white&theme=light\"></iframe>
</div>"
end
Liquid::Template.register_tag "youtube", self
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment