• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pystache.Renderer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pystache.Renderer的典型用法代码示例。如果您正苦于以下问题:Python Renderer类的具体用法?Python Renderer怎么用?Python Renderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Renderer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_render__kwargs_and_no_context

    def test_render__kwargs_and_no_context(self):
        """
        Test render(): passing **kwargs and no context.

        """
        renderer = Renderer()
        self.assertEquals(renderer.render('Hi {{person}}', person='Mom'), 'Hi Mom')
开发者ID:chuanzhang,项目名称:pystache,代码行数:7,代码来源:test_renderer.py


示例2: test_callables

    def test_callables(self):
        view = Lambdas()
        view.template = '{{#replace_foo_with_bar}}foo != bar. oh, it does!{{/replace_foo_with_bar}}'

        renderer = Renderer()
        actual = renderer.render(view)
        self.assertString(actual, u'bar != bar. oh, it does!')
开发者ID:SvetlanaM,项目名称:EnabledCityPaloAlto,代码行数:7,代码来源:test_simple.py


示例3: test_higher_order_rot13

    def test_higher_order_rot13(self):
        view = Lambdas()
        view.template = '{{#rot13}}abcdefghijklm{{/rot13}}'

        renderer = Renderer()
        actual = renderer.render(view)
        self.assertString(actual, u'nopqrstuvwxyz')
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:7,代码来源:test_specloader.py


示例4: test_higher_order_lambda

    def test_higher_order_lambda(self):
        view = Lambdas()
        view.template = '{{#sort}}zyxwvutsrqponmlkjihgfedcba{{/sort}}'

        renderer = Renderer()
        actual = renderer.render(view)
        self.assertString(actual, u'abcdefghijklmnopqrstuvwxyz')
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:7,代码来源:test_specloader.py


示例5: test_hierarchical_partials_with_lambdas

    def test_hierarchical_partials_with_lambdas(self):
        view = Lambdas()
        view.template = '{{>partial_with_partial_and_lambda}}'

        renderer = Renderer(search_dirs=EXAMPLES_DIR)
        actual = renderer.render(view)
        self.assertString(actual, u'nopqrstuvwxyznopqrstuvwxyz')
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:7,代码来源:test_specloader.py


示例6: test_render__context_and_kwargs__precedence

    def test_render__context_and_kwargs__precedence(self):
        """
        Test render(): **kwargs takes precedence over context.

        """
        renderer = Renderer()
        self.assertEquals(renderer.render('Hi {{person}}', {'person': 'Mom'}, person='Dad'), 'Hi Dad')
开发者ID:chuanzhang,项目名称:pystache,代码行数:7,代码来源:test_renderer.py


示例7: Plugin

class Plugin(BasePlugin):
    name = "pystache"

    defaults = dict(
        path = ("templates",),
        extension = "mustache",
        encoding = "utf-8",
        partials = None,
        layout = None,
    )

    def __init__(self, **options):
        super().__init__(**options)
        self.renderer = None

    def setup(self, app):
        super().setup(app)

        if isinstance(self.cfg.path, str):
            self.cfg.path = [self.cfg.path]
        self.cfg.path = [P.abspath(p) for p in self.cfg.path]
        self.renderer = Renderer(file_encoding=self.cfg.encoding,
                search_dirs=self.cfg.path,
                file_extension=self.cfg.extension,
                partials=self.cfg.partials)

    @coroutine
    def render(self, path, layout=None, *ctx, **kw):
        layout = self.cfg.layout if layout is None else layout
        if layout:
            kw["yield"] = self.renderer.render_name(path, *ctx, **kw)
            path = layout
        return self.renderer.render_name(path, *ctx, **kw)
开发者ID:aperezdc,项目名称:tacitum,代码行数:33,代码来源:muffin_pystache.py


示例8: test_render__context

    def test_render__context(self):
        """
        Test render(): passing a context.

        """
        renderer = Renderer()
        self.assertEquals(renderer.render('Hi {{person}}', {'person': 'Mom'}), 'Hi Mom')
开发者ID:chuanzhang,项目名称:pystache,代码行数:7,代码来源:test_renderer.py


示例9: test_non_callable_attributes

    def test_non_callable_attributes(self):
        view = Simple()
        view.thing = 'Chris'

        renderer = Renderer()
        actual = renderer.render(view)
        self.assertEqual(actual, "Hi Chris!")
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:7,代码来源:test_specloader.py


示例10: test_nested_context

    def test_nested_context(self):
        renderer = Renderer()
        view = NestedContext(renderer)
        view.template = '{{#foo}}{{thing1}} and {{thing2}} and {{outer_thing}}{{/foo}}{{^foo}}Not foo!{{/foo}}'

        actual = renderer.render(view)
        self.assertString(actual, u"one and foo and two")
开发者ID:SvetlanaM,项目名称:EnabledCityPaloAlto,代码行数:7,代码来源:test_simple.py


示例11: test_partials_with_lambda

    def test_partials_with_lambda(self):
        view = Lambdas()
        view.template = '{{>partial_with_lambda}}'

        renderer = Renderer(search_dirs=EXAMPLES_DIR)
        actual = renderer.render(view)
        self.assertEqual(actual, u'nopqrstuvwxyz')
开发者ID:tobiasandtobias,项目名称:pystache,代码行数:7,代码来源:test_specloader.py


示例12: test_looping_and_negation_context

    def test_looping_and_negation_context(self):
        template = '{{#item}}{{header}}: {{name}} {{/item}}{{^item}} Shouldnt see me{{/item}}'
        context = Complex()

        renderer = Renderer()
        actual = renderer.render(template, context)
        self.assertEqual(actual, "Colors: red Colors: green Colors: blue ")
开发者ID:SvetlanaM,项目名称:EnabledCityPaloAlto,代码行数:7,代码来源:test_simple.py


示例13: test_delimiters

    def test_delimiters(self):
        renderer = Renderer()
        actual = renderer.render(Delimiters())
        self.assertString(actual, u"""\
* It worked the first time.
* And it worked the second time.
* Then, surprisingly, it worked the third time.
""")
开发者ID:SvetlanaM,项目名称:EnabledCityPaloAlto,代码行数:8,代码来源:test_examples.py


示例14: test_render__context_and_kwargs

    def test_render__context_and_kwargs(self):
        """
        Test render(): passing a context and **kwargs.

        """
        renderer = Renderer()
        template = 'Hi {{person1}} and {{person2}}'
        self.assertEquals(renderer.render(template, {'person1': 'Mom'}, person2='Dad'), 'Hi Mom and Dad')
开发者ID:chuanzhang,项目名称:pystache,代码行数:8,代码来源:test_renderer.py


示例15: test_render__return_type

    def test_render__return_type(self):
        """
        Check that render() returns a string of type unicode.

        """
        renderer = Renderer()
        rendered = renderer.render('foo')
        self.assertEquals(type(rendered), unicode)
开发者ID:chuanzhang,项目名称:pystache,代码行数:8,代码来源:test_renderer.py


示例16: __init__

 def __init__(self, handler, search_dirs, caching=True):
     super(MustacheRenderer, self).__init__(handler)
     if caching:
         self.renderer = CachedRenderer(
             handler.application.cache,
             search_dirs=search_dirs)
     else:
         self.renderer = PystacheRenderer(search_dirs=search_dirs)
开发者ID:jagguli,项目名称:stormbase,代码行数:8,代码来源:renderers.py


示例17: test_nested_context_is_available_in_view

    def test_nested_context_is_available_in_view(self):
        renderer = Renderer()

        view = NestedContext(renderer)
        view.template = "{{#herp}}{{#derp}}{{nested_context_in_view}}{{/derp}}{{/herp}}"

        actual = renderer.render(view)
        self.assertString(actual, u"it works!")
开发者ID:Gsarault44,项目名称:Cinder,代码行数:8,代码来源:test_examples.py


示例18: test_partial_in_partial_has_access_to_grand_parent_context

    def test_partial_in_partial_has_access_to_grand_parent_context(self):
        renderer = Renderer(search_dirs=EXAMPLES_DIR)

        view = TemplatePartial(renderer=renderer)
        view.template = """{{>partial_in_partial}}"""

        actual = renderer.render(view, {"prop": "derp"})
        self.assertEqual(actual, "Hi derp!")
开发者ID:Gsarault44,项目名称:Cinder,代码行数:8,代码来源:test_examples.py


示例19: test_partial_in_partial_has_access_to_grand_parent_context

    def test_partial_in_partial_has_access_to_grand_parent_context(self):
        renderer = Renderer(search_dirs=EXAMPLES_DIR)

        view = TemplatePartial(renderer=renderer)
        view.template = '''{{>partial_in_partial}}'''

        actual = renderer.render(view, {'prop': 'derp'})
        self.assertEqual(actual, 'Hi derp!')
开发者ID:SvetlanaM,项目名称:EnabledCityPaloAlto,代码行数:8,代码来源:test_examples.py


示例20: _render_template

    def _render_template(self, template_name, template_data = None, partials = None):
            
        r = Renderer(search_dirs=[ROOT_PATH+"/static/template/"],partials=partials)
        
        template_data = self._add_in_default_data(template_data)
        

        return r.render_name(template_name, template_data)
开发者ID:jordancode,项目名称:phil,代码行数:8,代码来源:template_response.py



注:本文中的pystache.Renderer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pystache.TemplateSpec类代码示例发布时间:2022-05-27
下一篇:
Python pystache.render函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap