示例#1
0
def _compile(template_name):
    """
    Compiles a template file and returns the result.
    """
    template = _template_cache.get(template_name)

    if template is None or reload_templates:
        _template_cache[template_name] = template = Template(
            pkgutil.get_data(__name__, 'templates/' + template_name).decode('utf-8'),
            filename=template_name,
            globals={
                "STR": str,
                "LOGIN": get_sysname,
                "TOKEN": get_token,
                "CSRF": _get_csrf_input,
                "USER_TYPE": user_type,
                "DATE": convert_date,
                "ISO8601_DATE": iso8601_date,
                "TIME": _convert_time,
                "LOCAL_ARROW": local_arrow,
                "PRICE": text_price_amount,
                "SYMBOL": text_price_symbol,
                "TITLE": titlebar,
                "RENDER": render,
                "COMPILE": _compile,
                "CAPTCHA": _captcha_public,
                "MARKDOWN": text.markdown,
                "MARKDOWN_EXCERPT": text.markdown_excerpt,
                "SUMMARIZE": summarize,
                "SHA": CURRENT_SHA,
                "NOW": get_time,
                "THUMB": thumb_for_sub,
                "WEBP_THUMB": webp_thumb_for_sub,
                "M": macro,
                "R": ratings,
                "SLUG": text.slug_for,
                "QUERY_STRING": query_string,
                "INLINE_JSON": html.inline_json,
                "PATH": _get_path,
                "arrow": arrow,
                "constants": libweasyl.constants,
                "getattr": getattr,
                "json": json,
                "sorted": sorted,
                "staff": staff,
                "resource_path": get_resource_path,
            })

    return template
def t(code, **keywords):
    tmpl = Template(code, **keywords)
    return lambda *a, **kw: TestResult(tmpl(*a, **kw))
示例#3
0
文件: template.py 项目: zgsgs/bili
def gettemplate(s: str) -> Template:
    f = open(f"webuihtml/{s}.html", 'r', encoding='utf8')
    t = Template(f.read())
    f.close()
    return t
示例#4
0
def getTemplate(name: str) -> Template:
    with open(f"html/{name}", "r", encoding='utf8') as f:
        t = f.read()
        return Template(t)
    return None
示例#5
0
def template_reader(path, **keywords):
    if Template:
        return Template(open(path).read(), filename=path, **keywords)
    return file_reader(path)