mirror of
https://github.com/django-components/django-components.git
synced 2025-10-17 17:27:13 +00:00
Allow simpler definition of Media class.
This commit is contained in:
parent
c67fd29bdd
commit
b8f14404ac
2 changed files with 92 additions and 1 deletions
|
@ -97,3 +97,70 @@ class ComponentTest(SimpleTestCase):
|
|||
<svg>Dynamic2</svg>
|
||||
""")
|
||||
)
|
||||
|
||||
def test_component_media_with_strings(self):
|
||||
class SimpleComponent(component.Component):
|
||||
class Media:
|
||||
css = "path/to/style.css"
|
||||
js = "path/to/script.js"
|
||||
|
||||
comp = SimpleComponent("")
|
||||
self.assertHTMLEqual(
|
||||
comp.render_dependencies(),
|
||||
dedent("""\
|
||||
<link href="path/to/style.css" type="text/css" media="all" rel="stylesheet">
|
||||
<script src="path/to/script.js"></script>
|
||||
""")
|
||||
)
|
||||
|
||||
def test_component_media_with_lists(self):
|
||||
class SimpleComponent(component.Component):
|
||||
class Media:
|
||||
css = ["path/to/style.css", "path/to/style2.css"]
|
||||
js = ["path/to/script.js"]
|
||||
|
||||
comp = SimpleComponent("")
|
||||
self.assertHTMLEqual(
|
||||
comp.render_dependencies(),
|
||||
dedent("""\
|
||||
<link href="path/to/style.css" type="text/css" media="all" rel="stylesheet">
|
||||
<link href="path/to/style2.css" type="text/css" media="all" rel="stylesheet">
|
||||
<script src="path/to/script.js"></script>
|
||||
""")
|
||||
)
|
||||
|
||||
def test_component_media_with_dict_and_list(self):
|
||||
class SimpleComponent(component.Component):
|
||||
class Media:
|
||||
css = {
|
||||
"all": "path/to/style.css",
|
||||
"print": ["path/to/style2.css"],
|
||||
"screen": "path/to/style3.css",
|
||||
}
|
||||
js = ["path/to/script.js"]
|
||||
|
||||
comp = SimpleComponent("")
|
||||
self.assertHTMLEqual(
|
||||
comp.render_dependencies(),
|
||||
dedent("""\
|
||||
<link href="path/to/style.css" type="text/css" media="all" rel="stylesheet">
|
||||
<link href="path/to/style2.css" type="text/css" media="print" rel="stylesheet">
|
||||
<link href="path/to/style3.css" type="text/css" media="screen" rel="stylesheet">
|
||||
<script src="path/to/script.js"></script>
|
||||
""")
|
||||
)
|
||||
|
||||
def test_component_media_with_dict_with_list_and_list(self):
|
||||
class SimpleComponent(component.Component):
|
||||
class Media:
|
||||
css = {"all": ["path/to/style.css"]}
|
||||
js = ["path/to/script.js"]
|
||||
|
||||
comp = SimpleComponent("")
|
||||
self.assertHTMLEqual(
|
||||
comp.render_dependencies(),
|
||||
dedent("""\
|
||||
<link href="path/to/style.css" type="text/css" media="all" rel="stylesheet">
|
||||
<script src="path/to/script.js"></script>
|
||||
""")
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue