1
0
mirror of https://github.com/danbee/jekyll-video-tag synced 2025-03-04 08:59:11 +00:00

First commit.

This commit is contained in:
Dan Barber 2014-09-25 10:33:17 +01:00
commit 2b5ea79706
6 changed files with 103 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.sass-cache

21
LICENCE.txt Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Dan Barber
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

19
README.md Normal file
View File

@ -0,0 +1,19 @@
Video Tag
**Easy responsive videos for Jekyll.**
Jekyll Video Tag is a liquid tag that adds responsive videos to your [Jekyll](http://jekyllrb.com) static site.
### Usage
Add the CSS or Sass file to your site.
```liquid
{% video {embed-url} width={width} height={height} %}
```
### Example
```liquid
{% video //www.youtube.com/embed/7eP4pw03PCg width=560 height=315 %}
```

8
video.css Normal file
View File

@ -0,0 +1,8 @@
.video-container {
position: relative;
width: 100%;
height: 0; }
.video-container iframe {
position: absolute;
width: 100%;
height: 100%; }

8
video.css.sass Normal file
View File

@ -0,0 +1,8 @@
.video-container
position: relative
width: 100%
height: 0
iframe
position: absolute
width: 100%
height: 100%

46
video_tag.rb Normal file
View File

@ -0,0 +1,46 @@
# Plugin for rendering responsive video in Jekyll
# Written by: Dan Barber
# Version: 0.0.1
# ===============================================
# Usage:
# ------
# {% video {embed-url} width={width} height={height} %}
#
# The embed URL is the one that is referenced by the iframe in the video embed code.
#
# Example:
# {% video //www.youtube.com/embed/7eP4pw03PCg width=560 height=315 %}
module Jekyll
class VideoTag < Liquid::Tag
def initialize(tag_name, input, tokens)
super
@url = input.slice!(/[^ ]+/)
@options = parse_options(input)
end
def render(context)
%(<div class="video-container" style="#{container_style(@options)}">#{video_iframe(@url)}</div>)
end
private
def video_iframe(url)
%(<iframe src="#{url}" frameborder="0" allowfullscreen />)
end
def container_style(options)
"padding-bottom: #{height_as_percentage_of_width(options['width'], options['height'])}%"
end
def parse_options(input)
Hash[input.strip.split(' ').map { |option| option.split('=') }]
end
def height_as_percentage_of_width(width, height)
(height.to_f / width.to_f) * 100
end
end
end
Liquid::Template.register_tag('video', Jekyll::VideoTag)