vimeo.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """
  2. Vimeo Tag
  3. ---------
  4. This implements a Liquid-style vimeo tag for Pelican,
  5. based on the youtube tag which is in turn based on
  6. the jekyll / octopress youtube tag [1]_
  7. Syntax
  8. ------
  9. {% vimeo id [width height] %}
  10. Example
  11. -------
  12. {% vimeo 10739054 640 480 %}
  13. Output
  14. ------
  15. <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>
  16. [1] https://gist.github.com/jamieowen/2063748
  17. """
  18. import re
  19. from .mdx_liquid_tags import LiquidTags
  20. SYNTAX = "{% vimeo id [width height] %}"
  21. VIMEO = re.compile(r'(\S+)(\s+(\d+)\s(\d+))?')
  22. @LiquidTags.register('vimeo')
  23. def vimeo(preprocessor, tag, markup):
  24. width = 640
  25. height = 390
  26. vimeo_id = None
  27. match = VIMEO.search(markup)
  28. if match:
  29. groups = match.groups()
  30. vimeo_id = groups[0]
  31. width = groups[2] or width
  32. height = groups[3] or height
  33. if vimeo_id:
  34. vimeo_out = """
  35. <div class="videobox">
  36. <iframe src="//player.vimeo.com/video/{vimeo_id}?title=0&amp;byline=0&amp;portrait=0"
  37. width="{width}" height="{height}" frameborder="0"
  38. webkitAllowFullScreen mozallowfullscreen allowFullScreen>
  39. </iframe>
  40. </div>
  41. """.format(width=width, height=height, vimeo_id=vimeo_id).strip()
  42. else:
  43. raise ValueError("Error processing input, "
  44. "expected syntax: {0}".format(SYNTAX))
  45. return vimeo_out
  46. #----------------------------------------------------------------------
  47. # This import allows vimeo tag to be a Pelican plugin
  48. from liquid_tags import register