diff decoupage/formatters.py @ 88:c382bdd01751

directory indicator
author Jeff Hammel <k0scist@gmail.com>
date Sun, 12 Jan 2014 19:20:16 -0800
parents 3262010f7f79
children 450aff4c97e3
line wrap: on
line diff
--- a/decoupage/formatters.py	Tue Dec 31 02:01:17 2013 -0800
+++ b/decoupage/formatters.py	Sun Jan 12 19:20:16 2014 -0800
@@ -137,6 +137,20 @@
             files.append(file_hash.get(f, None))
         files = [ i for i in files if i is not None ]
 
+class DirectoryIndicator(FormatterBase):
+    """indicate a directory"""
+    indicator = '/'
+    def __init__(self, indicator):
+        self.indicator = indicator.strip() or self.indicator
+    def __call__(self, request, data):
+        for f in data['files']:
+            if f.get('type') == 'directory':
+                title = f.get('title')
+                if title is not None:
+                    f['title'] = '%s %s' % (title, self.indicator)
+                else:
+                    description = f.get('description') or f['name']
+                    f['description'] = '%s %s' % (description, self.indicator)
 
 class FilenameDescription(FormatterBase):
     """
@@ -144,6 +158,7 @@
     the file extension (if any) will be dropped and
     spaces will be substituted for underscores
     """
+
     # TODO : deal with CamelCaseFilenames
 
     separators = ['_', '-'] # space substitute separators
@@ -238,7 +253,6 @@
     fatal = False
     defaults = {'separator': ';'}
 
-
     def __call__(self, request, data):
         for f in data['files']:
             if f['description'] and self.separator in f['description']:
@@ -314,7 +328,8 @@
     def __call__(self, request, data):
         data['include'] = self.include
 
-###
+
+### general purpose functions for formatters
 
 def formatters():
     formatters = {}