本文整理汇总了Python中pystache.renderer.Renderer.load_template方法的典型用法代码示例。如果您正苦于以下问题:Python Renderer.load_template方法的具体用法?Python Renderer.load_template怎么用?Python Renderer.load_template使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pystache.renderer.Renderer
的用法示例。
在下文中一共展示了Renderer.load_template方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: crear_plantilla
# 需要导入模块: from pystache.renderer import Renderer [as 别名]
# 或者: from pystache.renderer.Renderer import load_template [as 别名]
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"
示例2: main
# 需要导入模块: from pystache.renderer import Renderer [as 别名]
# 或者: from pystache.renderer.Renderer import load_template [as 别名]
def main(sys_argv=sys.argv):
template, context, c_format, multiple = parse_args(sys_argv, USAGE)
if template.endswith('.mustache'):
template = template[:-9]
renderer = Renderer()
try:
template = renderer.load_template(template)
except TemplateNotFoundError:
pass
if context.endswith(".csv") or (c_format and (c_format == "csv")):
try:
context = csv.DictReader(open(context, 'rb'))#, delimiter=',', quotechar='"')
except IOError:
print('ERROR: Could not parse context as CSV file. Check usage for input format options')
exit(-1)
else:
try:
context = json.load(open(context))
except IOError:
context = json.loads(context)
except ValueError: #likely a not well-formed JSON string, or user forgot -f csv.
print('ERROR: Could not parse context as JSON file or text, check usage for input format options')
exit(1)
if (multiple):
print ("multiple render on field %s" % multiple)
fileName, fileExt = os.path.splitext(multiple)
for i,c in enumerate(context):
if multiple in c:
f_name = str(c[multiple])
else:
f_name = "%s-%03d%s" % (fileName, i, fileExt)
with open(f_name, "w") as f: # mode "wx" could be used to prevent overwriting, + pass IOError, adding "--force" option to override.
rendered = renderer.render(template, c)
f.write(rendered)
print ("%s done") % f_name
else:
rendered = renderer.render(template, context)
print rendered
示例3: main
# 需要导入模块: from pystache.renderer import Renderer [as 别名]
# 或者: from pystache.renderer.Renderer import load_template [as 别名]
def main(sys_argv=sys.argv):
template, context = parse_args(sys_argv, USAGE)
if template.endswith('.mustache'):
template = template[:-9]
renderer = Renderer()
try:
template = renderer.load_template(template)
except IOError:
pass
try:
context = json.load(open(context))
except IOError:
context = json.loads(context)
rendered = renderer.render(template, context)
print rendered
示例4: MustacheEngine
# 需要导入模块: from pystache.renderer import Renderer [as 别名]
# 或者: from pystache.renderer.Renderer import load_template [as 别名]
class MustacheEngine(TemplateEngine):
"""
Mustache template engine.
"""
def __init__(self, **kw):
"""
Initialize the template renderer.
:param directories: Keyword parameter. A list of directories used as
the search path for templates.
"""
self.renderer = Renderer(search_dirs=kw['directories'])
TemplateEngine.__init__(self, **kw)
def get_template(self, name, **kw):
"""
Get a template.
:param name: The name of the template.
"""
parts = name.rsplit('.', 2)
if len(parts) > 1 and parts[1] == 'mustache':
name = parts[0]
return self.renderer.load_template(name)
def render(self, name, **kw):
"""
Render a template.
:param name: The name of the template.
:param **kw: The values to substitute in the template.
"""
template = self.templates.get(name, None)
return self.renderer.render(template, kw)
示例5: render
# 需要导入模块: from pystache.renderer import Renderer [as 别名]
# 或者: from pystache.renderer.Renderer import load_template [as 别名]
def render(self, *context, **kwargs):
renderer = Renderer(search_dirs=[thisDir()])
template = renderer.load_template('govuk_template')
return renderer.render(template, *context, **kwargs)