Example #1
0
def packageCallback_genshisolari(packagename):
    print "packageCallback_genshisolari", packagename
    _loader_dict[packagename] = loader.package(packagename, '_webapp/templates')

    templateLoader = TemplateLoader(loader.prefixed(**_loader_dict), max_cache_size=100*len(_loader_dict))

    def generate_tmpl(template_path, data=None, cls=None):
        render_dict = {}

        if tmpl.__dict__:
            render_dict.update(tmpl.__dict__)

        if data:
            render_dict.update(data)

        return templateLoader.load(template_path, cls=cls).generate(**render_dict)

    def text(template_path, data=None, method='text'):
        return generate_tmpl(template_path, data, NewTextTemplate).render(method)

    def render(template_path, data=None, method='xhtml'):
        return generate_tmpl(template_path, data).render(method)

    def serialize(template_path, data=None, method='xhtml'):
        return generate_tmpl(template_path, data).serialize(method)

    context.defaults(
            templateLoader = templateLoader,
            text = text,
            render = render,
            serialize  = serialize,
        )
Example #2
0
def setup_tw_middleware(app, config):
    # Set up the TW middleware, as per errors and instructions at:
    # http://groups.google.com/group/toscawidgets-discuss/browse_thread/thread/c06950b8d1f62db9
    # http://toscawidgets.org/documentation/ToscaWidgets/install/pylons_app.html
    def enable_i18n_for_template(template):
        template.filters.insert(0, Translator(ugettext))

    def filename_suffix_adder(inner_loader, suffix):
        def _add_suffix(filename):
            return inner_loader(filename + suffix)

        return _add_suffix

    # Ensure that the toscawidgets template loader includes the search paths
    # from our main template loader.
    tw_engine_options = {"genshi.loader_callback": enable_i18n_for_template}
    tw_engines = EngineManager(extra_vars_func=None, options=tw_engine_options)
    tw_engines["genshi"] = MarkupTemplateEnginePlugin()
    tw_engines["genshi"].loader = config["pylons.app_globals"].genshi_loader

    # Disable the built-in package name template resolution.
    tw_engines["genshi"].use_package_naming = False

    # Rebuild package name template resolution using mostly standard Genshi
    # load functions. With our customizations to the TemplateLoader, the
    # absolute paths that the builtin resolution produces are erroneously
    # treated as being relative to the search path.

    # Search the tw templates dir using the pkg_resources API.
    # Expected input: 'input_field.html'
    tw_loader = loader.package("tw.forms", "templates")

    # Include the .html extension automatically.
    # Expected input: 'input_field'
    tw_loader = filename_suffix_adder(tw_loader, ".html")

    # Apply this loader only when the filename starts with tw.forms.templates.
    # This prefix is stripped off when calling the above loader.
    # Expected input: 'tw.forms.templates.input_field'
    tw_loader = loader.prefixed(**{"tw.forms.templates.": tw_loader})

    # Add this path to our global loader
    tw_engines["genshi"].loader.search_path.append(tw_loader)

    app = tw.api.make_middleware(
        app,
        {
            "toscawidgets.framework": "pylons",
            "toscawidgets.framework.default_view": "genshi",
            "toscawidgets.framework.translator": lazy_ugettext,
            "toscawidgets.framework.engines": tw_engines,
        },
    )
    return app
Example #3
0
def setup_tw_middleware(app, config):
    def filename_suffix_adder(inner_loader, suffix):
        def _add_suffix(filename):
            return inner_loader(filename + suffix)

        return _add_suffix

    # Ensure that the toscawidgets template loader includes the search paths
    # from our main template loader.
    tw_engines = EngineManager(extra_vars_func=None)
    tw_engines["genshi"] = MarkupTemplateEnginePlugin()
    tw_engines["genshi"].loader = config["pylons.app_globals"].genshi_loader

    # Disable the built-in package name template resolution.
    tw_engines["genshi"].use_package_naming = False

    # Rebuild package name template resolution using mostly standard Genshi
    # load functions. With our customizations to the TemplateLoader, the
    # absolute paths that the builtin resolution produces are erroneously
    # treated as being relative to the search path.

    # Search the tw templates dir using the pkg_resources API.
    # Expected input: 'input_field.html'
    tw_loader = loader.package("tw.forms", "templates")

    # Include the .html extension automatically.
    # Expected input: 'input_field'
    tw_loader = filename_suffix_adder(tw_loader, ".html")

    # Apply this loader only when the filename starts with tw.forms.templates.
    # This prefix is stripped off when calling the above loader.
    # Expected input: 'tw.forms.templates.input_field'
    tw_loader = loader.prefixed(**{"tw.forms.templates.": tw_loader})

    # Add this path to our global loader
    tw_engines["genshi"].loader.search_path.append(tw_loader)

    app = tw.api.make_middleware(
        app,
        {
            "toscawidgets.framework": "pylons",
            "toscawidgets.framework.default_view": "genshi",
            "toscawidgets.framework.engines": tw_engines,
        },
    )
    return app
def setup_tw_middleware(app, config):
    def filename_suffix_adder(inner_loader, suffix):
        def _add_suffix(filename):
            return inner_loader(filename + suffix)

        return _add_suffix

    # Ensure that the toscawidgets template loader includes the search paths
    # from our main template loader.
    tw_engines = EngineManager(extra_vars_func=None)
    tw_engines['genshi'] = MarkupTemplateEnginePlugin()
    tw_engines['genshi'].loader = config['pylons.app_globals'].genshi_loader

    # Disable the built-in package name template resolution.
    tw_engines['genshi'].use_package_naming = False

    # Rebuild package name template resolution using mostly standard Genshi
    # load functions. With our customizations to the TemplateLoader, the
    # absolute paths that the builtin resolution produces are erroneously
    # treated as being relative to the search path.

    # Search the tw templates dir using the pkg_resources API.
    # Expected input: 'input_field.html'
    tw_loader = loader.package('tw.forms', 'templates')

    # Include the .html extension automatically.
    # Expected input: 'input_field'
    tw_loader = filename_suffix_adder(tw_loader, '.html')

    # Apply this loader only when the filename starts with tw.forms.templates.
    # This prefix is stripped off when calling the above loader.
    # Expected input: 'tw.forms.templates.input_field'
    tw_loader = loader.prefixed(**{'tw.forms.templates.': tw_loader})

    # Add this path to our global loader
    tw_engines['genshi'].loader.search_path.append(tw_loader)

    app = tw.api.make_middleware(
        app, {
            'toscawidgets.framework': 'pylons',
            'toscawidgets.framework.default_view': 'genshi',
            'toscawidgets.framework.engines': tw_engines,
        })
    return app
Example #5
0
def create_tw_engine_manager(app_globals):
    def filename_suffix_adder(inner_loader, suffix):
        def _add_suffix(filename):
            return inner_loader(filename + suffix)
        return _add_suffix

    # Ensure that the toscawidgets template loader includes the search paths
    # from our main template loader.
    tw_engines = EngineManager(extra_vars_func=None)
    tw_engines['genshi'] = MarkupTemplateEnginePlugin()
    tw_engines['genshi'].loader = app_globals.genshi_loader

    # Disable the built-in package name template resolution.
    tw_engines['genshi'].use_package_naming = False

    # Rebuild package name template resolution using mostly standard Genshi
    # load functions. With our customizations to the TemplateLoader, the
    # absolute paths that the builtin resolution produces are erroneously
    # treated as being relative to the search path.

    # Search the tw templates dir using the pkg_resources API.
    # Expected input: 'input_field.html'
    tw_loader = loader.package('tw.forms', 'templates')

    # Include the .html extension automatically.
    # Expected input: 'input_field'
    tw_loader = filename_suffix_adder(tw_loader, '.html')

    # Apply this loader only when the filename starts with tw.forms.templates.
    # This prefix is stripped off when calling the above loader.
    # Expected input: 'tw.forms.templates.input_field'
    tw_loader = loader.prefixed(**{'tw.forms.templates.': tw_loader})

    # Add this path to our global loader
    tw_engines['genshi'].loader.search_path.append(tw_loader)
    return tw_engines