How to use the diazo.compiler.compile_theme function in diazo

To help you get started, we’ve selected a few diazo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TracyWebTech / django-revproxy / revproxy / transformer.py View on Github external
:param  rules: A file with a set of diazo rules to make a
                       transformation over the original response content
        :param  theme_template: A file containing the template used to format
                                the the original response content
        :param    is_html5: A boolean parameter to identify a html5 doctype
        :returns: A response with a content transformed based on the rules and
                  theme_template
        """

        if not self.should_transform():
            self.log.info("Don't need to be transformed")
            return self.response

        theme = loader.render_to_string(theme_template, context=context_data,
                                        request=self.request)
        output_xslt = compile_theme(
            rules=rules,
            theme=StringIO(theme),
        )

        transform = etree.XSLT(output_xslt)
        self.log.debug("Transform: %s", transform)

        charset = get_charset(self.response.get('Content-Type'))

        try:
            decoded_response = self.response.content.decode(charset)
        except UnicodeDecodeError:
            decoded_response = self.response.content.decode(charset, 'ignore')
            self.log.warning("Charset is {} and type of encode used in file is\
                              different. Some unknown characteres might be\
                              ignored.".format(charset))
github plone / plone.app.theming / src / plone / app / theming / utils.py View on Github external
accessControl = etree.XSLTAccessControl(
        read_file=True,
        write_file=False,
        create_dir=False,
        read_network=readNetwork,
        write_network=False
    )

    if absolutePrefix:
        absolutePrefix = expandAbsolutePrefix(absolutePrefix)
    params = set(['url', 'base', 'path', 'scheme', 'host'])
    params.update(parameterExpressions.keys())
    xslParams = {k: '' for k in params}

    compiledTheme = compile_theme(
        rules,
        absolute_prefix=absolutePrefix,
        parser=getParser('theme', readNetwork),
        rules_parser=getParser('rules', readNetwork),
        compiler_parser=getParser('compiler', readNetwork),
        read_network=readNetwork,
        access_control=accessControl,
        update=True,
        xsl_params=xslParams,
        runtrace=runtrace,
    )

    if not compiledTheme:
        return None

    return etree.XSLT(
github plone / diazo / lib / diazo / run.py View on Github external
runtrace = False
    if options.runtrace_xml or options.runtrace_html:
        runtrace = True

    parser = etree.HTMLParser()
    parser.resolvers.add(RunResolver(os.path.dirname(content)))

    if options.xsl is not None:
        output_xslt = etree.parse(options.xsl)
    else:
        xsl_params = None
        if options.xsl_params:
            xsl_params = split_params(options.xsl_params)

        output_xslt = compile_theme(
            rules=options.rules,
            theme=options.theme,
            extra=options.extra,
            parser=parser,
            read_network=options.read_network,
            absolute_prefix=options.absolute_prefix,
            includemode=options.includemode,
            indent=options.pretty_print,
            xsl_params=xsl_params,
            runtrace=runtrace,
        )

    if content == '-':
        content = sys.stdin

    if options.read_network:
github plone / diazo / lib / diazo / wsgi.py View on Github external
if self.read_network:
            rules_parser.resolvers.add(network_resolver)
        
        theme_parser = etree.HTMLParser()
        theme_parser.resolvers.add(filesystem_resolver)
        theme_parser.resolvers.add(wsgi_resolver)
        theme_parser.resolvers.add(python_resolver)
        if self.read_network:
            theme_parser.resolvers.add(network_resolver)
        
        xsl_params = self.params.copy()
        for value in self.environ_param_map.values():
            if value not in xsl_params:
                xsl_params[value] = None
        
        return compile_theme(self.rules,
                theme=self.theme,
                absolute_prefix=self.absolute_prefix,
                includemode=self.includemode,
                access_control=self.access_control,
                read_network=self.read_network,
                parser=theme_parser,
                rules_parser=rules_parser,
                xsl_params=xsl_params,
            )