当前位置: 首页>>代码示例>>Python>>正文


Python pystache.Renderer类代码示例

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


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


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