vimeo.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. <span style="width:640px; height:480px;">
  16. <iframe
  17. src="//player.vimeo.com/video/10739054?title=0&amp;byline=0&amp;portrait=0"
  18. width="640" height="480" frameborder="0"
  19. webkitallowfullscreen mozallowfullscreen allowfullscreen>
  20. </iframe>
  21. </span>
  22. [1] https://gist.github.com/jamieowen/2063748
  23. """
  24. import re
  25. from .mdx_liquid_tags import LiquidTags
  26. SYNTAX = "{% vimeo id [width height] %}"
  27. VIMEO = re.compile(r'(\S+)(\s+(\d+)\s(\d+))?')
  28. @LiquidTags.register('vimeo')
  29. def vimeo(preprocessor, tag, markup):
  30. width = 640
  31. height = 390
  32. vimeo_id = None
  33. match = VIMEO.search(markup)
  34. if match:
  35. groups = match.groups()
  36. vimeo_id = groups[0]
  37. width = groups[2] or width
  38. height = groups[3] or height
  39. if vimeo_id:
  40. vimeo_out = """
  41. <span class="videobox">
  42. <iframe
  43. src="//player.vimeo.com/video/{vimeo_id}?title=0&amp;byline=0&amp;portrait=0"
  44. width="{width}" height="{height}" frameborder="0"
  45. webkitAllowFullScreen mozallowfullscreen allowFullScreen>
  46. </iframe>
  47. </span>
  48. """.format(width=width, height=height, vimeo_id=vimeo_id).strip()
  49. else:
  50. raise ValueError("Error processing input, "
  51. "expected syntax: {0}".format(SYNTAX))
  52. return vimeo_out
  53. # ---------------------------------------------------
  54. # This import allows vimeo tag to be a Pelican plugin
  55. from liquid_tags import register # noqa