mirror of
https://github.com/django-components/django-components.git
synced 2025-07-14 04:14:58 +00:00
Dependencies are the same for all instances, so convert to classmethod.
This commit is contained in:
parent
143918e2cf
commit
33b1930ed5
1 changed files with 7 additions and 9 deletions
|
@ -5,25 +5,23 @@ class Component(object):
|
|||
CSS_TEMPLATE = '<link href="{}" type="text/css" media="{}" rel="stylesheet" />'
|
||||
JS_TEMPLATE = '<script type="text/javascript" src="{}"></script>'
|
||||
|
||||
def __init__(self):
|
||||
self._media = self.Media()
|
||||
|
||||
def context(self):
|
||||
return {}
|
||||
|
||||
def render_dependencies(self):
|
||||
@classmethod
|
||||
def render_dependencies(cls):
|
||||
out = []
|
||||
|
||||
for css_media, css_path in self._media.css.items():
|
||||
out.append(Component.CSS_TEMPLATE.format(css_path, css_media))
|
||||
for css_media, css_path in cls.Media.css.items():
|
||||
out.append(cls.CSS_TEMPLATE.format(css_path, css_media))
|
||||
|
||||
for js_path in self._media.js:
|
||||
out.append(Component.JS_TEMPLATE.format(js_path))
|
||||
for js_path in cls.Media.js:
|
||||
out.append(cls.JS_TEMPLATE.format(js_path))
|
||||
|
||||
return "\n".join(out)
|
||||
|
||||
def render(self, *args, **kwargs):
|
||||
return render_to_string(self._media.template, self.context(*args, **kwargs))
|
||||
return render_to_string(self.Media.template, self.context(*args, **kwargs))
|
||||
|
||||
class Media:
|
||||
template = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue