Support specifying block names with single quotes.

Fixes #15
This commit is contained in:
Emil Stenström 2020-12-08 23:41:10 +01:00
parent e9fba9538f
commit 4c14675c3a
2 changed files with 22 additions and 1 deletions

View file

@ -183,7 +183,7 @@ def do_component(parser, token):
"Component name '%s' should be in quotes" % component_name
)
component_name = component_name.strip('"')
component_name = component_name.strip('"\'')
component_class = registry.get(component_name)
component = component_class()

View file

@ -114,6 +114,15 @@ class ComponentTemplateTagTest(SimpleTestCase):
rendered = template.render(Context({}))
self.assertHTMLEqual(rendered, "Variable: <strong>variable</strong>\n")
def test_component_called_with_singlequoted_name(self):
component.registry.register(name="test", component=SimpleComponent)
template = Template(
'{% load component_tags %}{% component \'test\' variable="variable" %}'
)
rendered = template.render(Context({}))
self.assertHTMLEqual(rendered, "Variable: <strong>variable</strong>\n")
def test_multiple_component_dependencies(self):
component.registry.register(name="test1", component=SimpleComponent)
component.registry.register(name="test2", component=SimpleComponent)
@ -245,3 +254,15 @@ class ComponentSlottedTemplateTagTest(SimpleTestCase):
rendered = template.render(Context({}))
self.assertHTMLEqual(rendered, "<custom-template></custom-template>")
def test_slotted_template_without_slots_an_single_quotes(self):
component.registry.register(name="test", component=SlottedComponentNoSlots)
template = Template(
"""
{% load component_tags %}
{% component_block 'test' %}{% endcomponent_block %}
"""
)
rendered = template.render(Context({}))
self.assertHTMLEqual(rendered, "<custom-template></custom-template>")