Mercurial > hatta
changeset 2459:614423797e10
implemented custom templates support (1st draft)
| author | Vlad Glagolev <scm@vaygr.net> |
|---|---|
| date | Tue, 23 Dec 2014 13:44:34 +0300 |
| parents | 9c7f693e11d5 |
| children | 490966f6a530 |
| files | hatta/config.py hatta/wiki.py |
| diffstat | 2 files changed, 10 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/hatta/config.py Tue Dec 23 09:41:15 2014 +0100 +++ b/hatta/config.py Tue Dec 23 13:44:34 2014 +0300 @@ -24,6 +24,8 @@ help='Use the repository at DIR', metavar='DIR') _add('-t', '--cache-dir', dest='cache_path', help='Store cache in DIR', metavar='DIR') +_add('-T', '--template-dir', dest='template_path', + help='Use templates in DIR', metavar='DIR') _add('-i', '--interface', dest='interface', help='Listen on interface INT', metavar='INT') _add('-p', '--port', dest='port', type='int',
--- a/hatta/wiki.py Tue Dec 23 09:41:15 2014 +0100 +++ b/hatta/wiki.py Tue Dec 23 13:44:34 2014 +0300 @@ -52,10 +52,13 @@ return translation -def init_template(translation): +def init_template(translation, template_path): template_env = jinja2.Environment( extensions=['jinja2.ext.i18n'], - loader=jinja2.PackageLoader('hatta', 'templates'), + loader=jinja2.ChoiceLoader([ + jinja2.FileSystemLoader(template_path), + jinja2.PackageLoader('hatta', 'templates') + ]), ) template_env.autoescape = True template_env.install_gettext_translations(translation, True) @@ -82,7 +85,9 @@ self.language = config.get('language') translation = init_gettext(self.language) self.gettext = translation.ugettext - self.template_env = init_template(translation) + self.template_path = os.path.abspath(config.get('template_path', + 'templates')) + self.template_env = init_template(translation, self.template_path) self.path = os.path.abspath(config.get('pages_path', 'docs')) self.repo_path = config.get('repo_path') self.page_charset = config.get('page_charset', 'utf-8')
