Refactor info lookup into preview renderer ctor

This commit is contained in:
Tim Van Baak 2020-04-19 19:57:08 -07:00
parent 317fc07a45
commit 2705764a6a
2 changed files with 8 additions and 18 deletions

View File

@ -56,12 +56,12 @@ class HtmlRenderer():
class PreviewHtmlRenderer(): class PreviewHtmlRenderer():
def __init__(self, article_map): def __init__(self, lexicon):
""" with lexicon.ctx.read('info') as info:
article_map maps article titles to character ids. An article self.article_map = {
present in the map but mapped to None is a phantom article. title: article.character
""" for title, article in info.items()
self.article_map = article_map }
def TextSpan(self, span): def TextSpan(self, span):
return span.innertext return span.innertext

View File

@ -185,12 +185,7 @@ def get_bp():
return redirect(url_for('lexicon.session', name=name)) return redirect(url_for('lexicon.session', name=name))
parsed_draft = parse_raw_markdown(draft.contents) parsed_draft = parse_raw_markdown(draft.contents)
with g.lexicon.ctx.read('info') as info: rendered_html = parsed_draft.render(PreviewHtmlRenderer(g.lexicon))
authorship = {
title: article.character
for title, article in info.items()
}
rendered_html = parsed_draft.render(PreviewHtmlRenderer(authorship))
# If the article is ready and awaiting review # If the article is ready and awaiting review
if not draft.status.approved: if not draft.status.approved:
@ -324,12 +319,7 @@ def get_bp():
# check if article was previously approved # check if article was previously approved
# check extrinsic constraints for blocking errors # check extrinsic constraints for blocking errors
parsed_draft = parse_raw_markdown(article['contents']) parsed_draft = parse_raw_markdown(article['contents'])
with g.lexicon.ctx.read('info') as info: rendered_html = parsed_draft.render(PreviewHtmlRenderer(g.lexicon))
authorship = {
title: article.character
for title, article in info.items()
}
rendered_html = parsed_draft.render(PreviewHtmlRenderer(authorship))
features = parsed_draft.render(FeatureCounter()) features = parsed_draft.render(FeatureCounter())
filename = f'{article["character"]}.{article["aid"]}' filename = f'{article["character"]}.{article["aid"]}'