New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactored generic_page_renderer and generic_post_list_renderer. #2519
Conversation
…e common function generic_renderer for some of the dirty work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, but could use some more documentation, and a small bug fix.
@@ -1986,38 +1986,27 @@ def scan_posts(self, really=False, ignore_quit=False, quiet=False): | |||
sys.exit(1) | |||
signal('scanned').send(self) | |||
|
|||
def generic_page_renderer(self, lang, post, filters, context=None): | |||
"""Render post fragments to final HTML pages.""" | |||
def generic_renderer(self, lang, output_name, template_name, filters, deps=[], uptodate_deps=[], pre_context=None, post_context=None, context_deps_remove=None, post_deps_dict=None, url_type=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can’t use deps=[], uptodate_deps=[]
. You should also document what arguments mean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed deps
to file_deps
. I also now documented all arguments.
deps_dict['PREV_LINK'] = [post.prev_post.permalink(lang)] | ||
if post.next_post: | ||
deps_dict['NEXT_LINK'] = [post.next_post.permalink(lang)] | ||
if context_deps_remove: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use a comment to explain this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean what context_deps_remove
does? That should now be covered in the argument documentation. Please tell me if that's enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s enough.
@@ -1986,38 +1986,40 @@ def scan_posts(self, really=False, ignore_quit=False, quiet=False): | |||
sys.exit(1) | |||
signal('scanned').send(self) | |||
|
|||
def generic_page_renderer(self, lang, post, filters, context=None): | |||
"""Render post fragments to final HTML pages.""" | |||
def generic_renderer(self, lang, output_name, template_name, filters, file_deps=[], uptodate_deps=[], pre_context=None, post_context=None, context_deps_remove=None, post_deps_dict=None, url_type=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant, you can’t provide an empty list as a default argument to file_deps and uptodate_deps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I forgot about that trap... I'll fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will merge when tests pass.
One note: this will cause all pages rendered with |
Also, another thing: the difference between |
|
|
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 {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a second copy here, just to override lang
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in case someone calls this function with the same context for different languages in a row. That person will be quite surprised if they all end up with the same lang
value in their context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Merging
Thanks for merging. I'll now update the plugin accordingly. |
Preliminary work for @Kwpolska's suggestion in getnikola/plugins#175.