Permalink
Browse files

Remove code duplication, makes things neater

  • Loading branch information...
1 parent eceb78f commit c4bf91a2a1a0c16d8dd6e4d6fa5a7deee75da4b2 @ralsina committed Sep 25, 2012
Showing with 13 additions and 20 deletions.
  1. +2 −3 docs/extending.txt
  2. +5 −1 nikola/nikola.py
  3. +2 −2 nikola/plugin_categories.py
  4. +2 −7 nikola/plugins/template_jinja.py
  5. +2 −7 nikola/plugins/template_mako.py
View
@@ -190,9 +190,8 @@ a stub for a hypothetical system called "Templater":
# The method that does the actual rendering.
# template_name is the name of the template file,
# output_name is the file for the output, context
- # and global_context are dictionaries containing
- # the data the template must use for rendering.
- # context takes priority over global_context.
+ # is a dictionary containing the data the template
+ # uses for rendering.
def render_template(self, template_name, output_name,
context, global_context):
View
@@ -192,8 +192,12 @@ def get_compiler(self, source_name):
return compile_html
def render_template(self, template_name, output_name, context):
+ local_context = {}
+ local_context["template_name"] = template_name
+ local_context.update(self.config['GLOBAL_CONTEXT'])
+ local_context.update(context)
data = self.template_system.render_template(
- template_name, None, context, self.GLOBAL_CONTEXT)
+ template_name, None, local_context)
assert output_name.startswith(self.config["OUTPUT_FOLDER"])
url_part = output_name[len(self.config["OUTPUT_FOLDER"]) + 1:]
@@ -66,8 +66,8 @@ def template_deps(self, template_name):
"""Returns filenames which are dependencies for a template."""
raise Exception("Implement Me First")
- def render_template(name, output_name, context, global_context):
- """Renders template to a file using contexts.
+ def render_template(name, output_name, context):
+ """Renders template to a file using context.
This must save the data to output_name *and* return it
so that the caller may do additional processing.
@@ -19,16 +19,11 @@ def set_directories(self, directories):
encoding='utf-8',
))
- def render_template(self, template_name, output_name, context,
- global_context):
+ def render_template(self, template_name, output_name, context):
"""Render the template into output_name using context."""
template = self.lookup.get_template(template_name)
- local_context = {}
- local_context["template_name"] = template_name
- local_context.update(global_context)
- local_context.update(context)
- output = template.render(**local_context)
+ output = template.render(**context)
if output_name is not None:
try:
os.makedirs(os.path.dirname(output_name))
@@ -40,16 +40,11 @@ def set_directories(self, directories):
output_encoding='utf-8',
)
- def render_template(self, template_name, output_name,
- context, global_context):
+ def render_template(self, template_name, output_name, context):
"""Render the template into output_name using context."""
template = self.lookup.get_template(template_name)
- local_context = {}
- local_context["template_name"] = template_name
- local_context.update(global_context)
- local_context.update(context)
- data = template.render_unicode(**local_context)
+ data = template.render_unicode(**context)
if output_name is not None:
try:
os.makedirs(os.path.dirname(output_name))

0 comments on commit c4bf91a

Please sign in to comment.