<%page expression_filter="h"/> <%! import logging import json from django.contrib.staticfiles.storage import staticfiles_storage from pipeline_mako import compressed_css, compressed_js from pipeline_mako.helpers.studiofrontend import load_sfe_i18n_messages from django.utils.translation import get_language_bidi from mako.exceptions import TemplateLookupException from edxmako.shortcuts import marketing_link from openedx.core.djangolib.js_utils import js_escaped_string, dump_js_escaped_json from openedx.core.djangolib.markup import HTML from openedx.core.djangoapps.site_configuration.helpers import ( page_title_breadcrumbs, get_value, ) from openedx.core.djangoapps.theming.helpers import ( get_template_path, is_request_in_themed_site, ) from lms.djangoapps.certificates.api import get_asset_url_by_slug from webpack_loader.templatetags.webpack_loader import render_bundle logger = logging.getLogger(__name__) %> <%def name="marketing_link(name)"><% link = marketing_link(name) return "/" if link == "#" else link %> <%def name='url(file, raw=False)'><% try: url = staticfiles_storage.url(file) except: url = file ## HTML-escaping must be handled by caller %>${url | n, decode.utf8}${"?raw" if raw else ""} <%def name='certificate_asset_url(slug)'><% try: url = get_asset_url_by_slug(slug) except: url = '' ## HTML-escaping must be handled by caller %>${url | n, decode.utf8} <%def name='css(group, raw=False)'> <% rtl_group = '{}-rtl'.format(group) if get_language_bidi() and rtl_group in settings.PIPELINE_CSS: group = rtl_group %> % if settings.PIPELINE_ENABLED: ${compressed_css(group, raw=raw) | n, decode.utf8} % else: % for filename in settings.PIPELINE_CSS[group]['source_filenames']: % endfor %endif <%def name='js(group)'> % if settings.PIPELINE_ENABLED: ${compressed_js(group) | n, decode.utf8} % else: % for filename in settings.PIPELINE_JS[group]['source_filenames']: % endfor %endif ## A language-direction indicator, suitable for use in class="" attributes, ## for example: ## ## ## <%def name="dir_rtl()"><% return 'rtl' if get_language_bidi() else 'ltr' %> <%def name="include(path)"><% from django.conf import settings from django.template.engine import Engine from django.template.loaders.filesystem import Loader engine = Engine(dirs=settings.DEFAULT_TEMPLATE_ENGINE['DIRS']) source, template_path = Loader(engine).load_template_source(path) %>${source | n, decode.utf8} <%def name="studiofrontend(entry)"> <%doc> Loads a studio-frontend page, with the necessary context. Context is expected as a dictionary in the body of this tag. <% body = capture(caller.body) body_dict = json.loads(body) locale = body_dict['lang'] messages = load_sfe_i18n_messages(locale) %>
% if settings.STUDIO_FRONTEND_CONTAINER_URL: % else: % endif <%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. <% body = capture(caller.body) %> ${HTML(render_bundle(entry, extension=None, config='DEFAULT', attrs=attrs))} % if body: % endif <%def name="renderReact(component, id, props={})"> <%doc> Wrapper function to load a React component via webpack() and render it onto the page, passing an optional context object via props. component: (string) The component to render, as specified by the name of its Webpack entry point. id: (string) A unique id to apply to the component's container div. props: (dict, optional) An object containing data to pass into the component as props. ${HTML(render_bundle(component))} ${HTML(render_bundle('ReactRenderer'))}
<%def name="invoke_page_bundle(page_name, class_name=None)"> <%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 class_name: % endif <%self:webpack entry="${page_name}"/> <%def name="require_module(module_name, class_name)"> <%doc> Loads Javascript onto your page synchronously. Uses RequireJS in development and a plain script tag in production. Use this form of require_module for all new code. % if not settings.REQUIRE_DEBUG: % endif <%def name="require_module_async(module_name, class_name)"> <%doc> Legacy mode of require_module that operates asynchronously, required for certain edge cases (notably where Javascript is required outside of a <%block name="js_extra" or "headextra"). Do not use for any new code; instead create a factory and use require_module above. <%def name="optional_include_mako(file, is_theming_enabled=False)"><% # http://stackoverflow.com/q/21219531 if is_theming_enabled: file = get_template_path(file) try: tmpl = self.get_template(file) except TemplateLookupException: pass else: tmpl.render_context(context) %> <%def name="get_page_title_breadcrumbs(*args)"><% return page_title_breadcrumbs(*args) %> <%def name="get_platform_name()"><% return get_value('platform_name', settings.PLATFORM_NAME) %> <%def name="get_value(val_name, default=None, **kwargs)"><% return get_value(val_name, default=default, **kwargs) %> <%def name="get_template_path(relative_path, **kwargs)"><% return get_template_path(relative_path, **kwargs) %> <%def name="is_request_in_themed_site()"><% return is_request_in_themed_site() %> <%def name="get_tech_support_email_address()"><% return get_value('email_from_address', settings.TECH_SUPPORT_EMAIL) %> <%def name="get_contact_email_address()"><% return get_value('email_from_address', settings.CONTACT_EMAIL) %>