diff options
author | Will Kahn-Greene <willg@bluesock.org> | 2012-07-12 19:18:15 -0400 |
---|---|---|
committer | Will Kahn-Greene <willg@bluesock.org> | 2012-07-16 09:26:28 -0400 |
commit | 54b42ee5645ff40aa572f89e60184bf540b50041 (patch) | |
tree | 0db2d68000fcfcbe142ff034ff1dea424ef3cbc0 /mediagoblin/plugins/flatpagesfile/__init__.py | |
parent | 8815541c2628c40190319c70f6227b32e0e35bf2 (diff) | |
download | mediagoblin-54b42ee5645ff40aa572f89e60184bf540b50041.tar.lz mediagoblin-54b42ee5645ff40aa572f89e60184bf540b50041.tar.xz mediagoblin-54b42ee5645ff40aa572f89e60184bf540b50041.zip |
Overhaul flatpages
* move contents of main.py to __init__.py
* update documentation in README
* change the key/value configuration specification
* added a recipe for passing values from the url to the template
* removed some unused code
Diffstat (limited to 'mediagoblin/plugins/flatpagesfile/__init__.py')
-rw-r--r-- | mediagoblin/plugins/flatpagesfile/__init__.py | 65 |
1 files changed, 62 insertions, 3 deletions
diff --git a/mediagoblin/plugins/flatpagesfile/__init__.py b/mediagoblin/plugins/flatpagesfile/__init__.py index 69c40a77..9ed26102 100644 --- a/mediagoblin/plugins/flatpagesfile/__init__.py +++ b/mediagoblin/plugins/flatpagesfile/__init__.py @@ -15,6 +15,65 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. -# This imports the main module which has the FlatPagesPlugin class -# which does all the work. -import mediagoblin.plugins.flatpagesfile.main +import logging +import os + +import jinja2 +from routes.route import Route + +from mediagoblin.tools import pluginapi +from mediagoblin.tools.response import render_to_response + + +PLUGIN_DIR = os.path.dirname(__file__) + + +_log = logging.getLogger(__name__) + + +@jinja2.contextfunction +def print_context(c): + s = [] + for key, val in c.items(): + s.append('%s: %s' % (key, repr(val))) + return '\n'.join(s) + + +def flatpage_handler_builder(template): + """Flatpage view generator + + Given a template, generates the controller function for handling that + route. + + """ + def _flatpage_handler_builder(request): + return render_to_response( + request, 'flatpagesfile/%s' % template, + {'request': request}) + return _flatpage_handler_builder + + +class FlatpagesFilePlugin(pluginapi.Plugin): + """ + This is the flatpages plugin class. See the README for how to use + flatpages. + """ + def setup_plugin(self): + self.config = pluginapi.get_config('mediagoblin.plugins.flatpagesfile') + + _log.info('Setting up flatpagesfile....') + + # Register the template path. + pluginapi.register_template_path(os.path.join(PLUGIN_DIR, 'templates')) + + pages = self.config.items() + + routes = [] + for name, (url, template) in pages: + name = 'flatpagesfile.%s' % name.strip() + controller = flatpage_handler_builder(template) + routes.append( + Route(name, url, controller=controller)) + + pluginapi.register_routes(routes) + _log.info('Done setting up flatpagesfile!') |