mirror of
https://github.com/django-components/django-components.git
synced 2025-11-25 16:39:11 +00:00
Add component tag.
This commit is contained in:
parent
57286f8389
commit
9a91df7978
2 changed files with 13 additions and 0 deletions
|
|
@ -10,3 +10,9 @@ def component_dependencies_tag():
|
|||
out.append(component_class.render_dependencies())
|
||||
|
||||
return "\n".join(out)
|
||||
|
||||
@register.simple_tag(name="component")
|
||||
def component_tag(name, *args, **kwargs):
|
||||
component_class = registry._registry[name]
|
||||
component = component_class()
|
||||
return component.render(*args, **kwargs)
|
||||
|
|
|
|||
|
|
@ -29,3 +29,10 @@ class ComponentTemplateTagTest(unittest.TestCase):
|
|||
<link href="style.css" type="text/css" media="all" rel="stylesheet" />
|
||||
<script type="text/javascript" src="script.js"></script>
|
||||
""").strip())
|
||||
|
||||
def test_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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue