mirror of
https://github.com/venthur/blag.git
synced 2025-11-25 20:52:43 +00:00
fixed bug in blag where context was not provided to pages
This commit is contained in:
@@ -289,7 +289,7 @@ def process_markdown(convertibles, input_dir, output_dir,
|
|||||||
articles.append((dst, context))
|
articles.append((dst, context))
|
||||||
result = article_template.render(context)
|
result = article_template.render(context)
|
||||||
else:
|
else:
|
||||||
pages.append((dst, content))
|
pages.append((dst, context))
|
||||||
result = page_template.render(context)
|
result = page_template.render(context)
|
||||||
with open(f'{output_dir}/{dst}', 'w') as fh_dest:
|
with open(f'{output_dir}/{dst}', 'w') as fh_dest:
|
||||||
fh_dest.write(result)
|
fh_dest.write(result)
|
||||||
|
|||||||
@@ -177,3 +177,59 @@ def test_environment_factory():
|
|||||||
env = blag.environment_factory(globals_=globals_)
|
env = blag.environment_factory(globals_=globals_)
|
||||||
assert env.globals['foo'] == 'bar'
|
assert env.globals['foo'] == 'bar'
|
||||||
assert env.globals['test'] == 'me'
|
assert env.globals['test'] == 'me'
|
||||||
|
|
||||||
|
|
||||||
|
def test_process_markdown(tempdir, page_template, article_template):
|
||||||
|
inputdir = f'{tempdir}/content'
|
||||||
|
outdir = f'{tempdir}/build'
|
||||||
|
page1 = """\
|
||||||
|
title: some page
|
||||||
|
|
||||||
|
some text
|
||||||
|
foo bar
|
||||||
|
"""
|
||||||
|
|
||||||
|
article1 = """\
|
||||||
|
title: some article1
|
||||||
|
date: 2020-01-01
|
||||||
|
|
||||||
|
some text
|
||||||
|
foo bar
|
||||||
|
"""
|
||||||
|
|
||||||
|
article2 = """\
|
||||||
|
title: some article2
|
||||||
|
date: 2021-01-01
|
||||||
|
|
||||||
|
some text
|
||||||
|
foo bar
|
||||||
|
"""
|
||||||
|
|
||||||
|
convertibles = []
|
||||||
|
for i, txt in enumerate((page1, article1, article2)):
|
||||||
|
i = str(i)
|
||||||
|
with open(f'{inputdir}/{i}', 'w') as fh:
|
||||||
|
fh.write(txt)
|
||||||
|
convertibles.append([i, i])
|
||||||
|
|
||||||
|
articles, pages = blag.process_markdown(
|
||||||
|
convertibles,
|
||||||
|
inputdir,
|
||||||
|
outdir,
|
||||||
|
page_template,
|
||||||
|
article_template
|
||||||
|
)
|
||||||
|
|
||||||
|
assert isinstance(articles, list)
|
||||||
|
assert len(articles) == 2
|
||||||
|
for dst, context in articles:
|
||||||
|
assert isinstance(dst, str)
|
||||||
|
assert isinstance(context, dict)
|
||||||
|
assert 'content' in context
|
||||||
|
|
||||||
|
assert isinstance(pages, list)
|
||||||
|
assert len(pages) == 1
|
||||||
|
for dst, context in pages:
|
||||||
|
assert isinstance(dst, str)
|
||||||
|
assert isinstance(context, dict)
|
||||||
|
assert 'content' in context
|
||||||
|
|||||||
Reference in New Issue
Block a user