本文整理汇总了Python中pelican.generators.TemplatePagesGenerator类的典型用法代码示例。如果您正苦于以下问题:Python TemplatePagesGenerator类的具体用法?Python TemplatePagesGenerator怎么用?Python TemplatePagesGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TemplatePagesGenerator类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_turkish_locale
def test_turkish_locale(self):
if platform == 'win32':
locale_string = 'Turkish'
else:
locale_string = 'tr_TR.UTF-8'
settings = read_settings(
override={
'LOCALE': locale_string,
'TEMPLATE_PAGES': {
'template/source.html': 'generated/file.html'
}
})
generator = TemplatePagesGenerator(
{'date': self.date}, settings,
self.temp_content, '', self.temp_output)
generator.env.filters.update({'strftime': utils.DateFormatter()})
writer = Writer(self.temp_output, settings=settings)
generator.generate_output(writer)
output_path = os.path.join(
self.temp_output, 'generated', 'file.html')
# output file has been generated
self.assertTrue(os.path.exists(output_path))
# output content is correct
with utils.pelican_open(output_path) as output_file:
self.assertEqual(output_file,
utils.strftime(self.date, 'date = %A, %d %B %Y'))
示例2: test_generate_output
def test_generate_output(self):
settings = get_settings()
settings['STATIC_PATHS'] = ['static']
settings['TEMPLATE_PAGES'] = {
'template/source.html': 'generated/file.html'
}
generator = TemplatePagesGenerator({'foo': 'bar'}, settings,
self.temp_content, '', self.temp_output, None)
# create a dummy template file
template_dir = os.path.join(self.temp_content, 'template')
template_path = os.path.join(template_dir, 'source.html')
os.makedirs(template_dir)
with open(template_path, 'w') as template_file:
template_file.write(self.TEMPLATE_CONTENT)
writer = Writer(self.temp_output, settings=settings)
generator.generate_output(writer)
output_path = os.path.join(
self.temp_output, 'generated', 'file.html')
# output file has been generated
self.assertTrue(os.path.exists(output_path))
# output content is correct
with open(output_path, 'r') as output_file:
self.assertEqual(output_file.read(), 'foo: bar')
示例3: test_generate_output
def test_generate_output(self):
settings = get_settings()
settings["STATIC_PATHS"] = ["static"]
settings["TEMPLATE_PAGES"] = {"template/source.html": "generated/file.html"}
generator = TemplatePagesGenerator(
context={"foo": "bar"}, settings=settings, path=self.temp_content, theme="", output_path=self.temp_output
)
# create a dummy template file
template_dir = os.path.join(self.temp_content, "template")
template_path = os.path.join(template_dir, "source.html")
os.makedirs(template_dir)
with open(template_path, "w") as template_file:
template_file.write(self.TEMPLATE_CONTENT)
writer = Writer(self.temp_output, settings=settings)
generator.generate_output(writer)
output_path = os.path.join(self.temp_output, "generated", "file.html")
# output file has been generated
self.assertTrue(os.path.exists(output_path))
# output content is correct
with open(output_path, "r") as output_file:
self.assertEqual(output_file.read(), "foo: bar")
示例4: test_turkish_locale
def test_turkish_locale(self):
settings = read_settings(
override={
"LOCALE": locale.normalize("tr_TR.UTF-8"),
"TEMPLATE_PAGES": {"template/source.html": "generated/file.html"},
}
)
generator = TemplatePagesGenerator({"date": self.date}, settings, self.temp_content, "", self.temp_output)
generator.env.filters.update({"strftime": utils.DateFormatter()})
writer = Writer(self.temp_output, settings=settings)
generator.generate_output(writer)
output_path = os.path.join(self.temp_output, "generated", "file.html")
# output file has been generated
self.assertTrue(os.path.exists(output_path))
# output content is correct
with utils.pelican_open(output_path) as output_file:
self.assertEqual(output_file, utils.strftime(self.date, "date = %A, %d %B %Y"))
示例5: generate_output
def generate_output(self, article, templates, file_num):
settings = self.settings
settings['TEMPLATE_PAGES'] = templates
generator = TemplatePagesGenerator(
context={'article': article, 'current_page': file_num},
settings=settings,
path=settings['PATH'],
theme=settings['THEME'],
output_path=self.output_path
)
writer = Writer(self.output_path, settings=settings)
generator.generate_output(writer)
output_path = os.path.join(self.output_path, 'generated', 'file.html')
# output content is correct
with open(output_path, 'r') as output_file:
rendered_html = output_file.read()
return rendered_html