Simplified way to embed videos

This commit is contained in:
Juda Kaleta 2013-06-27 10:10:27 +02:00
parent 7368db578a
commit 99ff8e472f
3 changed files with 28 additions and 4 deletions

View file

@ -55,12 +55,23 @@ Usage of variables:
::
{% video item.video as video %}
URL: {{ video.url }}
Thumbnail: {{ video.thumbnail }}
{% video item.video as my_video %}
URL: {{ my_video.url }}
Thumbnail: {{ my_video.thumbnail }}
{% endvideo %}
There is a simplier way, if you don't need work with parameters as
``my_video.url`` or ``my_video.thumbnail`` and you want to use just ``embed``
tag.
::
{{ 'http://www.youtube.com/watch?v=guXyvo2FfLs'|embed:'large' }}
Model examples
---------------
@ -82,6 +93,7 @@ TODO
- Vimeo thumbnail
.. vim: set tw=80:

View file

@ -1,5 +1,5 @@
from django.template import Library, Node, TemplateSyntaxError
from django.utils.safestring import mark_safe
from django.utils.safestring import mark_safe, SafeText
from ..base import detect_backend, SoundCloundBackend
@ -40,6 +40,9 @@ class VideoNode(Node):
@register.filter(is_safe=True)
def embed(backend, _size='small'):
if isinstance(backend, SafeText):
backend = detect_backend(backend)
sizes = {
'tiny': (420, 315),
'small': (480, 360),

View file

@ -53,6 +53,15 @@ class EmbedVideoTestCase(TestCase):
self.assertEqual(template.render(self._grc()).strip(), rendered)
def test_direct_embed(self):
template = Template("""
{% load embed_video_tags %}
{{ 'http://www.youtube.com/watch?v=jsrRJyHBvzw'|embed:'large' }}
""")
rendered = u'<iframe width="960" height="720" src="http://www.youtube.com/embed/jsrRJyHBvzw?wmode=opaque" frameborder="0" allowfullscreen></iframe>'
self.assertEqual(template.render(self._grc()).strip(), rendered)
def test_embed_user_size(self):
template = Template("""
{% load embed_video_tags %}