mirror of
https://github.com/Hopiu/django-embed-video.git
synced 2026-05-14 23:53:10 +00:00
Merge branch 'relative-size'
Conflicts: embed_video/backends.py
This commit is contained in:
commit
847be2d6d9
3 changed files with 29 additions and 2 deletions
|
|
@ -38,6 +38,16 @@ Default sizes are ``tiny`` (420x315), ``small`` (480x360), ``medium`` (640x480),
|
|||
.. versionadded:: 0.7
|
||||
This usage has been added in version 0.7.
|
||||
|
||||
.. versionadded:: 0.9
|
||||
|
||||
And use relative percentual size:
|
||||
|
||||
::
|
||||
|
||||
{% video my_video '100% x 50%' %}
|
||||
|
||||
|
||||
|
||||
.. tip::
|
||||
|
||||
We recommend to use `sorl-thumbnail
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ class VideoNode(Node):
|
|||
|
||||
{% video item.video "large" %}
|
||||
{% video item.video "340x200" %}
|
||||
{% video item.video "100% x 300" %}
|
||||
|
||||
{% video item.video as my_video %}
|
||||
URL: {{ my_video.url }}
|
||||
|
|
@ -48,7 +49,7 @@ class VideoNode(Node):
|
|||
error_msg = 'Syntax error. Expected: ``{% video URL ... %}``'
|
||||
default_size = 'small'
|
||||
|
||||
re_size = re.compile('(?P<width>\d+)x(?P<height>\d+)')
|
||||
re_size = re.compile('(?P<width>\d+%?) *x *(?P<height>\d+%?)')
|
||||
|
||||
def __init__(self, parser, token):
|
||||
self.size = None
|
||||
|
|
@ -150,7 +151,7 @@ class VideoNode(Node):
|
|||
|
||||
try:
|
||||
size = VideoNode.re_size.match(value)
|
||||
return [int(size.group('width')), int(size.group('height'))]
|
||||
return [size.group('width'), size.group('height')]
|
||||
except AttributeError:
|
||||
raise TemplateSyntaxError(
|
||||
'Incorrect size.\nPossible format is WIDTHxHEIGHT or using '
|
||||
|
|
|
|||
|
|
@ -187,3 +187,19 @@ class EmbedVideoNodeTestCase(TestCase):
|
|||
log = logs.records[-1]
|
||||
self.assertEqual(log.name, 'embed_video.templatetags.embed_video_tags')
|
||||
self.assertEqual(log.msg, 'Timeout reached during rendering embed video (`http://vimeo.com/72304002`)')
|
||||
|
||||
def test_relative_size(self):
|
||||
template = Template("""
|
||||
{% load embed_video_tags %}
|
||||
{% video "http://vimeo.com/72304002" "80%x30%" %}
|
||||
""")
|
||||
rendered = '<iframe width="80%" height="30%" src="http://player.vimeo.com/video/72304002" frameborder="0" allowfullscreen></iframe>'
|
||||
self.assertEqual(template.render(self._grc()).strip(), rendered)
|
||||
|
||||
def test_allow_spaces_in_size(self):
|
||||
template = Template("""
|
||||
{% load embed_video_tags %}
|
||||
{% video "http://vimeo.com/72304002" "80% x 300" %}
|
||||
""")
|
||||
rendered = '<iframe width="80%" height="300" src="http://player.vimeo.com/video/72304002" frameborder="0" allowfullscreen></iframe>'
|
||||
self.assertEqual(template.render(self._grc()).strip(), rendered)
|
||||
|
|
|
|||
Loading…
Reference in a new issue