Skip to content

Commit

Permalink
Just having one context argument for generic_renderer.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Oct 9, 2016
1 parent f36c640 commit 175ca48
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions nikola/nikola.py
Expand Up @@ -1986,7 +1986,7 @@ def scan_posts(self, really=False, ignore_quit=False, quiet=False):
sys.exit(1)
signal('scanned').send(self)

def generic_renderer(self, lang, output_name, template_name, filters, file_deps=None, uptodate_deps=None, pre_context=None, post_context=None, context_deps_remove=None, post_deps_dict=None, url_type=None):
def generic_renderer(self, lang, output_name, template_name, filters, file_deps=None, uptodate_deps=None, context=None, context_deps_remove=None, post_deps_dict=None, url_type=None):
"""Helper function for rendering pages and post lists and other related pages.
lang is the current language.
Expand All @@ -1995,22 +1995,19 @@ def generic_renderer(self, lang, output_name, template_name, filters, file_deps=
filters is the list of filters (usually site.config['FILTERS']) which will be used to post-process the result.
file_deps (optional) is a list of additional file dependencies (next to template and its dependencies).
uptodate_deps (optional) is a list of additional entries added to the task's uptodate list.
pre_context (optional) is a dict used as a basis for the template context. Its contents might be overwritten.
post_context (optional) is a dict merged into the context before passing it to the renderer.
context (optional) a dict used as a basis for the template context. The lang parameter will always be added.
context_deps_remove (optional) is a list of keys to remove from the context after using it as an uptodate dependency. This should name all keys containing non-trivial Python objects; they can be replaced by adding JSON-style dicts in post_deps_dict.
post_deps_dict (optional) is a dict merged into the copy of context which is used as an uptodate dependency.
url_type (optional) allows to override the ``URL_TYPE`` configuration
"""
utils.LocaleBorg().set_locale(lang)

file_deps = [] if file_deps is None else file_deps
file_deps = copy(file_deps) if file_deps else []
file_deps += self.template_system.template_deps(template_name)
file_deps = sorted(list(filter(None, file_deps)))

context = copy(pre_context) if pre_context else {}
context = copy(context) if context else {}
context["lang"] = lang
if post_context:
context.update(post_context)

deps_dict = copy(context)
if context_deps_remove:
Expand Down Expand Up @@ -2052,32 +2049,31 @@ def generic_page_renderer(self, lang, post, filters, context=None):
uptodate_deps = post.deps_uptodate(lang)
deps.extend(utils.get_asset_path(x, self.THEMES) for x in ('bundles', 'parent', 'engine'))

post_context = {}
post_context['post'] = post
post_context['title'] = post.title(lang)
post_context['description'] = post.description(lang)
post_context['permalink'] = post.permalink(lang)
context = copy(context) if context else {}
context['post'] = post
context['title'] = post.title(lang)
context['description'] = post.description(lang)
context['permalink'] = post.permalink(lang)
if 'pagekind' not in context:
post_context['pagekind'] = ['generic_page']
context['pagekind'] = ['generic_page']
if post.use_in_feeds:
post_context['enable_comments'] = True
context['enable_comments'] = True
else:
post_context['enable_comments'] = self.config['COMMENTS_IN_STORIES']
context['enable_comments'] = self.config['COMMENTS_IN_STORIES']

deps_dict = {}
if post.prev_post:
deps_dict['PREV_LINK'] = [post.prev_post.permalink(lang)]
if post.next_post:
deps_dict['NEXT_LINK'] = [post.next_post.permalink(lang)]
deps_dict['comments'] = post_context['enable_comments']
deps_dict['comments'] = context['enable_comments']
if post:
deps_dict['post_translations'] = post.translated_to

yield self.generic_renderer(lang, output_name, post.template_name, filters,
file_deps=deps,
uptodate_deps=uptodate_deps,
pre_context=context,
post_context=post_context,
context=context,
context_deps_remove=['post'],
post_deps_dict=deps_dict)

Expand All @@ -2089,22 +2085,22 @@ def generic_post_list_renderer(self, lang, posts, output_name, template_name, fi
deps += post.deps(lang)
uptodate_deps += post.deps_uptodate(lang)

post_context = {}
post_context["posts"] = posts
post_context["title"] = self.config['BLOG_TITLE'](lang)
post_context["description"] = self.config['BLOG_DESCRIPTION'](lang)
post_context["prevlink"] = None
post_context["nextlink"] = None
context = {}
context["posts"] = posts
context["title"] = self.config['BLOG_TITLE'](lang)
context["description"] = self.config['BLOG_DESCRIPTION'](lang)
context["prevlink"] = None
context["nextlink"] = None
if extra_context:
post_context.update(extra_context)
context.update(extra_context)

post_deps_dict = {}
post_deps_dict["posts"] = [(p.meta[lang]['title'], p.permalink(lang)) for p in posts]

return self.generic_renderer(lang, output_name, template_name, filters,
file_deps=deps,
uptodate_deps=uptodate_deps,
post_context=post_context,
context=context,
post_deps_dict=post_deps_dict)

def atom_feed_renderer(self, lang, posts, output_path, filters,
Expand Down

0 comments on commit 175ca48

Please sign in to comment.