Template from the simple themes can now be extended from the other themes

Templates from the `simple` themes can be used in the other themes using
the `extends` keyword:

    {% extends "simple/index.html" %}

This does not affect the behavior of Pelican:, so there is no need to modify
the existing themes.
This commit is contained in:
Skami18 2011-07-19 12:31:18 +02:00
commit 81722f65b8
2 changed files with 6 additions and 3 deletions

1
TODO
View file

@ -1,5 +1,4 @@
* Add a way to support pictures (see how sphinx makes that) * Add a way to support pictures (see how sphinx makes that)
* Find a way to extend the existing templates instead of rewriting all from scratch.
* Make the program support UTF8-encoded files as input (and later: any encoding?) * Make the program support UTF8-encoded files as input (and later: any encoding?)
* Add status support (draft, published, hidden) * Add status support (draft, published, hidden)
* Add a serve + automatic generation behaviour. * Add a serve + automatic generation behaviour.

View file

@ -8,7 +8,7 @@ import os
import math import math
import random import random
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader, PrefixLoader, ChoiceLoader
from jinja2.exceptions import TemplateNotFound from jinja2.exceptions import TemplateNotFound
from pelican.utils import copy, get_relative_path, process_translations, open from pelican.utils import copy, get_relative_path, process_translations, open
@ -32,7 +32,10 @@ class Generator(object):
self._templates = {} self._templates = {}
self._templates_path = os.path.expanduser(os.path.join(self.theme, 'templates')) self._templates_path = os.path.expanduser(os.path.join(self.theme, 'templates'))
self._env = Environment( self._env = Environment(
loader=FileSystemLoader(self._templates_path), loader=ChoiceLoader([
FileSystemLoader(self._templates_path),
PrefixLoader({'simple' : FileSystemLoader(os.path.join(os.path.dirname(os.path.abspath(__file__)), "themes", "simple", "templates"))})
]),
extensions=self.settings.get('JINJA_EXTENSIONS', []), extensions=self.settings.get('JINJA_EXTENSIONS', []),
) )
@ -49,6 +52,7 @@ class Generator(object):
try: try:
self._templates[name] = self._env.get_template(name + '.html') self._templates[name] = self._env.get_template(name + '.html')
except TemplateNotFound: except TemplateNotFound:
debug('self._env.list_templates(): {0}'.format(self._env.list_templates()))
raise Exception('[templates] unable to load %s.html from %s' % ( raise Exception('[templates] unable to load %s.html from %s' % (
name, self._templates_path)) name, self._templates_path))
return self._templates[name] return self._templates[name]