Add a form of static:require_module that assumes that the factory is self-initializing
This commit is contained in:
@@ -111,7 +111,7 @@ source, template_path = Loader(engine).load_template_source(path)
|
||||
${HTML(render_bundle(page))}
|
||||
</%def>
|
||||
|
||||
<%def name="webpack(entry)">
|
||||
<%def name="webpack(entry, extension=None, config='DEFAULT', attrs='')">
|
||||
<%doc>
|
||||
Loads Javascript onto your page from a Webpack-generated bundle.
|
||||
Uses the Django template engine because our webpack loader only provides template tags for Jinja and Django.
|
||||
@@ -119,7 +119,7 @@ source, template_path = Loader(engine).load_template_source(path)
|
||||
<%
|
||||
body = capture(caller.body)
|
||||
%>
|
||||
${HTML(render_bundle(entry))}
|
||||
${HTML(render_bundle(entry, extension=None, config='DEFAULT', attrs=attrs))}
|
||||
% if body:
|
||||
<script type="text/javascript">
|
||||
${body | n, decode.utf8}
|
||||
@@ -154,6 +154,36 @@ source, template_path = Loader(engine).load_template_source(path)
|
||||
</script>
|
||||
</%def>
|
||||
|
||||
<%def name="require_page(page_name, class_name)">
|
||||
<%doc>
|
||||
Loads Javascript onto your page synchronously.
|
||||
Uses RequireJS in development and a plain script tag in production.
|
||||
The body of the tag should be a comma-separated list of arguments
|
||||
to be passed to the page factory specified by the class_name argument.
|
||||
</%doc>
|
||||
<%
|
||||
body = capture(caller.body)
|
||||
%>
|
||||
<script type="text/javascript">
|
||||
if (typeof pageFactoryArguments == "undefined") {
|
||||
var pageFactoryArguments = {};
|
||||
}
|
||||
% if body:
|
||||
pageFactoryArguments['${class_name | n, js_escaped_string}'] = [${ body | n, decode.utf8 }];
|
||||
% else:
|
||||
pageFactoryArguments['${class_name | n, js_escaped_string}'] = [];
|
||||
% endif
|
||||
</script>
|
||||
% if not settings.REQUIRE_DEBUG:
|
||||
<script type="text/javascript" src="${staticfiles_storage.url(page_name + '.js') + '?raw'}"></script>
|
||||
% endif
|
||||
<script type="text/javascript">
|
||||
(function (require) {
|
||||
require(['${page_name | n, js_escaped_string}']);
|
||||
}).call(this, require || RequireJS.require);
|
||||
</script>
|
||||
</%def>
|
||||
|
||||
<%def name="require_module(module_name, class_name)">
|
||||
<%doc>
|
||||
Loads Javascript onto your page synchronously.
|
||||
|
||||
Reference in New Issue
Block a user