本文整理汇总了Python中genshi.template.plugin.MarkupTemplateEnginePlugin.loader方法的典型用法代码示例。如果您正苦于以下问题:Python MarkupTemplateEnginePlugin.loader方法的具体用法?Python MarkupTemplateEnginePlugin.loader怎么用?Python MarkupTemplateEnginePlugin.loader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类genshi.template.plugin.MarkupTemplateEnginePlugin
的用法示例。
在下文中一共展示了MarkupTemplateEnginePlugin.loader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_tw_middleware
# 需要导入模块: from genshi.template.plugin import MarkupTemplateEnginePlugin [as 别名]
# 或者: from genshi.template.plugin.MarkupTemplateEnginePlugin import loader [as 别名]
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
示例2: setup_tw_middleware
# 需要导入模块: from genshi.template.plugin import MarkupTemplateEnginePlugin [as 别名]
# 或者: from genshi.template.plugin.MarkupTemplateEnginePlugin import loader [as 别名]
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
示例3: create_tw_engine_manager
# 需要导入模块: from genshi.template.plugin import MarkupTemplateEnginePlugin [as 别名]
# 或者: from genshi.template.plugin.MarkupTemplateEnginePlugin import loader [as 别名]
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