changeset 10:a328cc9d2c74

* fix formatters * allow /inherit keyword to specify configuration * bump version
author k0s <k0scist@gmail.com>
date Fri, 25 Dec 2009 01:03:06 -0500
parents ec2d0d850b83
children fad6fa9037a5
files decoupage/formatters.py decoupage/web.py setup.py
diffstat 3 files changed, 25 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/decoupage/formatters.py	Thu Dec 24 23:33:37 2009 -0500
+++ b/decoupage/formatters.py	Fri Dec 25 01:03:06 2009 -0500
@@ -13,21 +13,24 @@
     'arg1, arg2, arg3, kw1=foo, kw2=bar, kw3=baz
     """
 
-    defaults = {}
+    defaults = {} # default values for attrs to be set on the instance
+    
 
     def __init__(self, string):
-        args = [ i.strip() for i in string.split(',') ]
+        args = [ i.strip() for i in string.split(',')]
         for index, arg in enumerate(args):
             if '=' in arg:
                 break
         else:
             self.args = args
+            for key, default in self.defaults.items():
+                setattr(self, key, default)
             return
         self.args = args[:index]
         self.kw = dict([i.split('=', 1) for i in args[index:]])
-        for key, default in defaults.items():
-            if key not in self.kw:
-                self.kw[key] = default
+        for key, default in self.defaults.items():
+            value = self.kw.pop(key, default)
+            setattr(self, key, value)
 
 
 ### formatters
@@ -104,7 +107,7 @@
             else:
                 f['title'] = f['description']
                 f['description'] = None
-                
+
         
 def formatters():
     formatters = {}
--- a/decoupage/web.py	Thu Dec 24 23:33:37 2009 -0500
+++ b/decoupage/web.py	Fri Dec 25 01:03:06 2009 -0500
@@ -4,6 +4,8 @@
 
 import os
 
+from formatters import formatters
+
 from genshi.builder import Markup
 from genshi.template import TemplateLoader
 from martini.config import ConfigMunger
@@ -99,7 +101,6 @@
             files.append({'path' : '%s/%s' % (path.rstrip('/'), i),
                           'name': i,
                           'description': conf.get(i.lower(), None)})
-
         # build data dictionary
         data = {'path': path, 'files': files, 'request': request}
 
@@ -119,7 +120,8 @@
         for name in formatters:
             formatter = self.formatters[name](conf.get('/%s' % name, ''))
             formatter(request, data)
-        
+
+
         # render the template
         template = conf.get('/template')
         if template is None:
@@ -137,8 +139,10 @@
 
     ### internal methods
 
-    def conf(self, path):
+    def conf(self, path, cascade=None):
         """returns configuration dictionary appropriate to a path"""
+        if cascade is None:
+            cascase = self.cascade
 
         directory = os.path.join(self.directory, path.strip('/'))
         if path.strip('/'):
@@ -163,9 +167,14 @@
         if not conf and self.configuration and os.path.exists(self.configuration):
             conf = ConfigMunger(self.configuration).dict().get('/%s' % path.rstrip('/'), {})
 
-        # cascade configuration
-        if self.cascade and path_tuple:
-            parent_configuration = self.conf('/%s' % '/'.join(path_tuple[:-1]))
+        # inherit and cascade configuration
+        inherit_directory = None
+        if '/inherit' in conf:
+            inherit_directory = conf['/inherit']
+        elif self.cascade and path_tuple:
+            inherit_directory = '/%s' % '/'.join(path_tuple[:-1])
+        if inherit_directory:
+            parent_configuration = self.conf(inherit_directory)
             for key, value in parent_configuration.items():
                 if key.startswith('/') and key not in conf:
                     conf[key] = value
--- a/setup.py	Thu Dec 24 23:33:37 2009 -0500
+++ b/setup.py	Fri Dec 25 01:03:06 2009 -0500
@@ -6,7 +6,7 @@
 except IOError:
     description = ''
 
-version = '0.3.2'
+version = '0.3.3'
 
 setup(name='decoupage',
       version=version,