Esempio n. 1
0
    def render_to_page_load_sync_html(self, extension=None):
        """
        Generates the appropriate script tags for the bundle, be they JS or CSS
        files.

        :param bundle_data: The data returned from
        :return: HTML of script tags for insertion into a page.
        """
        tags = []
        js_tag = '<script type="text/javascript" src="{url}"></script>'
        css_tag = '<link type="text/css" href="{url}" rel="stylesheet"/>'
        for chunk in self.bundle_filtered(extension=extension):
            if chunk['name'].endswith('.js'):
                tags.append(js_tag.format(url=render_as_url(chunk)))
            elif chunk['name'].endswith('.css'):
                tags.append(css_tag.format(url=render_as_url(chunk)))
        return mark_safe('\n'.join(tags))
Esempio n. 2
0
    def render_to_page_load_async_html(self, extension=None):
        """
        Generates script tag containing Javascript to register an
        asynchronously loading Javascript FrontEnd plugin against the core
        front-end Kolibri app. It passes in the events that would trigger
        loading the plugin, both multi-time firing events (events) and one time
        firing events (once).

        It also passes in information about the methods that the events should
        be delegated to once the plugin has loaded.

        TODO: What do we do with the extension parameter here?

        :returns: HTML of a script tag to insert into a page.
        """
        urls = [render_as_url(chunk) for chunk in self.bundle]
        js = 'Kolibri.register_kolibri_module_async("{bundle}", ["{urls}"], {events}, {once});'.format(
            bundle=self.unique_slug,
            urls='","'.join(urls),
            events=json.dumps(self.events),
            once=json.dumps(self.once)
        )
        return mark_safe('<script>{js}</script>'.format(js=js))