瀏覽代碼

New vimeo tag.

Sven Kreiss 11 年之前
父節點
當前提交
b95142b415
共有 2 個文件被更改,包括 65 次插入2 次删除
  1. 11 2
      liquid_tags/Readme.md
  2. 54 0
      liquid_tags/vimeo.py

+ 11 - 2
liquid_tags/Readme.md

@@ -14,8 +14,8 @@ First, in your pelicanconf.py file, add the plugins you want to  use:
 
     PLUGIN_PATH = '/path/to/pelican-plugins'
     PLUGINS = ['liquid_tags.img', 'liquid_tags.video',
-               'liquid_tags.youtube', 'liquid_tags.include_code',
-               'liquid_tags.notebook']
+               'liquid_tags.youtube', 'liquid_tags.vimeo',
+               'liquid_tags.include_code', 'liquid_tags.notebook']
 
 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
 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
 To insert flash/HTML5-friendly video into a post, enable the
 ``liquid_tags.video`` plugin, and add to your document:

+ 54 - 0
liquid_tags/vimeo.py

@@ -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