本文整理汇总了Python中pystache.Renderer.render_name方法的典型用法代码示例。如果您正苦于以下问题:Python Renderer.render_name方法的具体用法?Python Renderer.render_name怎么用?Python Renderer.render_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pystache.Renderer
的用法示例。
在下文中一共展示了Renderer.render_name方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Plugin
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render_name [as 别名]
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)
示例2: MustacheRenderer
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render_name [as 别名]
class MustacheRenderer(BaseRenderer):
def __init__(self, handler, search_dirs, caching=True):
super(MustacheRenderer, self).__init__(handler)
if caching:
self.renderer = CachedRenderer(
handler.application.cache,
search_dirs=search_dirs)
else:
self.renderer = PystacheRenderer(search_dirs=search_dirs)
def _default_template_variables(self, kwargs):
super(MustacheRenderer, self)._default_template_variables(kwargs)
kwargs['xsrf_form_html'] = self.handler.xsrf_form_html()
def add_options_variables(self, kwargs):
kwargs['class_options_debug_html'] = 'debug' \
if options.debug_html else ''
kwargs['js_debug'] = 'true' \
if options.debug else 'false'
for option in options._options:
kwargs['option_' + option] = getattr(options, option)
def render_string_template(self, string_template, **kwargs):
self._default_template_variables(kwargs)
self.add_options_variables(kwargs)
return self.renderer.render(string_template, kwargs)
def render(self, template_name, context=None, **kwargs):
# template_name = "".join(template_name.split('.')[:-1])
self._default_template_variables(kwargs)
self.add_options_variables(kwargs)
kwargs['block_css'] = self.block_css
kwargs['block_javascript'] = self.block_javascript
return self.renderer.render_name(
template_name, context or self.handler, **kwargs)
def block_css(self, text, *args, **kwargs):
css_includes = load_json(text)
csses = []
for css_args in css_includes:
csses.append(self.add_css(**css_args))
return "\n".join(csses)
def block_javascript(self, text, *args, **kwargs):
js_includes = load_json(text)
jses = []
for js_args in js_includes:
jses.append(self.add_javascript(**js_args))
return "\n".join(jses)
def render_error(self, *args, **kwargs):
kwargs['option_debug?'] = options.debug
error_template = self.renderer.render_name(
"error", self.handler, *args, **kwargs)
return self.render("base", block_content=error_template)
示例3: _render_template
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render_name [as 别名]
def _render_template(self, template_name, template_data = None, partials = None):
r = Renderer(search_dirs=[ROOT_PATH+"/static/template/"],partials=partials)
template_data = self._add_in_default_data(template_data)
return r.render_name(template_name, template_data)
示例4: test_render_name
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render_name [as 别名]
def test_render_name(self):
"""Test the render_name() method."""
data_dir = get_data_path()
renderer = Renderer(search_dirs=data_dir)
actual = renderer.render_name("say_hello", to='foo')
self.assertString(actual, "Hello, foo")
示例5: _render_html
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import render_name [as 别名]
def _render_html(self, html_file):
r = Renderer(search_dirs=[ROOT_PATH+"/static/html/"],file_extension="html")
template_data = r.render_name(html_file)
return template_data