Example #1
0
def html(d,
         elements,
         title=None,
         css=[],
         js=[],
         gatag=None,
         rel='',
         tmplfname='generic.tmpl',
         globalvars=None,
         **kw):
    """Renders the given page with given js, css, etc.
    If gatag is given, then it's used as a google analytics id.
    If rel is given, it's used as the basis for local style sheets and javascripts.
    Otherwise, local scripts are at /static/
    Remote scripts are always fine.
    You can also specify globalvars as needed. zip and enumerate are always included.
    """
    out = stor(css=css, js=js, elements=elements, gatag=gatag, rel=rel)
    import web.template as template
    if not globalvars:
        globalvars = {}
    globalvars.update(dict(zip=zip, enumerate=enumerate))
    render = template.frender(tmplfname, globals=globalvars)
    if not title:
        title = d.title.title()
    out.title = title
    for k, v in kw.iteritems():
        out[k] = v
    return render(out)
Example #2
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_path = os.path.join(macro.MACRO_APP_ROOT, 'templates',
                                     template_name)
        _template_cache[template_name] = template = frender(
            template_path,
            globals={
                "INT": int,
                "STR": str,
                "SUM": sum,
                "LOGIN": get_sysname,
                "TOKEN": get_token,
                "CSRF": _get_csrf_input,
                "USER_TYPE": user_type,
                "DATE": convert_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,
                "CONFIG": config_read_setting,
                "SHA": CURRENT_SHA,
                "NOW": get_time,
                "THUMB": thumb_for_sub,
                "M": macro,
                "R": ratings,
                "SLUG": text.slug_for,
                "QUERY_STRING": query_string,
                "INLINE_JSON": html.inline_json,
                "CDNIFY": cdnify_url,
                "PATH": _get_path,
                "arrow": arrow,
                "constants": libweasyl.constants,
                "getattr": getattr,
                "json": json,
                "sorted": sorted,
                "staff": staff,
                "request": the_fake_request,
                "resource_path": get_resource_path,
            })

    return template
Example #3
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_path = os.path.join(macro.MACRO_SYS_BASE_PATH, 'templates', template_name)
        _template_cache[template_name] = template = frender(
            template_path,
            globals={
                "INT": int,
                "STR": str,
                "SUM": sum,
                "LOGIN": get_sysname,
                "TOKEN": get_token,
                "CSRF": get_csrf_token,
                "USER_TYPE": user_type,
                "DATE": convert_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,
                "CONFIG": config_read_setting,
                "SHA": CURRENT_SHA,
                "NOW": get_time,
                "THUMB": thumb_for_sub,
                "M": macro,
                "R": ratings,
                "SLUG": text.slug_for,
                "QUERY_STRING": query_string,
                "INLINE_JSON": html.inline_json,
                "CDNIFY": cdnify_url,
                "PATH": get_path,
                "arrow": arrow,
                "getattr": getattr,
                "sorted": sorted,
                "staff": staff,
                "request": the_fake_request,
                "resource_path": get_resource_path,
            })

    return template
Example #4
0
def html(d, elements, title=None, css=[], js=[], gatag=None, rel='', tmplfname='generic.tmpl', globalvars=None, **kw):
    """Renders the given page with given js, css, etc.
    If gatag is given, then it's used as a google analytics id.
    If rel is given, it's used as the basis for local style sheets and javascripts.
    Otherwise, local scripts are at /static/
    Remote scripts are always fine.
    You can also specify globalvars as needed. zip and enumerate are always included.
    """
    out = stor(css=css, js=js, elements=elements, gatag=gatag, rel=rel)
    import web.template as template
    if not globalvars:
        globalvars = {}
    globalvars.update(dict(zip=zip, enumerate=enumerate))
    render = template.frender(tmplfname, globals=globalvars)
    if not title:
        title = d.title.title()
    out.title = title
    for k, v in kw.iteritems():
        out[k] = v
    return render(out)
Example #5
0
 def GET(self):
     render = template.frender("templates/upload.html");
     return render();
Example #6
0
File: temp.py Project: VAEAZE/trunk
 def GET(self):
     render = template.frender("templates/form.html", globals={"name" : 'Lv9', 'get_id':get_id});
     return render();
Example #7
0
def renderDict(d, tmpl):
    """Renders a given dictionary to a string using the given template fname."""
    import web.template as template
    renfunc = template.frender(tmpl, globals=RENDER_GLOBALS)
    s = str(renfunc(d))
    return s
Example #8
0
def renderDict(d, tmpl):
    """Renders a given dictionary to a string using the given template fname."""
    import web.template as template
    renfunc = template.frender(tmpl, globals=RENDER_GLOBALS)
    s = str(renfunc(d))
    return s