diff --git a/cms/envs/common.py b/cms/envs/common.py index efe84ee5e43b..75a1da4d5503 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -1126,6 +1126,9 @@ # Entitlements, used in openedx tests 'entitlements', + + # Asset management for mako templates + 'pipeline_mako', ] diff --git a/cms/templates/base.html b/cms/templates/base.html index 64a2a0366877..1736677f2a4b 100644 --- a/cms/templates/base.html +++ b/cms/templates/base.html @@ -143,6 +143,7 @@ }); }); + <%block name='requirejs_page'> <%include file="widgets/segment-io-footer.html" /> diff --git a/common/djangoapps/pipeline_mako/templates/static_content.html b/common/djangoapps/pipeline_mako/templates/static_content.html index 514cdf6cd521..83f85fd9ad83 100644 --- a/common/djangoapps/pipeline_mako/templates/static_content.html +++ b/common/djangoapps/pipeline_mako/templates/static_content.html @@ -111,7 +111,7 @@ ${HTML(render_bundle(page))} -<%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 @@ <% body = capture(caller.body) %> - ${HTML(render_bundle(entry))} + ${HTML(render_bundle(entry, extension=None, config='DEFAULT', attrs=attrs))} % if body: +<%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. + + <% + body = capture(caller.body) + %> + + % if not settings.REQUIRE_DEBUG: + + % endif + + + <%def name="require_module(module_name, class_name)"> <%doc> Loads Javascript onto your page synchronously. diff --git a/common/static/common/js/utils/page_factory.js b/common/static/common/js/utils/page_factory.js new file mode 100644 index 000000000000..8b3e72c827a7 --- /dev/null +++ b/common/static/common/js/utils/page_factory.js @@ -0,0 +1,27 @@ +define([], function() { + 'use strict'; + + return function invokePageFactory(name, factory) { + var args; + + if (typeof window.pageFactoryArguments === 'undefined') { + throw Error( + 'window.pageFactoryArguments must be initialized before calling invokePageFactory(' + + name + + '). Use the <%static:require_page> template tag.' + ); + } + args = window.pageFactoryArguments[name]; + + if (typeof args === 'undefined') { + throw Error( + 'window.pageFactoryArguments["' + + name + + '"] must be initialized before calling invokePageFactory(' + + name + + '). Use the <%static:require_page> template tag.' + ); + } + factory.apply(null, window.pageFactoryArguments[name]); + }; +}); diff --git a/conftest.py b/conftest.py index 1f32a76982e3..513e5f762d62 100644 --- a/conftest.py +++ b/conftest.py @@ -14,5 +14,5 @@ def no_webpack_loader(monkeypatch): monkeypatch.setattr( "webpack_loader.templatetags.webpack_loader.render_bundle", - lambda x: '' + lambda entry, extension=None, config='DEFAULT', attrs='': '' )