Parses the given template using the jinja environment of the given app
    and returns the AST. ASTs are cached in parse_template.cache
774049
def parse_template(app, filename):
    
    if not hasattr(parse_template, "cache"):
        parse_template.cache = {}
    if filename not in parse_template.cache:
        source = get_template_source(app, filename)
        parse_template.cache[filename] = app.jinja_env.parse(source, filename=filename)
    return parse_template.cache[filename]
260420
def render_template(env, html_path, template_filename, context):
    
    template = env.get_template(template_filename)
    rendered_html = template.render(**context)  # pylint: disable=no-member
    html_path.write_text(rendered_html, encoding='utf-8')
676277
def render_app_name(context, app, template="/admin_app_name.html"):
    
    try:
        template = app['app_label'] + template
        text = render_to_string(template, context)
    except:
        text = app['name']
    return text
524741
def get_template_for_path(path, use_cache=True):
    '''
    
    '''
    dmp = apps.get_app_config('django_mako_plus')
    app_path, template_name = os.path.split(path)
    return dmp.engine.get_template_loader_for_path(app_path, use_cache=use_cache).get_template(template_name)
939844
def stream_template(template_name, **context):
    '''
    
    '''
    app.update_template_context(context)
    template = app.jinja_env.get_template(template_name)
    stream = template.generate(context)
    return Response(stream_with_context(stream))
564986
def render(self, template, context_stack, delimiters=None):
        
        parsed_template = parse(template, delimiters)

        return parsed_template.render(self, context_stack)
895498
def partial_jinja_template(template_name, name='data', mimetype="text/html"):
    
    def partial_jinja_renderer(result, errors):
        template = get_jinja_template(template_name)
        old = template.environment.undefined
        template.environment.undefined = DebugUndefined
        context = {name: result or Mock(), 'errors': errors}
        rendered = template.render(**context)
        template.environment.undefined = old
        return {'body': rendered, 'mimetype': mimetype}
    return partial_jinja_renderer
186452
def apispec_to_template(app, spec, definitions=None, paths=None):
    
    definitions = definitions or []
    paths = paths or []
    spec_dict = spec.to_dict()

    with app.app_context():
        for definition in definitions:
            if isinstance(definition, (tuple, list)):
                name, schema = definition
            else:
                schema = definition
                name = schema.__name__.replace('Schema', '')

            spec.components.schema(name, schema=schema)

        for path in paths:
            spec.path(view=path)

    ret = ordered_dict_to_dict(spec_dict)
    return ret
772369
def find_referenced_templates(template, search_path):
    
    from jinja2 import Environment, meta
    env = Environment()
    ast = env.parse(template.read())
    referenced_templates = list(meta.find_referenced_templates(ast))

    def realpath(tpl):
        for path in search_path:
            t = os.path.realpath(os.path.join(path, tpl))
            if os.path.isfile(t):
                return t
        return None

    return [realpath(t) for t in referenced_templates if t is not None]
148383
def load_template_source(self, template_name, template_dirs=None):
        """"""
        #Get every app's folder
        log.error("Calling zip loader")
        for folder in app_template_dirs:
            if ".zip/" in folder.replace("\\", "/"):
                lib_file, relative_folder = get_zip_file_and_relative_path(folder)
                log.error(lib_file, relative_folder)
                try:
                    z = zipfile.ZipFile(lib_file)
                    log.error(relative_folder + template_name)
                    template_path_in_zip = os.path.join(relative_folder, template_name).replace("\\", "/")
                    source = z.read(template_path_in_zip)
                except (IOError, KeyError) as e:
                    import traceback
                    log.error(traceback.format_exc())
                    try:
                        z.close()
                    except:
                        pass
                    continue
                z.close()
                # We found a template, so return the source.
                template_path = "%s:%s" % (lib_file, template_path_in_zip)
                return (source, template_path)

        # If we reach here, the template couldn't be loaded
        raise TemplateDoesNotExist(template_name)
244795
async def render_template_string(source: str, **context: Any) -> str:
    
    await current_app.update_template_context(context)
    template = current_app.jinja_env.from_string(source)
    return await _render(template, context)
648148
def add_template_dirs(app):
    
    template_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')

    app.jinja_loader = jinja2.ChoiceLoader(
        [app.jinja_loader, jinja2.FileSystemLoader(template_dir)]
    )
1123004
def render_template(template_file, template_vars):
    """"""
    # Load our Jinja templates
    template_dir = "{0}/templates".format(
        os.path.dirname(os.path.abspath(__file__))
    )
    jinja_env = jinja2.Environment(
        loader=jinja2.FileSystemLoader(template_dir),
        trim_blocks=True
    )
    rendered = jinja_env.get_template(template_file).render(template_vars)

    return rendered
369261
def parse_route(cls, template):
        
        regex = ''
        last_pos = 0

        for match in cls.ROUTES_RE.finditer(template):
            regex += re.escape(template[last_pos:match.start()])
            var_name = match.group(1)
            expr = match.group(2) or '[^/]+'
            expr = '(?P<%s>%s)' % (var_name, expr)
            regex += expr
            last_pos = match.end()

        regex += re.escape(template[last_pos:])
        regex = '^%s$' % regex

        return re.compile(regex)
1077880
def render_template(self, template_file, target_file, template_vars = {}):
        
        template_dir = str(self.__class__.__name__).lower()
        template = self.jinja_env.get_template(os.path.join(template_dir, template_file))
        file_path = os.path.join(self.work_root, target_file)
        with open(file_path, 'w') as f:
            f.write(template.render(template_vars))
793553
def sbatch_template_str(self):
        """"""
        templates = self.campaign.process.sbatch_template
        if isinstance(templates, Mapping):
            # find proper template according to the tag
            template = templates.get(self.tag)
            if template is None:
                template = templates.get('*')
            if template is None:
                template = SBATCH_JINJA_TEMPLATE
        else:
            template = templates
        return template
1285043
def _get_template(self):
        
        loader = PackageLoader(self._package_name, 'assets/templates')
        env = Environment(extensions=['jinja2.ext.with_'], loader=loader)
        return env.get_template('{}.html'.format(self._report_name))