本文整理汇总了Python中pystache.Renderer.render方法的典型用法代码示例。如果您正苦于以下问题:Python Renderer.render方法的具体用法?Python Renderer.render怎么用?Python Renderer.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pystache.Renderer
的用法示例。
在下文中一共展示了Renderer.render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_nonexist_formatter
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render [as 别名]
def test_nonexist_formatter(self):
renderer = Renderer()
renderer.register_formatter('u', lambda x: x.upper())
self.assertRaises(FormatterNotFoundError, renderer.render, '{{foo|x}}', {'foo': 'bar'})
try:
renderer.render('{{foo|x}}', {'foo': 'bar'})
except FormatterNotFoundError as e:
self.assertString('None:1.0', str(e.location))
示例2: test_render__kwargs_does_not_modify_context
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render [as 别名]
def test_render__kwargs_does_not_modify_context(self):
"""
Test render(): passing **kwargs does not modify the passed context.
"""
context = {}
renderer = Renderer()
renderer.render('Hi {{person}}', context=context, foo="bar")
self.assertEquals(context, {})
示例3: test_rendering_partial
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render [as 别名]
def test_rendering_partial(self):
renderer = Renderer(search_dirs=EXAMPLES_DIR)
view = TemplatePartial(renderer=renderer)
view.template = '{{>inner_partial}}'
actual = renderer.render(view)
self.assertString(actual, u'Again, Welcome!')
view.template = '{{#looping}}{{>inner_partial}} {{/looping}}'
actual = renderer.render(view)
self.assertString(actual, u"Again, Welcome! Again, Welcome! Again, Welcome! ")
示例4: test_render__object
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render [as 别名]
def test_render__object(self):
"""
Test rendering an object instance.
"""
renderer = Renderer()
say_hello = SayHello()
actual = renderer.render(say_hello)
self.assertEqual('Hello, World', actual)
actual = renderer.render(say_hello, to='Mars')
self.assertEqual('Hello, Mars', actual)
示例5: test_render__nonascii_template
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render [as 别名]
def test_render__nonascii_template(self):
"""
Test passing a non-unicode template with non-ascii characters.
"""
renderer = Renderer()
template = "déf"
# Check that decode_errors and string_encoding are both respected.
renderer.decode_errors = 'ignore'
renderer.string_encoding = 'ascii'
self.assertEquals(renderer.render(template), "df")
renderer.string_encoding = 'utf_8'
self.assertEquals(renderer.render(template), u"déf")
示例6: test_template_path_for_partials
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render [as 别名]
def test_template_path_for_partials(self):
"""
Test that View.template_rel_path is respected for partials.
"""
spec = TemplateSpec()
spec.template = "Partial: {{>tagless}}"
renderer1 = Renderer()
renderer2 = Renderer(search_dirs=EXAMPLES_DIR)
actual = renderer1.render(spec)
self.assertString(actual, "Partial: ")
actual = renderer2.render(spec)
self.assertEqual(actual, "Partial: No tags...")
示例7: test_hierarchical_partials_with_lambdas
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render [as 别名]
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')
示例8: test_higher_order_rot13
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render [as 别名]
def test_higher_order_rot13(self):
view = Lambdas()
view.template = '{{#rot13}}abcdefghijklm{{/rot13}}'
renderer = Renderer()
actual = renderer.render(view)
self.assertString(actual, u'nopqrstuvwxyz')
示例9: test_higher_order_lambda
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render [as 别名]
def test_higher_order_lambda(self):
view = Lambdas()
view.template = '{{#sort}}zyxwvutsrqponmlkjihgfedcba{{/sort}}'
renderer = Renderer()
actual = renderer.render(view)
self.assertString(actual, u'abcdefghijklmnopqrstuvwxyz')
示例10: test_nested_context
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render [as 别名]
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_looping_and_negation_context
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render [as 别名]
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 ")
示例12: test_render__context_and_kwargs__precedence
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render [as 别名]
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')
示例13: test_render__context
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render [as 别名]
def test_render__context(self):
"""
Test render(): passing a context.
"""
renderer = Renderer()
self.assertEquals(renderer.render('Hi {{person}}', {'person': 'Mom'}), 'Hi Mom')
示例14: test_render__kwargs_and_no_context
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render [as 别名]
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')
示例15: test_callables
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render [as 别名]
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!')