mirror of
https://github.com/django-components/django-components.git
synced 2025-07-16 04:54:59 +00:00
Add support for - and / in component names in middleware
- Fix the COMPONENT_COMMENT_REGEX to find component names with special symbols.
- Fix the test to catch the error.
Follow-up of e0c29e5
and ref: #262
This commit is contained in:
parent
c0fc6c0a12
commit
a919b648b3
2 changed files with 20 additions and 17 deletions
|
@ -11,9 +11,9 @@ CSS_DEPENDENCY_PLACEHOLDER = '<link name="CSS_PLACEHOLDER">'
|
||||||
JS_DEPENDENCY_PLACEHOLDER = '<script name="JS_PLACEHOLDER"></script>'
|
JS_DEPENDENCY_PLACEHOLDER = '<script name="JS_PLACEHOLDER"></script>'
|
||||||
|
|
||||||
SCRIPT_TAG_REGEX = re.compile("<script")
|
SCRIPT_TAG_REGEX = re.compile("<script")
|
||||||
COMPONENT_COMMENT_REGEX = re.compile(rb"<!-- _RENDERED (?P<name>\w+?) -->")
|
COMPONENT_COMMENT_REGEX = re.compile(rb"<!-- _RENDERED (?P<name>[\w\-/]+?) -->")
|
||||||
PLACEHOLDER_REGEX = re.compile(
|
PLACEHOLDER_REGEX = re.compile(
|
||||||
rb"<!-- _RENDERED (?P<name>[\w\-\/]+?) -->"
|
rb"<!-- _RENDERED (?P<name>[\w\-/]+?) -->"
|
||||||
rb'|<link name="CSS_PLACEHOLDER">'
|
rb'|<link name="CSS_PLACEHOLDER">'
|
||||||
rb'|<script name="JS_PLACEHOLDER"></script>'
|
rb'|<script name="JS_PLACEHOLDER"></script>'
|
||||||
)
|
)
|
||||||
|
|
|
@ -399,18 +399,21 @@ class ComponentMediaRenderingTests(SimpleTestCase):
|
||||||
request = Mock()
|
request = Mock()
|
||||||
self.assertEqual(response, middleware(request=request))
|
self.assertEqual(response, middleware(request=request))
|
||||||
|
|
||||||
def test_middleware_response_with_components_with_slash_and_dash(self):
|
def test_middleware_response_with_components_with_slash_dash_and_underscore(self):
|
||||||
component.registry.register(
|
component_names = ["test-component", "test/component", "test_component"]
|
||||||
name="test-component", component=SimpleComponent
|
for component_name in component_names:
|
||||||
)
|
component.registry.register(
|
||||||
component.registry.register(
|
name=component_name, component=SimpleComponent
|
||||||
name="test/component", component=SimpleComponent
|
)
|
||||||
)
|
template = Template(
|
||||||
|
"{% load component_tags %}"
|
||||||
template = Template(
|
"{% component_js_dependencies %}"
|
||||||
"{% load component_tags %}{% component_js_dependencies %}"
|
"{% component_css_dependencies %}"
|
||||||
"{% component 'test-component' variable='variable' %}"
|
f"{{% component '{component_name}' variable='value' %}}"
|
||||||
"{% component 'test/component' variable='variable' %}"
|
)
|
||||||
)
|
rendered = create_and_process_template_response(template)
|
||||||
rendered = create_and_process_template_response(template)
|
self.assertEqual((
|
||||||
self.assertNotIn("_RENDERED", rendered)
|
'<script src="script.js"></script>'
|
||||||
|
'<link href="style.css" media="all" rel="stylesheet">'
|
||||||
|
"Variable: <strong>value</strong>\n"
|
||||||
|
), rendered)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue