diff --git a/mediagoblin/app.py b/mediagoblin/app.py index dfc715b9..4870b89c 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -32,6 +32,7 @@ from mediagoblin.init.plugins import setup_plugins from mediagoblin.init import (get_jinja_loader, get_staticdirector, setup_global_and_app_config, setup_workbench, setup_database, setup_storage, setup_beaker_cache) +from mediagoblin.tools.pluginapi import PluginCache _log = logging.getLogger(__name__) @@ -80,7 +81,9 @@ class MediaGoblinApp(object): # Get the template environment self.template_loader = get_jinja_loader( app_config.get('local_templates'), - self.current_theme) + self.current_theme, + PluginCache().get_template_paths() + ) # Set up storage systems self.public_store, self.queue_store = setup_storage() 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 = [] + path_list = [] - # user template overrides - if user_template_path: - loader_choices.append(jinja2.FileSystemLoader(user_template_path)) + # 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'): - loader_choices.append( - jinja2.FileSystemLoader( - current_theme['templates_dir'])) + # 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 the main mediagoblin templates - loader_choices.append( - jinja2.PackageLoader('mediagoblin', 'templates')) + # 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)) - return jinja2.ChoiceLoader(loader_choices) - else: - return jinja2.PackageLoader('mediagoblin', 'templates') + # Add core templates last. + path_list.append(jinja2.PackageLoader('mediagoblin', 'templates')) + + return jinja2.ChoiceLoader(path_list) def get_staticdirector(app_config): diff --git a/mediagoblin/plugins/flatpagesfile/README b/mediagoblin/plugins/flatpagesfile/README new file mode 100644 index 00000000..23a675e1 --- /dev/null +++ b/mediagoblin/plugins/flatpagesfile/README @@ -0,0 +1,50 @@ +======== + README +======== + +This is the flatpages file plugin. It allows you to add pages to your +MediaGoblin instance which are not generated from user content. For +example, this is useful for these pages: + +* About this site +* Terms of service +* Privacy policy +* How to get an account here +* ... + + +How to add pages +================ + +To add pages, you must edit template files on the file system in your +`local_templates` directory. + +The directory structure looks kind of like this:: + + local_templates + |- flatpagesfile + |- flatpage1.html + |- flatpage2.html + |- ... + + +The ``.html`` file contains the content of your page. It's just a +template like all the other templates you have. + +Here's an example:: + + {% extends "flatpagesfile/base.html" %} + {% block mediagoblin_content %} +
+ This site is a MediaGoblin instance set up to host media for + me, my family and my friends. +
+ {% endblock %} + + +.. Note:: + + If you have a bunch of flatpages that kind of look like one + another, take advantage of Jinja2 template extending and create a + base template that the others extend. diff --git a/mediagoblin/plugins/flatpagesfile/__init__.py b/mediagoblin/plugins/flatpagesfile/__init__.py new file mode 100644 index 00000000..69c40a77 --- /dev/null +++ b/mediagoblin/plugins/flatpagesfile/__init__.py @@ -0,0 +1,20 @@ +# GNU MediaGoblin -- federated, autonomous media hosting +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see