本文整理汇总了Python中pystache.renderer.Renderer类的典型用法代码示例。如果您正苦于以下问题:Python Renderer类的具体用法?Python Renderer怎么用?Python Renderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Renderer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:chuanzhang,项目名称:pystache,代码行数:30,代码来源:test_spec.py
示例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)
开发者ID:SvetlanaM,项目名称:EnabledCityPaloAlto,代码行数:7,代码来源:init.py
示例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: ')
开发者ID:jakearchibald,项目名称:pystache,代码行数:8,代码来源:test_renderer.py
示例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)
开发者ID:GaloisInc,项目名称:echronos,代码行数:8,代码来源:init.py
示例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
开发者ID:SvetlanaM,项目名称:EnabledCityPaloAlto,代码行数:9,代码来源:test_renderengine.py
示例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"
开发者ID:fitoria,项目名称:icaro-cli,代码行数:9,代码来源:__init__.py
示例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: é')
开发者ID:jakearchibald,项目名称:pystache,代码行数:10,代码来源:test_renderer.py
示例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')
开发者ID:jakearchibald,项目名称:pystache,代码行数:11,代码来源:test_renderer.py
示例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.")
开发者ID:Web5design,项目名称:autopilot,代码行数:12,代码来源:setup.py
示例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")
开发者ID:jakearchibald,项目名称:pystache,代码行数:12,代码来源:test_renderer.py
示例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")
开发者ID:jakearchibald,项目名称:pystache,代码行数:12,代码来源:test_renderer.py
示例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")
开发者ID:jakearchibald,项目名称:pystache,代码行数:12,代码来源:test_renderer.py
示例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")
开发者ID:jakearchibald,项目名称:pystache,代码行数:12,代码来源:test_renderer.py
示例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.")
开发者ID:jakearchibald,项目名称:pystache,代码行数:13,代码来源:test_renderer.py
示例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"é")
开发者ID:jakearchibald,项目名称:pystache,代码行数:13,代码来源:test_renderer.py
示例16: generate_page
def generate_page(self, articles):
view_model = {
"articles": articles,
"site_name": BaseController.settings["site_name"]
}
self.attach_meta_data(view_model)
loader = Loader(file_encoding='utf8', extension='html',
search_dirs=['view', ])
renderer = Renderer(file_encoding='utf8', file_extension='html',
search_dirs=['view/partials'])
template = loader.load_name('list')
html = renderer.render(template, view_model)
return html
开发者ID:Web5design,项目名称:autopilot,代码行数:14,代码来源:list.py
示例17: get
def get(self, article_name):
article_name = article_name.lower()
if article_name in BaseController.articles:
article = BaseController.articles[article_name]
# if content has not modified since last request
# send a 304 not modified status
modified_header_key = "If-Modified-Since"
if modified_header_key in self.request.headers:
if (self.request.headers["If-Modified-Since"] ==
article['modified_date']):
self.set_status(304)
return
if (BaseController.settings['enable_caching'] and
article_name in BaseController.cached_articles):
html = BaseController.cached_articles[article_name]
else:
view_model = {
"article": article,
"site_name": BaseController.settings['site_name']
}
self.attach_meta_data(view_model)
loader = Loader(file_encoding='utf8',
extension='html',
search_dirs=['view', ])
renderer = Renderer(file_encoding='utf8',
file_extension='html',
search_dirs=['view/partials'])
template = loader.load_name('article')
html = renderer.render(template, view_model)
# cache the html
BaseController.cached_articles[article_name] = html
# set http caching headers
if "http_caching_max_age" in BaseController.settings:
max_age = BaseController.settings["http_caching_max_age"]
else:
max_age = 60
self.set_header("Cache-control", "max-age=%s" % max_age)
self.set_header("Last-Modified", article['modified_date'])
self.write(html)
else:
raise tornado.web.HTTPError(404)
开发者ID:Web5design,项目名称:autopilot,代码行数:50,代码来源:article.py
示例18: render
def render(self, content, data):
"""
Render the given ``content`` as template with the ``data`` dictionary.
Args:
content (str): The template content to render.
data (dict): The data dictionary to render.
Returns:
str: The rendered template text
"""
stache = Renderer(partials=self._partials_loader)
return stache.render(content, data)
开发者ID:datafolklabs,项目名称:cement,代码行数:15,代码来源:ext_mustache.py
示例19: test_unicode__decode_errors
def test_unicode__decode_errors(self):
"""
Test that the decode_errors attribute is respected.
"""
renderer = Renderer()
renderer.default_encoding = "ascii"
s = "déf"
renderer.decode_errors = "ignore"
self.assertEquals(renderer.unicode(s), "df")
renderer.decode_errors = "replace"
# U+FFFD is the official Unicode replacement character.
self.assertEquals(renderer.unicode(s), u'd\ufffd\ufffdf')
开发者ID:jakearchibald,项目名称:pystache,代码行数:15,代码来源:test_renderer.py
示例20: test_render__nonascii_template
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 default_encoding are both respected.
renderer.decode_errors = 'ignore'
renderer.default_encoding = 'ascii'
self.assertEquals(renderer.render(template), "df")
renderer.default_encoding = 'utf_8'
self.assertEquals(renderer.render(template), u"déf")
开发者ID:jakearchibald,项目名称:pystache,代码行数:15,代码来源:test_renderer.py
注:本文中的pystache.renderer.Renderer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论