def __init__(self, engines=None, default_view='mako', translator=ugettext, template_paths=[], engine_options=None): if engines is None: opts = engine_options or {} opts.setdefault('mako.directories', template_paths) evf = opts.pop('extra_vars_func', None) engines = EngineManager(extra_vars_func=evf, options=opts) super(PylonsHostFramework, self).__init__(engines, default_view, translator)
def __init__(self, engines=None, default_view='toscawidgets', translator=lambda s: s, enable_runtime_checks=True): if engines is None: engines = EngineManager() self.engines = engines self._default_view = default_view self.translator = translator if not enable_runtime_checks: disable_runtime_checks()
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 __init__(self, engines=None, default_view='toscawidgets', translator=lambda s: s, enable_runtime_checks=True, default_engine=None, aggregation_config=None): if engines is None: engines = EngineManager() self.engines = engines self._default_view = default_view self._default_engine = default_engine if default_engine is None: self._default_engine = default_view self.translator = translator if not enable_runtime_checks: disable_runtime_checks() # these are for now not set up, # this is done lazy, see belowe self.aggregation_config = aggregation_config self.aggregated_js_mapping = {} self.aggregated_css_mapping = {} self.middleware = None