Example #1
0
def render():
    """
    Render HTML templates and compile assets.
    """
    from flask import g

    update_copy()
    less()
    jst()

    # Fake out deployment target
    deployment_target = app_config.DEPLOYMENT_TARGET
    app_config.configure_targets(env.get("settings", None))

    app_config_js()

    compiled_includes = []

    for rule in app.app.url_map.iter_rules():
        rule_string = rule.rule
        name = rule.endpoint

        if name == "static" or name.startswith("_"):
            print "Skipping %s" % name
            continue

        if rule_string.endswith("/"):
            filename = "www" + rule_string + "index.html"
        elif rule_string.endswith(".html") or rule_string.endswith(".xml") or rule_string.endswith(".js"):
            filename = "www" + rule_string
        else:
            print "Skipping %s" % name
            continue

        dirname = os.path.dirname(filename)

        if not (os.path.exists(dirname)):
            os.makedirs(dirname)

        print "Rendering %s" % (filename)

        with app.app.test_request_context(path=rule_string):
            g.compile_includes = True
            g.compiled_includes = compiled_includes

            view = app.__dict__[name]
            content = view()

            if isinstance(content, tuple):
                content = content[0]

            compiled_includes = g.compiled_includes

        with open(filename, "w") as f:
            f.write(content.encode("utf-8"))

    # We choose a sample playground to render so its JS will
    # be rendered. We don't deploy it.
    sample_playgrounds = models.Playground.select().limit(1)
    data.render_playgrounds(sample_playgrounds, compiled_includes)

    # Un-fake-out deployment target
    app_config.configure_targets(deployment_target)
Example #2
0
def render():
    """
    Render HTML templates and compile assets.
    """
    from flask import g

    update_copy()
    less()
    jst()

    # Fake out deployment target
    deployment_target = app_config.DEPLOYMENT_TARGET
    app_config.configure_targets(env.get('settings', None))

    app_config_js()

    compiled_includes = []

    for rule in app.app.url_map.iter_rules():
        rule_string = rule.rule
        name = rule.endpoint

        if name == 'static' or name.startswith('_'):
            print 'Skipping %s' % name
            continue

        if rule_string.endswith('/'):
            filename = 'www' + rule_string + 'index.html'
        elif rule_string.endswith('.html') or rule_string.endswith('.xml') or rule_string.endswith('.js'):
            filename = 'www' + rule_string
        else:
            print 'Skipping %s' % name
            continue

        dirname = os.path.dirname(filename)

        if not (os.path.exists(dirname)):
            os.makedirs(dirname)

        print 'Rendering %s' % (filename)

        with app.app.test_request_context(path=rule_string):
            g.compile_includes = True
            g.compiled_includes = compiled_includes

            view = app.__dict__[name]
            content = view()

            if isinstance(content, tuple):
                content = content[0]

            compiled_includes = g.compiled_includes

        with open(filename, 'w') as f:
            f.write(content.encode('utf-8'))

    # We choose a sample playground to render so its JS will
    # be rendered. We don't deploy it.
    sample_playgrounds = models.Playground.select().limit(1)
    data.render_playgrounds(sample_playgrounds)

    # Un-fake-out deployment target
    app_config.configure_targets(deployment_target)
Example #3
0
def render_playgrounds():
    data.render_playgrounds()
Example #4
0
def render_playgrounds():
    data.render_playgrounds()