Example #1
0
 def renderer_for_inline_tag(self, inline_tag):
     for k, v in self._raw.get("plugins", {}).get("renderer", {}).items():
         if inline_tag == v.get("inline_tag"):
             classpath = v.get("class")
             klazz = plugin.load_class(classpath)
             return klazz(k)
     return None
Example #2
0
 def renderer_for_file_suffix(self, suffix):
     for k, v in self._raw.get("plugins", {}).get("renderer", {}).items():
         if suffix in v.get("file_suffixes", []):
             classpath = v.get("class")
             klazz = plugin.load_class(classpath)
             return klazz(k)
     return None
Example #3
0
 def data_plugin(self, type, shape):
     typecfg = self._data_plugin_by_suffix(type)
     classpath = typecfg.get("shapes", {}).get(shape)
     if classpath is None:
         raise exceptions.ConfigurationException(
             "No shape '{x}' for type '{y}'".format(x=shape, y=type))
     return plugin.load_class(classpath)
Example #4
0
 def default_data_plugin(self, type):
     typecfg = self._data_plugin_by_suffix(type)
     default = typecfg.get("default")
     if default is None:
         raise exceptions.ConfigurationException(
             "No default provided for '{x}'".format(x=type))
     classpath = typecfg.get("shapes", {}).get(default)
     return plugin.load_class(classpath)
Example #5
0
def _compile_templates():
    config = context.config
    bd = config.build_dir()
    post_template_dir = os.path.join(bd, "post_template")
    post_markup_dir = os.path.join(bd, "post_markup")
    src_dir = config.src_dir()
    content_path = os.path.join(src_dir, "content")
    templates_path = os.path.join(src_dir, "templates")

    # prep the extensions
    extensions = []
    for k, v in config.renderers().items():
        if "jinja2_extension" in v:
            ext_klazz = plugin.load_class(v["jinja2_extension"])
            extensions.append(ext_klazz)

    # set up the initial environment with the essential globals
    env = Environment(
        loader=MarkupWrapperLoader(
            FileSystemLoader([content_path, templates_path]), config),
        autoescape=
        False,  # select_autoescape(['html'], default_for_string=False),
        extensions=extensions)
    env.globals.update(config=context.config, data=context.data)

    # add any additional globals that will be available
    globals_def = {}
    util_defs = config.utils()
    for k, v in util_defs.items():
        fn = plugin.load_function(v.get("function"))
        globals_def[k] = fn
    env.globals.update(**globals_def)

    pages = []
    pages_path = os.path.join(content_path, "pages")
    for dirpath, dirnames, filenames in os.walk(pages_path):
        for fn in filenames:
            sub_path = dirpath[len(pages_path) + 1:]
            pages.append(os.path.join(sub_path, fn))

    for page in pages:
        # render the template from file the first time
        template = env.get_template(os.path.join("pages", page))
        two = template.render()
        one = ""

        # now keep rendering until we have rendered everything renderable
        # FIXME: we should record each iteration of the template for review in the build dir
        while one != two:
            one = two
            template = env.from_string(one)
            two = template.render()

        outfile = os.path.join(post_template_dir, page)
        outdir = os.path.dirname(outfile)
        if not os.path.exists(outdir):
            os.makedirs(outdir)
        with codecs.open(outfile, "wb", "utf-8") as f:
            f.write(two)

    # now we want to reinit the jinja environment, this time with extensions enabled
    # set up the new environment with the essential globals and extensions
    """