feat: allow to set main JS and CSS from files + lazy-load component m… (#870)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Juro Oravec 2024-12-30 18:00:46 +01:00 committed by GitHub
parent 8fcb84c002
commit 715bf7d447
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 1014 additions and 248 deletions

View file

@ -8,9 +8,9 @@ class Calendar(Component):
#
# `template_name` can be relative to dir where `calendar.py` is, or relative to COMPONENTS.dirs
template_name = "calendar/calendar.html"
# Or
# def get_template_name(context):
# return f"template-{context['name']}.html"
css_file = "calendar/calendar.css"
js_file = "calendar/calendar.js"
# This component takes one parameter, a date string to show in the template
def get_context_data(self, date):
@ -25,10 +25,6 @@ class Calendar(Component):
},
)
class Media:
css = "calendar/calendar.css"
js = "calendar/calendar.js"
@register("calendar_relative")
class CalendarRelative(Component):
@ -37,9 +33,9 @@ class CalendarRelative(Component):
#
# `template_name` can be relative to dir where `calendar.py` is, or relative to COMPONENTS.dirs
template_name = "calendar.html"
# Or
# def get_template_name(context):
# return f"template-{context['name']}.html"
css_file = "calendar.css"
js_file = "calendar.js"
# This component takes one parameter, a date string to show in the template
def get_context_data(self, date):
@ -53,7 +49,3 @@ class CalendarRelative(Component):
"date": request.GET.get("date", ""),
},
)
class Media:
css = "calendar.css"
js = "calendar.js"

View file

@ -8,9 +8,9 @@ class CalendarNested(Component):
#
# `template_name` can be relative to dir where `calendar.py` is, or relative to COMPONENTS.dirs
template_name = "calendar.html"
# Or
# def get_template_name(context):
# return f"template-{context['name']}.html"
css_file = "calendar.css"
js_file = "calendar.js"
# This component takes one parameter, a date string to show in the template
def get_context_data(self, date):
@ -24,7 +24,3 @@ class CalendarNested(Component):
"date": request.GET.get("date", ""),
},
)
class Media:
css = "calendar.css"
js = "calendar.js"