本文整理汇总了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')
示例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!')
示例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')
示例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')
示例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')
示例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')
示例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)
示例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')
示例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!")
示例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")
示例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')
示例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 ")
示例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.
""")
示例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')
示例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)