changeset 70:262fb90a54b4

make template loading lenient and other fixes; bump version
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 04 Aug 2012 15:55:52 -0700
parents 9fac58348520
children 94298e137131
files decoupage/formats.py decoupage/formatters.py decoupage/templates/index.html decoupage/web.py setup.py
diffstat 5 files changed, 32 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/decoupage/formats.py	Fri Aug 03 23:48:25 2012 -0700
+++ b/decoupage/formats.py	Sat Aug 04 15:55:52 2012 -0700
@@ -27,7 +27,7 @@
         f['modified'] = f['modified'].ctime()
 
     return 'application/json', json.dumps(data['files'])
-  
+
 class RSS(object):
   """RSS for indices"""
 
@@ -38,7 +38,7 @@
 
   def __call__(self, request, data):
     items = [ PyRSS2Gen.RSSItem(title=item['name'],
-                                description=item['description'] or item['name'],
+                                description=item['description'] or item.get('title') or item['name'],
                                 pubDate=item['modified'],
                                 guid=PyRSS2Gen.Guid(link(request, item['path'])))
               for item in data['files'] ]
--- a/decoupage/formatters.py	Fri Aug 03 23:48:25 2012 -0700
+++ b/decoupage/formatters.py	Sat Aug 04 15:55:52 2012 -0700
@@ -17,6 +17,7 @@
     defaults = {} # default values for attrs to be set on the instance
 
     def __init__(self, string):
+        self._string = string
         args = [ i.strip() for i in string.split(',')]
         for index, arg in enumerate(args):
             if '=' in arg:
@@ -174,6 +175,18 @@
     defaults = { 'separator': ':' }
 
     def __call__(self, request, data):
+
+        # title webpage
+        title = self._string
+        if ':' in title:
+            _title, url = [i.strip() for i in title.split(':', 1)]
+            if '://' in url:
+                # XXX could also use urlparse
+                title = _title
+                data['link'] = url
+        data['title'] = title
+
+        # title files
         for f in data['files']:
             if f['description'] and self.separator in f['description']:
                 title, description = f['description'].split(self.separator, 1)
--- a/decoupage/templates/index.html	Fri Aug 03 23:48:25 2012 -0700
+++ b/decoupage/templates/index.html	Sat Aug 04 15:55:52 2012 -0700
@@ -10,7 +10,7 @@
   </head>
   <body>
     <xi:include py:if="include" href="${include}"/>
-    <h1 py:if="title">${title}</h1>
+    <h1 py:if="title"><a py:if="link" href="${link}">${title}</a><py:if test="not link">${title}</py:if></h1>
     <ul id="listing">
       <li py:for="f in files">
         <a name="${f['path']}"></a>
--- a/decoupage/web.py	Fri Aug 03 23:48:25 2012 -0700
+++ b/decoupage/web.py	Sat Aug 04 15:55:52 2012 -0700
@@ -73,7 +73,7 @@
                 print >> sys.stderr, e
                 continue
             self.formats[_format.name] = _instance
-        
+
         # pluggable index data formatters
         self.formatters = {}
         for formatter in iter_entry_points('decoupage.formatters'):
@@ -86,17 +86,18 @@
                 # record the error, but persist
                 print >> sys.stderr, "Couldn't load formatter: %s" % formatter
                 print >> sts.stderr, e
-                continue 
+                continue
             self.formatters[formatter.name] = _formatter
-        
+
         # template loader
-        self.loader = TemplateLoader(self.template_directories, 
+        self.loader = TemplateLoader(self.template_directories,
+                                     variable_lookup="lenient",
                                      auto_reload=self.auto_reload)
 
-        
+
 
     ### methods dealing with HTTP
-        
+
     def __call__(self, environ, start_response):
 
         # boilerplate: request and filename
@@ -106,7 +107,7 @@
 
         # check to see what we have to serve
         if os.path.exists(path):
-            
+
             if os.path.isdir(path):
                 # serve an index
                 if request.path_info.endswith('/'):
@@ -129,7 +130,7 @@
                     fileserver = FileTypeTransformer(*args, **kwargs)
                 else:
                     fileserver = self.fileserver
-                    
+
                 fileserver = fileserver(path)
                 return fileserver(environ, start_response)
         else:
@@ -142,12 +143,12 @@
         """
         return response to a GET requst
         """
-        
-        # ensure a sane path        
+
+        # ensure a sane path
         path = request.path_info.strip('/')
         directory = os.path.join(self.directory, path)
         path = '/%s' % path
-        
+
         # get the configuraton
         conf = self.conf(path)
 
@@ -159,15 +160,10 @@
         # add a function to get the path to files
         data['filepath'] = lambda *segments: os.path.join(*([directory] + list(segments)))
 
-        # defaults; TODO: make this better
-        # there shouldn't need to be defaults;
-        # iirc, genshi has a mode where these will default to None
-        data['title'] = conf.get('/title')
+        # defaults
         data['directory'] = directory
-        data['include'] = None
         data['css'] = ()
         data['scripts'] = ()
-        data['icon'] = None
 
         # apply formatters
         # XXX this should be cached if not self.auto_reload
--- a/setup.py	Fri Aug 03 23:48:25 2012 -0700
+++ b/setup.py	Sat Aug 04 15:55:52 2012 -0700
@@ -6,7 +6,7 @@
 except IOError:
     description = ''
 
-version = '0.10.3'
+version = '0.11'
 
 setup(name='decoupage',
       version=version,
@@ -22,7 +22,7 @@
       zip_safe=False,
       install_requires=[
           # -*- Extra requirements: -*-
-          'WebOb',	
+          'WebOb',
           'Paste',
           'PasteScript',
           'genshi',
@@ -59,4 +59,4 @@
       up = decoupage.formatters:Up
       """,
       )
-      
+