aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/init
diff options
context:
space:
mode:
authorWill Kahn-Greene <willg@bluesock.org>2012-06-10 11:50:14 -0400
committerWill Kahn-Greene <willg@bluesock.org>2012-07-16 09:26:28 -0400
commit8545dd50f0cd588d505c217d367450198199a2b0 (patch)
tree3ba262185cbbf7366f1ab9673efd49d1c6856fe0 /mediagoblin/init
parent62157a898f60fab7c82eb76b2969354f9f02390d (diff)
downloadmediagoblin-8545dd50f0cd588d505c217d367450198199a2b0.tar.lz
mediagoblin-8545dd50f0cd588d505c217d367450198199a2b0.tar.xz
mediagoblin-8545dd50f0cd588d505c217d367450198199a2b0.zip
Flatpages first pass
This fixes the template loader so that it can load plugin templates. This adds code for registering template paths so that plugins can add their own templates. This adds the base code for the flatpagesfile plugin. It doesn't serve pages, yet, but it's pretty close.
Diffstat (limited to 'mediagoblin/init')
-rw-r--r--mediagoblin/init/__init__.py45
1 files changed, 24 insertions, 21 deletions
diff --git a/mediagoblin/init/__init__.py b/mediagoblin/init/__init__.py
index f7bef421..9b0025c9 100644
--- a/mediagoblin/init/__init__.py
+++ b/mediagoblin/init/__init__.py
@@ -71,7 +71,8 @@ def setup_database():
return connection, db
-def get_jinja_loader(user_template_path=None, current_theme=None):
+def get_jinja_loader(user_template_path=None, current_theme=None,
+ plugin_template_paths=None):
"""
Set up the Jinja template loaders, possibly allowing for user
overridden templates.
@@ -79,26 +80,28 @@ def get_jinja_loader(user_template_path=None, current_theme=None):
(In the future we may have another system for providing theming;
for now this is good enough.)
"""
- if user_template_path or current_theme:
- loader_choices = []
-
- # user template overrides
- if user_template_path:
- loader_choices.append(jinja2.FileSystemLoader(user_template_path))
-
- # Any theme directories in the registry
- if current_theme and current_theme.get('templates_dir'):
- loader_choices.append(
- jinja2.FileSystemLoader(
- current_theme['templates_dir']))
-
- # Add the main mediagoblin templates
- loader_choices.append(
- jinja2.PackageLoader('mediagoblin', 'templates'))
-
- return jinja2.ChoiceLoader(loader_choices)
- else:
- return jinja2.PackageLoader('mediagoblin', 'templates')
+ path_list = []
+
+ # Add user path first--this takes precedence over everything.
+ if user_template_path is not None:
+ path_list.append(jinja2.FileSystemLoader(user_template_path))
+
+ # Any theme directories in the registry
+ if current_theme and current_theme.get('templates_dir'):
+ path_list.append(
+ jinja2.FileSystemLoader(
+ current_theme['templates_dir']))
+
+ # Add plugin template paths next--takes precedence over
+ # core templates.
+ if plugin_template_paths is not None:
+ path_list.extend((jinja2.FileSystemLoader(path)
+ for path in plugin_template_paths))
+
+ # Add core templates last.
+ path_list.append(jinja2.PackageLoader('mediagoblin', 'templates'))
+
+ return jinja2.ChoiceLoader(path_list)
def get_staticdirector(app_config):