Merge pull request #174 from svenkreiss/master

Add Vimeo support to liquid_tags plugin
This commit is contained in:
Justin Mayer
2014-03-09 12:04:38 +01:00
2 changed files with 65 additions and 2 deletions

View File

@@ -14,8 +14,8 @@ First, in your pelicanconf.py file, add the plugins you want to use:
PLUGIN_PATH = '/path/to/pelican-plugins' PLUGIN_PATH = '/path/to/pelican-plugins'
PLUGINS = ['liquid_tags.img', 'liquid_tags.video', PLUGINS = ['liquid_tags.img', 'liquid_tags.video',
'liquid_tags.youtube', 'liquid_tags.include_code', 'liquid_tags.youtube', 'liquid_tags.vimeo',
'liquid_tags.notebook'] 'liquid_tags.include_code', 'liquid_tags.notebook']
There are several options available There are several options available
@@ -34,6 +34,15 @@ To insert youtube video into a post, enable the
The width and height are in pixels, and can be optionally specified. If they The width and height are in pixels, and can be optionally specified. If they
are not, then the dimensions will be 640 (wide) by 390 (tall). are not, then the dimensions will be 640 (wide) by 390 (tall).
## Vimeo Tag
To insert a Vimeo video into a post, enable the
``liquid_tags.vimeo`` plugin, and add to your document:
{% vimeo vimeo_id [width] [height] %}
The width and height are in pixels, and can be optionally specified. If they
are not, then the dimensions will be 640 (wide) by 390 (tall).
## Video Tag ## Video Tag
To insert flash/HTML5-friendly video into a post, enable the To insert flash/HTML5-friendly video into a post, enable the
``liquid_tags.video`` plugin, and add to your document: ``liquid_tags.video`` plugin, and add to your document:

54
liquid_tags/vimeo.py Normal file
View File

@@ -0,0 +1,54 @@
"""
Vimeo Tag
---------
This implements a Liquid-style vimeo tag for Pelican,
based on the youtube tag which is in turn based on
the jekyll / octopress youtube tag [1]_
Syntax
------
{% vimeo id [width height] %}
Example
-------
{% vimeo 10739054 640 480 %}
Output
------
<div style="width:640px; height:480px;"><iframe src="//player.vimeo.com/video/10739054?title=0&amp;byline=0&amp;portrait=0" width="640" height="480" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>
[1] https://gist.github.com/jamieowen/2063748
"""
import re
from .mdx_liquid_tags import LiquidTags
SYNTAX = "{% vimeo id [width height] %}"
VIMEO = re.compile(r'(\w+)(\s+(\d+)\s(\d+))?')
@LiquidTags.register('vimeo')
def vimeo(preprocessor, tag, markup):
width = 640
height = 390
vimeo_id = None
match = VIMEO.search(markup)
if match:
groups = match.groups()
vimeo_id = groups[0]
width = groups[2] or width
height = groups[3] or height
if vimeo_id:
vimeo_out = '<div style="width:{width}px; height:{height}px;"><iframe src="//player.vimeo.com/video/{vimeo_id}?title=0&amp;byline=0&amp;portrait=0" width="{width}" height="{height}" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>'.format(width=width, height=height, vimeo_id=vimeo_id)
else:
raise ValueError("Error processing input, "
"expected syntax: {0}".format(SYNTAX))
return vimeo_out
#----------------------------------------------------------------------
# This import allows vimeo tag to be a Pelican plugin
from liquid_tags import register