當前位置: 首頁>>代碼示例>>Python>>正文


Python MarkupTemplateEnginePlugin.loader方法代碼示例

本文整理匯總了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
開發者ID:kiberpipa,項目名稱:mediacore,代碼行數:56,代碼來源:middleware.py

示例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
開發者ID:greentv,項目名稱:mediacore,代碼行數:48,代碼來源:middleware.py

示例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
開發者ID:knyar,項目名稱:mediadrop,代碼行數:38,代碼來源:middleware.py


注:本文中的genshi.template.plugin.MarkupTemplateEnginePlugin.loader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。