本文整理汇总了Python中pystache.renderer.Renderer类的典型用法代码示例。如果您正苦于以下问题:Python Renderer类的具体用法?Python Renderer怎么用?Python Renderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Renderer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
def test(self):
template = testData['template']
partials = testData.has_key('partials') and testData['partials'] or {}
expected = testData['expected']
data = testData['data']
# Convert code strings to functions.
# TODO: make this section of code easier to understand.
new_data = {}
for key, val in data.iteritems():
if isinstance(val, dict) and val.get('__tag__') == 'code':
val = eval(val['python'])
new_data[key] = val
renderer = Renderer(partials=partials)
actual = renderer.render(template, new_data)
actual = actual.encode('utf-8')
message = """%s
Template: \"""%s\"""
Expected: %s
Actual: %s
Expected: \"""%s\"""
Actual: \"""%s\"""
""" % (description, template, repr(expected), repr(actual), expected, actual)
self.assertEquals(actual, expected, message)
示例2: render
def render(template, context=None, **kwargs):
"""
Return the given template string rendered using the given context.
"""
renderer = Renderer()
return renderer.render(template, context, **kwargs)
示例3: test_read__decode_errors
def test_read__decode_errors(self):
filename = 'nonascii.mustache'
renderer = Renderer()
self.assertRaises(UnicodeDecodeError, self._read, renderer, filename)
renderer.decode_errors = 'ignore'
actual = self._read(renderer, filename)
self.assertEquals(actual, 'non-ascii: ')
示例4: render
def render(template, context=None, name=None, **kwargs):
"""
Return the given template string rendered using the given context.
"""
renderer = Renderer()
parsed_template = parse(template, name=name)
return renderer.render(parsed_template, context, **kwargs)
示例5: _engine
def _engine(self):
"""
Create and return a default RenderEngine for testing.
"""
renderer = Renderer(string_encoding='utf-8', missing_tags='strict')
engine = renderer._make_render_engine()
return engine
示例6: crear_plantilla
def crear_plantilla(archivo_fuente='user.c'):
print "creando plantilla para archivo %s" % archivo_fuente
renderer = Renderer()
template = renderer.load_template(SOURCE_TEMPLATE)
dato_plantilla = renderer.render(template, {'include_path': archivo_fuente})
archivo = open(SOURCE_FILE, 'w')
archivo.write(dato_plantilla)
archivo.close()
print "plantilla creada"
示例7: test_read__file_encoding
def test_read__file_encoding(self):
filename = 'nonascii.mustache'
renderer = Renderer()
renderer.file_encoding = 'ascii'
self.assertRaises(UnicodeDecodeError, self._read, renderer, filename)
renderer.file_encoding = 'utf-8'
actual = self._read(renderer, filename)
self.assertEquals(actual, u'non-ascii: é')
示例8: test_make_locator__file_extension
def test_make_locator__file_extension(self):
"""
Test that make_locator() respects the file_extension attribute.
"""
renderer = Renderer()
renderer.file_extension = 'foo'
locator = renderer.make_locator()
self.assertEquals(locator.template_extension, 'foo')
示例9: get
def get(self):
pass_phrase = self.authenticate_request()
if pass_phrase:
if self.check_setup():
loader = Loader(extension='html', search_dirs=['view', 'view/setup'])
renderer = Renderer(file_extension='html',
search_dirs=['view/partials', 'view/setup'])
template = loader.load_name('setup')
html = renderer.render(template, {"pass": pass_phrase})
self.write(html)
else:
self.write("setup already completed.")
示例10: test__escape__uses_renderer_unicode
def test__escape__uses_renderer_unicode(self):
"""
Test that escape uses the renderer's unicode function.
"""
renderer = Renderer()
renderer.unicode = lambda s: s.upper()
engine = renderer._make_render_engine()
escape = engine.escape
self.assertEquals(escape("foo"), "FOO")
示例11: test__escape__uses_renderer_escape
def test__escape__uses_renderer_escape(self):
"""
Test that escape uses the renderer's escape function.
"""
renderer = Renderer()
renderer.escape = lambda s: "**" + s
engine = renderer._make_render_engine()
escape = engine.escape
self.assertEquals(escape("foo"), "**foo")
示例12: test__literal__handles_unicode
def test__literal__handles_unicode(self):
"""
Test that literal doesn't try to "double decode" unicode.
"""
renderer = Renderer()
renderer.default_encoding = 'ascii'
engine = renderer._make_render_engine()
literal = engine.literal
self.assertEquals(literal(u"foo"), "foo")
示例13: test__literal__uses_renderer_unicode
def test__literal__uses_renderer_unicode(self):
"""
Test that literal uses the renderer's unicode function.
"""
renderer = Renderer()
renderer.unicode = lambda s: s.upper()
engine = renderer._make_render_engine()
literal = engine.literal
self.assertEquals(literal("foo"), "FOO")
示例14: test_make_load_partial
def test_make_load_partial(self):
"""
Test the _make_load_partial() method.
"""
renderer = Renderer()
renderer.partials = {'foo': 'bar'}
load_partial = renderer._make_load_partial()
actual = load_partial('foo')
self.assertEquals(actual, 'bar')
self.assertEquals(type(actual), unicode, "RenderEngine requires that "
"load_partial return unicode strings.")
示例15: test_unicode__default_encoding
def test_unicode__default_encoding(self):
"""
Test that the default_encoding attribute is respected.
"""
renderer = Renderer()
s = "é"
renderer.default_encoding = "ascii"
self.assertRaises(UnicodeDecodeError, renderer.unicode, s)
renderer.default_encoding = "utf-8"
self.assertEquals(renderer.unicode(s), u"é")