Exemple #1
0
def main():
    """@todo: Docstring for main.
    :returns: @todo

    """
    # Clear the frozen directory
    for file in os.listdir(FROZEN_DIR):
        if file != '.empty':
            path = os.path.abspath(os.path.join(FROZEN_DIR, file))
            if os.path.isdir(path):
                shutil.rmtree(path)
            else:
                os.remove(path)

    # Copy themes
    theme_dirs = get_theme_dirs()
    for theme_dir in theme_dirs:
        dest = os.path.join(FROZEN_DIR, theme_dir[0])
        shutil.copytree(theme_dir[1], dest)

    # Copy Uploads
    shutil.copytree(os.path.abspath('uploads/'), os.path.abspath(os.path.join(FROZEN_DIR, 'uploads/')))

    # Render all the templates
    with app.app_context():
        theme = get_current_theme()
        app.jinja_env.globals['theme_static'] = theme_static
        contents = Content.filter(Content.published == True).all()
        for content in contents:
            template = content.template
            f_template = 'freeze-{}'.format(content.template)
            freeze_template = os.path.join('impression/themes/',
                                           theme.identifier,
                                           'templates/',
                                           f_template)
            if (os.path.isfile(os.path.abspath(freeze_template))):
                template = f_template

            html = render(template, content=content, menu_items=get_menu_items(), freeze=True)
            with open('frozen/{}.html'.format(content.slug), 'w') as f:
                f.write(html)
Exemple #2
0
def theme_static(the_file, **kwargs):
    theme = get_current_theme()
    return '{}/static/{}'.format(theme.identifier, the_file)