mirror of
https://github.com/django-components/django-components.git
synced 2025-11-18 14:10:19 +00:00
Registering the same component twice only renders one dependency <link> and <script> tag.
This commit is contained in:
parent
be574fb520
commit
7bc1096e94
2 changed files with 16 additions and 3 deletions
|
|
@ -5,8 +5,10 @@ register = template.Library()
|
|||
|
||||
@register.simple_tag(name="component_dependencies")
|
||||
def component_dependencies_tag():
|
||||
unique_component_classes = set(registry._registry.values())
|
||||
|
||||
out = []
|
||||
for component_class in registry._registry.values():
|
||||
for component_class in unique_component_classes:
|
||||
out.append(component_class.render_dependencies())
|
||||
|
||||
return "\n".join(out)
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class ComponentTemplateTagTest(unittest.TestCase):
|
|||
# NOTE: component.registry is global, so need to clear before each test
|
||||
component.registry._registry = {}
|
||||
|
||||
def test_component_dependencies(self):
|
||||
def test_single_component_dependencies(self):
|
||||
component.registry.register(name="test", component=SimpleComponent)
|
||||
|
||||
template = Template('{% load component_tags %}{% component_dependencies %}')
|
||||
|
|
@ -30,9 +30,20 @@ class ComponentTemplateTagTest(unittest.TestCase):
|
|||
<script type="text/javascript" src="script.js"></script>
|
||||
""").strip())
|
||||
|
||||
def test_component(self):
|
||||
def test_single_component(self):
|
||||
component.registry.register(name="test", component=SimpleComponent)
|
||||
|
||||
template = Template('{% load component_tags %}{% component name="test" variable="variable" %}')
|
||||
rendered = template.render(Context({}))
|
||||
self.assertEqual(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)
|
||||
|
||||
template = Template('{% load component_tags %}{% component_dependencies %}')
|
||||
rendered = template.render(Context())
|
||||
self.assertEqual(rendered, dedent("""
|
||||
<link href="style.css" type="text/css" media="all" rel="stylesheet" />
|
||||
<script type="text/javascript" src="script.js"></script>
|
||||
""").strip())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue