Added the init_libs template tag to initialize the CSS and JavaScript library resolver in the Mia core application.

This commit is contained in:
依瑪貓 2020-08-30 22:55:25 +08:00
parent c0946481dd
commit 4cb92dd309

View File

@ -104,6 +104,21 @@ def url_keep_return(context: RequestContext, url: str) -> str:
return str(UrlBuilder(url).query(r=context.request.GET.get("r")))
@register.simple_tag(takes_context=True)
def init_libs(context: RequestContext) -> str:
"""Initializes the static libraries.
Args:
context: The request context.
Returns:
An empty string.
"""
if "libs" not in context.dicts[0]:
context.dicts[0]["libs"] = CssAndJavaScriptLibraries()
return ""
@register.simple_tag(takes_context=True)
def add_lib(context: RequestContext, *args) -> str:
"""Adds CSS and JavaScript libraries.