本文整理匯總了Python中wheezy.template.engine.Engine類的典型用法代碼示例。如果您正苦於以下問題:Python Engine類的具體用法?Python Engine怎麽用?Python Engine使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Engine類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: tohtml
def tohtml(self):
# TODO temporary
path = os.path.join(os.path.dirname(__file__), 'reader.html.template')
loader = DictLoader({'reader': open(path).read()})
engine = Engine(loader=loader, extensions=[CoreExtension()])
template = engine.get_template('reader')
return template.render({'feed': self}).encode('utf-8')
示例2: tohtml
def tohtml(self):
if DictLoader is None:
raise ImportError('dep wheezy.template needed')
loader = DictLoader({'reader': open('reader.html.template').read()})
engine = Engine(loader=loader, extensions=[CoreExtension()])
template = engine.get_template('reader')
return template.render({'feed': self}).encode('utf-8')
示例3: render
def render(self, result):
"""Take the function return value and renders a html document."""
templateFile = result["templatePath"]
context = result["context"]
searchPath = [""]
engine = Engine(loader=FileLoader(searchPath), extensions=[CoreExtension(), CodeExtension()])
template = engine.get_template(templateFile)
return template.render(context)
示例4: render
def render(self, source, ctx=None):
from wheezy.template.engine import Engine
from wheezy.template.ext.core import CoreExtension
from wheezy.template.loader import DictLoader
loader = DictLoader({'test.html': source})
engine = Engine(
loader=loader,
extensions=[CoreExtension()])
template = engine.get_template('test.html')
return template.render(ctx or {})
示例5: init_templates
def init_templates():
""" Initialize all templates.
"""
global g_template_dic
searchpath = ['mportal/templates']
engine = Engine(loader=FileLoader(searchpath),extensions=[CoreExtension()])
g_template_dic['login'] = engine.get_template('login.html')
g_template_dic['console'] = engine.get_template('console.html')
g_template_dic['not_found'] = engine.get_template('not_found.html')
g_template_dic['redirect'] = engine.get_template('redirect.html')
示例6: to_autopkg
def to_autopkg(self, outfile):
searchpath = [os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')]
engine = Engine(
loader=FileLoader(searchpath),
extensions=[CoreExtension()]
)
template = engine.get_template('redist-packages.autopkg')
autopkg = template.render({'package': self})
with open(outfile, 'w') as f:
f.write(autopkg)
return autopkg
示例7: get
def get(self):
fortunes = db_session.query(Fortune).all()
fortunes.append(Fortune(id=0, message="Additional fortune added at request time."))
fortunes.sort(key=attrgetter("message"))
engine = Engine(loader=FileLoader(["views"]), extensions=[CoreExtension()])
template = engine.get_template("fortune.html")
for f in fortunes:
f.message = bleach.clean(f.message)
template_html = template.render({"fortunes": fortunes})
response = HTTPResponse()
response.write(template_html)
return response
示例8: main
def main(args=None):
if not json: # pragma: nocover
print('error: json module is not available')
return 1
args = parse_args(args or sys.argv[1:])
if not args:
return 2
ts = args.token_start
extensions = [CoreExtension(ts), CodeExtension(ts)]
extensions.extend(args.extensions)
engine = Engine(FileLoader(args.searchpath), extensions)
engine.global_vars.update({'h': escape})
t = engine.get_template(args.template)
sys.stdout.write(t.render(load_context(args.context)))
return 0
示例9: generate_source
def generate_source(options, version, enums, functions_by_category, passthru, extensions, types, raw_enums):
template_pattern = re.compile("(.*).template")
# Sort by categories and sort the functions inside the categories
functions_by_category = sorted(functions_by_category
,key=lambda x: x[0])
functions_by_category = list(map(lambda c: (c[0], sorted(c[1], key=lambda x: x.name))
,functions_by_category))
template_namespace = {'passthru' : passthru,
'functions' : functions_by_category,
'enums' : enums,
'options' : options,
'version' : version,
'extensions': extensions,
'types': types,
'raw_enums': raw_enums}
if not os.path.isdir(options.template_dir):
print ('%s is not a directory' % options.template_dir)
exit(1)
if os.path.exists(options.outdir) and not os.path.isdir(options.outdir):
print ('%s is not a directory' % options.outdir)
exit(1)
if not os.path.exists(options.outdir):
os.mkdir(options.outdir)
engine = Engine(loader=FileLoader([options.template_dir]),extensions=[CoreExtension(),CodeExtension()])
generatedFiles = 0
allFiles = 0;
for template_path in glob('%s/*.template' % os.path.abspath(options.template_dir)):
infile = os.path.basename(template_path)
outfile = '%s/%s' % (options.outdir, template_pattern.match(infile).group(1))
template = engine.get_template(infile)
allFiles += 1
with open(outfile, 'w') as out:
out.write(template.render(template_namespace))
print("Successfully generated %s" % outfile)
generatedFiles += 1;
print("Generated %d of %d files" % (generatedFiles, allFiles))
示例10: __init__
def __init__(self, path):
self.path = path
template_dct = {
'docker': templates.docker,
}
engine = Engine(
loader=DictLoader(template_dct),
extensions=[
CoreExtension(),
CodeExtension()
]
)
self.templates = {
name: engine.get_template(name) for name in template_dct
}
示例11: setUp
def setUp(self):
from wheezy.template.engine import Engine
from wheezy.template.ext.core import CoreExtension
from wheezy.template.loader import DictLoader
self.templates = {}
self.engine = Engine(
loader=DictLoader(templates=self.templates),
extensions=[CoreExtension()])
示例12: generate_source
def generate_source(options, version, enums, functions_by_category, passthru, extensions):
generated_warning = '/* WARNING: This file was automatically generated */\n/* Do not edit. */\n'
template_pattern = re.compile("(.*).template")
template_namespace = {'passthru' : passthru,
'functions' : functions_by_category,
'enums' : enums,
'options' : options,
'version' : version,
'extensions': extensions}
if not os.path.isdir(options.template_dir):
print ('%s is not a directory' % options.template_dir)
exit(1)
if os.path.exists(options.outdir) and not os.path.isdir(options.outdir):
print ('%s is not a directory' % options.outdir)
exit(1)
if not os.path.exists(options.outdir):
os.mkdir(options.outdir)
engine = Engine(loader=FileLoader([options.template_dir]), extensions=[CoreExtension()])
generatedFiles = 0
allFiles = 0;
for template_path in glob('%s/*.template' % os.path.abspath(options.template_dir)):
infile = os.path.basename(template_path)
outfile = '%s/%s' % (options.outdir, template_pattern.match(infile).group(1))
template = engine.get_template(infile)
allFiles += 1
with open(outfile, 'w') as out:
out.write(generated_warning)
out.write(template.render(template_namespace))
print("Successfully generated %s" % outfile)
generatedFiles += 1;
print("Generated %d of %d files" % (generatedFiles, allFiles))
示例13: render
def render(outname, templatename, newcontext=None):
engine = Engine(
loader=FileLoader(['templates'], 'UTF-8'),
extensions=[CoreExtension()]
)
template = engine.get_template(templatename)
context = {
'title': WLOG_TITLE,
'wlog_url': WLOG_URL,
'site_url': SITE_URL,
'version': VERSION,
'categories': MAIN_CATEGORIES,
}
if newcontext:
context.update(newcontext)
output = template.render(context)
with open("output/{}.html".format(outname), 'w') as f:
f.write(output.encode('utf-8'))
示例14: EngineTestCase
class EngineTestCase(unittest.TestCase):
""" Test the ``Engine``.
"""
def setUp(self):
from wheezy.template.engine import Engine
from wheezy.template.loader import DictLoader
self.engine = Engine(
loader=DictLoader(templates={}),
extensions=[])
def test_template_not_found(self):
""" Raises IOError.
"""
self.assertRaises(IOError, lambda: self.engine.get_template('x'))
def test_import_not_found(self):
""" Raises IOError.
"""
self.assertRaises(IOError, lambda: self.engine.import_name('x'))
def test_remove_unknown_name(self):
""" Invalidate name that is not known to engine.
"""
self.engine.remove('x')
def test_remove_name(self):
""" Invalidate name that is known to engine.
"""
self.engine.templates['x'] = 'x'
self.engine.renders['x'] = 'x'
self.engine.modules['x'] = 'x'
self.engine.remove('x')
示例15: generate_html
def generate_html(self, filename, template_file="Default.html"):
engine = Engine(
loader=FileLoader(['templates']),
extensions=[CoreExtension()]
)
template = engine.get_template(template_file)
try:
file = open(filename, "w")
try:
clients_list_descendant = list(reversed(sorted(self.clients_hours.items(), key=lambda x: x[1])))
file.write(template.render({'clients_hours':clients_list_descendant,
'total_hours':str(self.total_hours_booked),
'unbooked_timeranges':self.get_unbooked_hours(),
'total_hours_unbooked': self.total_hours_unbooked}))
finally:
file.close()
except IOError:
pass