aboutsummaryrefslogtreecommitdiffstats
path: root/nikola/plugins/template
diff options
context:
space:
mode:
authorLibravatarAgustin Henze <tin@sluc.org.ar>2015-08-26 07:57:23 -0300
committerLibravatarAgustin Henze <tin@sluc.org.ar>2015-08-26 07:57:23 -0300
commit70ceb871117ca811d63cb02671dc0fefc2700883 (patch)
tree846133ea39797d2cd1101cff2ac0818167353490 /nikola/plugins/template
parent8559119e2f45b7f6508282962c0430423bfab051 (diff)
parent787b97a4cb24330b36f11297c6d3a7a473a907d0 (diff)
Merge tag 'upstream/7.6.4'
Upstream version 7.6.4
Diffstat (limited to 'nikola/plugins/template')
-rw-r--r--nikola/plugins/template/__init__.py2
-rw-r--r--nikola/plugins/template/jinja.plugin16
-rw-r--r--nikola/plugins/template/jinja.py19
-rw-r--r--nikola/plugins/template/mako.plugin16
-rw-r--r--nikola/plugins/template/mako.py28
5 files changed, 47 insertions, 34 deletions
diff --git a/nikola/plugins/template/__init__.py b/nikola/plugins/template/__init__.py
index a1d17a6..d416ad7 100644
--- a/nikola/plugins/template/__init__.py
+++ b/nikola/plugins/template/__init__.py
@@ -23,3 +23,5 @@
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+"""Default template engines for Nikola."""
diff --git a/nikola/plugins/template/jinja.plugin b/nikola/plugins/template/jinja.plugin
index 0bdcb94..cfe9fa8 100644
--- a/nikola/plugins/template/jinja.plugin
+++ b/nikola/plugins/template/jinja.plugin
@@ -1,9 +1,13 @@
[Core]
-Name = jinja
-Module = jinja
+name = jinja
+module = jinja
[Documentation]
-Author = Roberto Alsina
-Version = 1.0
-Website = http://getnikola.com
-Description = Support for Jinja2 templates.
+author = Roberto Alsina
+version = 1.0
+website = http://getnikola.com
+description = Support for Jinja2 templates.
+
+[Nikola]
+plugincategory = Template
+
diff --git a/nikola/plugins/template/jinja.py b/nikola/plugins/template/jinja.py
index 82e8397..b02d75c 100644
--- a/nikola/plugins/template/jinja.py
+++ b/nikola/plugins/template/jinja.py
@@ -24,8 +24,10 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-"""Jinja template handlers"""
+"""Jinja template handler."""
+
+from __future__ import unicode_literals
import os
import json
from collections import deque
@@ -40,14 +42,15 @@ from nikola.utils import makedirs, req_missing
class JinjaTemplates(TemplateSystem):
- """Wrapper for Jinja2 templates."""
+
+ """Support for Jinja2 templates."""
name = "jinja"
lookup = None
dependency_cache = {}
def __init__(self):
- """ initialize Jinja2 wrapper with extended set of filters"""
+ """Initialize Jinja2 environment with extended set of filters."""
if jinja2 is None:
return
self.lookup = jinja2.Environment()
@@ -59,26 +62,25 @@ class JinjaTemplates(TemplateSystem):
self.lookup.globals['tuple'] = tuple
def set_directories(self, directories, cache_folder):
- """Create a template lookup."""
+ """Create a new template lookup with set directories."""
if jinja2 is None:
req_missing(['jinja2'], 'use this theme')
self.directories = directories
self.create_lookup()
def inject_directory(self, directory):
- """if it's not there, add the directory to the lookup with lowest priority, and
- recreate the lookup."""
+ """Add a directory to the lookup and recreate it if it's not there yet."""
if directory not in self.directories:
self.directories.append(directory)
self.create_lookup()
def create_lookup(self):
- """Create a template lookup object."""
+ """Create a template lookup."""
self.lookup.loader = jinja2.FileSystemLoader(self.directories,
encoding='utf-8')
def set_site(self, site):
- """Sets the site."""
+ """Set the Nikola site."""
self.site = site
self.lookup.filters.update(self.site.config['TEMPLATE_FILTERS'])
@@ -99,6 +101,7 @@ class JinjaTemplates(TemplateSystem):
return self.lookup.from_string(template).render(**context)
def template_deps(self, template_name):
+ """Generate list of dependencies for a template."""
# Cache the lists of dependencies for each template name.
if self.dependency_cache.get(template_name) is None:
# Use a breadth-first search to find all templates this one
diff --git a/nikola/plugins/template/mako.plugin b/nikola/plugins/template/mako.plugin
index 2fe6d98..d256faf 100644
--- a/nikola/plugins/template/mako.plugin
+++ b/nikola/plugins/template/mako.plugin
@@ -1,9 +1,13 @@
[Core]
-Name = mako
-Module = mako
+name = mako
+module = mako
[Documentation]
-Author = Roberto Alsina
-Version = 1.0
-Website = http://getnikola.com
-Description = Support for Mako templates.
+author = Roberto Alsina
+version = 1.0
+website = http://getnikola.com
+description = Support for Mako templates.
+
+[Nikola]
+plugincategory = Template
+
diff --git a/nikola/plugins/template/mako.py b/nikola/plugins/template/mako.py
index e5545f6..aed6596 100644
--- a/nikola/plugins/template/mako.py
+++ b/nikola/plugins/template/mako.py
@@ -24,14 +24,15 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-"""Mako template handlers"""
+"""Mako template handler."""
+
from __future__ import unicode_literals, print_function, absolute_import
import os
import shutil
import sys
import tempfile
-from mako import util, lexer
+from mako import util, lexer, parsetree
from mako.lookup import TemplateLookup
from mako.template import Template
from markupsafe import Markup # It's ok, Mako requires it
@@ -43,7 +44,8 @@ LOGGER = get_logger('mako', STDERR_HANDLER)
class MakoTemplates(TemplateSystem):
- """Wrapper for Mako templates."""
+
+ """Support for Mako templates."""
name = "mako"
@@ -54,6 +56,7 @@ class MakoTemplates(TemplateSystem):
cache_dir = None
def get_deps(self, filename):
+ """Get dependencies for a template (internal function)."""
text = util.read_file(filename)
lex = lexer.Lexer(text=text, filename=filename)
lex.parse()
@@ -61,13 +64,12 @@ class MakoTemplates(TemplateSystem):
deps = []
for n in lex.template.nodes:
keyword = getattr(n, 'keyword', None)
- if keyword in ["inherit", "namespace"]:
+ if keyword in ["inherit", "namespace"] or isinstance(n, parsetree.IncludeTag):
deps.append(n.attributes['file'])
- # TODO: include tags are not handled
return deps
def set_directories(self, directories, cache_folder):
- """Set directories and create a template lookup."""
+ """Create a new template lookup with set directories."""
cache_dir = os.path.join(cache_folder, '.mako.tmp')
# Workaround for a Mako bug, Issue #825
if sys.version_info[0] == 2:
@@ -83,21 +85,20 @@ class MakoTemplates(TemplateSystem):
self.create_lookup()
def inject_directory(self, directory):
- """if it's not there, add the directory to the lookup with lowest priority, and
- recreate the lookup."""
+ """Add a directory to the lookup and recreate it if it's not there yet."""
if directory not in self.directories:
self.directories.append(directory)
self.create_lookup()
def create_lookup(self):
- """Create a template lookup object."""
+ """Create a template lookup."""
self.lookup = TemplateLookup(
directories=self.directories,
module_directory=self.cache_dir,
output_encoding='utf-8')
def set_site(self, site):
- """Sets the site."""
+ """Set the Nikola site."""
self.site = site
self.filters.update(self.site.config['TEMPLATE_FILTERS'])
@@ -113,14 +114,12 @@ class MakoTemplates(TemplateSystem):
return data
def render_template_to_string(self, template, context):
- """ Render template to a string using context. """
-
+ """Render template to a string using context."""
context.update(self.filters)
-
return Template(template).render(**context)
def template_deps(self, template_name):
- """Returns filenames which are dependencies for a template."""
+ """Generate list of dependencies for a template."""
# We can cache here because dependencies should
# not change between runs
if self.cache.get(template_name, None) is None:
@@ -134,4 +133,5 @@ class MakoTemplates(TemplateSystem):
def striphtml(text):
+ """Strip HTML tags from text."""
return Markup(text).striptags()