Ticket #10094: 10094-loader_tags-split_contents.diff

File 10094-loader_tags-split_contents.diff, 2.4 KB (added by mcroydon, 16 years ago)

Patch and tests to use token.split_contents() in include and extends tags.

  • django/template/loader_tags.py

    diff --git a/django/template/loader_tags.py b/django/template/loader_tags.py
    index 38b2fff..f91699d 100644
    a b def do_extends(parser, token):  
    158158    name of the parent template to extend (if it evaluates to a string) or as
    159159    the parent tempate itelf (if it evaluates to a Template object).
    160160    """
    161     bits = token.contents.split()
     161    bits = token.split_contents()
    162162    if len(bits) != 2:
    163163        raise TemplateSyntaxError, "'%s' takes one argument" % bits[0]
    164164    parent_name, parent_name_expr = None, None
    def do_include(parser, token):  
    179179
    180180        {% include "foo/some_include" %}
    181181    """
    182     bits = token.contents.split()
     182    bits = token.split_contents()
    183183    if len(bits) != 2:
    184184        raise TemplateSyntaxError, "%r tag takes one argument: the name of the template to be included" % bits[0]
    185185    path = bits[1]
  • tests/regressiontests/templates/tests.py

    diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
    index f0eee52..5419c18 100644
    a b class Templates(unittest.TestCase):  
    658658            'include02': ('{% include "basic-syntax02" %}', {'headline': 'Included'}, "Included"),
    659659            'include03': ('{% include template_name %}', {'template_name': 'basic-syntax02', 'headline': 'Included'}, "Included"),
    660660            'include04': ('a{% include "nonexistent" %}b', {}, "ab"),
     661            'include 05': ('template with a space', {}, 'template with a space'),
     662            'include06': ('{% include "include 05"%}', {}, 'template with a space'),
    661663
    662664            ### NAMED ENDBLOCKS #######################################################
    663665
    class Templates(unittest.TestCase):  
    757759            # Inheritance from a template that doesn't have any blocks
    758760            'inheritance27': ("{% extends 'inheritance26' %}", {}, 'no tags'),
    759761
     762            # Set up a base template with a space in it
     763            'inheritance 28': ("{% block first %}!{% endblock %}", {}, '!'),
     764
     765            # Inheritance from a template with a space in its name should work
     766            'inheritance29': ("{% extends 'inheritance 28' %}", {}, '!'),
     767
    760768            ### I18N ##################################################################
    761769
    762770            # {% spaceless %} tag
Back to Top