Skip to content

Commit

Permalink
Optional hooks for before and after the rendering loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtigas committed Nov 8, 2011
1 parent 9c9096e commit 4c39079
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion django_medusa/management/commands/staticsitegen.py
@@ -1,14 +1,19 @@
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand
from django_medusa.renderers import StaticSiteRenderer
from django_medusa.utils import get_static_renderers


class Command(BaseCommand):
can_import_settings = True

help = 'Looks for \'renderers.py\' in each INSTALLED_APP, which defines '\
'a class for processing one or more URL paths into static files.'

def handle(self, *args, **options):
StaticSiteRenderer.initialize_output()

for Renderer in get_static_renderers():
r = Renderer()
r.generate()

StaticSiteRenderer.finalize_output()
25 changes: 25 additions & 0 deletions django_medusa/renderers/base.py
Expand Up @@ -23,6 +23,31 @@ class BaseStaticSiteRenderer(object):
through the Django testclient.
"""

@classmethod
def initialize_output(cls):
"""
Things that should be done only once to the output directory BEFORE
rendering occurs (i.e. setting up a config file, creating dirs,
creating an external resource, starting an atomic deploy, etc.)
Management command calls this once before iterating over all
renderer instances.
"""
pass

@classmethod
def finalize_output(cls):
"""
Things that should be done only once to the output directory AFTER
rendering occurs (i.e. writing end of config file, setting up
permissions, calling an external "deploy" method, finalizing an
atomic deploy, etc.)
Management command calls this once after iterating over all
renderer instances.
"""
pass

def get_paths(self):
""" Override this in a subclass to define the URLs to process """
raise NotImplementedError
Expand Down

0 comments on commit 4c39079

Please sign in to comment.