diff decoupage/formatters.py @ 32:983c13e1b71f

included a links formatter; restructure index template
author k0s <k0scist@gmail.com>
date Mon, 08 Feb 2010 11:10:54 -0500
parents 6b27461955d1
children e384d4569ac3
line wrap: on
line diff
--- a/decoupage/formatters.py	Sun Jan 17 19:49:04 2010 -0500
+++ b/decoupage/formatters.py	Mon Feb 08 11:10:54 2010 -0500
@@ -15,7 +15,6 @@
 
     defaults = {} # default values for attrs to be set on the instance
     
-
     def __init__(self, string):
         args = [ i.strip() for i in string.split(',')]
         for index, arg in enumerate(args):
@@ -37,7 +36,6 @@
 
 class Ignore(object):
     """ignore files of a certain pattern"""
-    
 
     def __init__(self, ignore):
         self.match = ignore.split()
@@ -62,7 +60,6 @@
     
     def __init__(self, pattern):
         self.match = pattern.split()
-        
 
     def __call__(self, request, data):
         _files = []
@@ -108,7 +105,6 @@
 class TitleDescription(FormatterBase):
     """splits a description into a title and a description with a separator"""
     
-
     defaults = { 'separator': ':' }
         
     def __call__(self, request, data):
@@ -121,8 +117,26 @@
                 f['title'] = f['description']
                 f['description'] = None
 
+class Links(FormatterBase):
+    """
+    allow list of links per item:
+    foo.html = description of foo; [PDF]=foo.pdf; [TXT]=foo.txt
+    """
+    
+    defaults = { 'separator': ';' }
+
+    def __call__(self, request, data):
+        for f in data['files']:
+            if f['description'] and self.separator in f['description']:
+                f['description'], links = f['description'].split(self.separator, 1)
+                links = links.split(self.separator)
+                assert min(['=' in link for link in links])
+                links = [ link.split('=', 1) for link in links ]
+                f['links'] = [ { 'text': text, 'link': link }
+                             for text, link in links ]
+
 class CSS(object):
-    """specify CSS"""
+    """specify CSS for the page"""
 
     def __init__(self, arg):
         self.css = arg.split()