comparison decoupage/formatters.py @ 34:527ccb76d043

merged some stuff
author k0s <k0scist@gmail.com>
date Mon, 08 Feb 2010 11:44:20 -0500
parents e384d4569ac3 fc1c479296c3
children 20e3d138dc98
comparison
equal deleted inserted replaced
33:e384d4569ac3 34:527ccb76d043
33 33
34 34
35 ### formatters 35 ### formatters
36 36
37 class Ignore(object): 37 class Ignore(object):
38 """ignore files of a certain pattern""" 38 """
39 ignore files of a glob patterns.
40 These files will not be linked to in the template.
41 e.g. /ignore = .* *.pdf # don't list dotfiles and PDFs
42 """
39 43
40 def __init__(self, ignore): 44 def __init__(self, ignore):
41 self.match = ignore.split() 45 self.match = ignore.split()
42 46
43 def __call__(self, request, data): 47 def __call__(self, request, data):
74 if f['description'] is not None: 78 if f['description'] is not None:
75 _files.append(f) 79 _files.append(f)
76 data['files'] = _files 80 data['files'] = _files
77 81
78 class Sort(object): 82 class Sort(object):
79 """ determines how to sort the files in a directory """ 83 """
84 determines how to sort the files in a directory;
85 right now only by case-insensitive alphabetically
86 * reverse : reverse the order of the sorting
87 """
80 def __init__(self, pattern): 88 def __init__(self, pattern):
81 self.args = [i.strip() for i in pattern.split(',')] 89 self.args = [i.strip() for i in pattern.split(',')]
82 90
83 def __call__(self, request, data): 91 def __call__(self, request, data):
84 92
87 if 'reverse' in self.args: 95 if 'reverse' in self.args:
88 data['files'] = list(reversed(data['files'])) 96 data['files'] = list(reversed(data['files']))
89 97
90 98
91 class FilenameDescription(FormatterBase): 99 class FilenameDescription(FormatterBase):
92 """substitute the description for the filename""" 100 """
101 obtain the description from the filename
102 the file extension (if any) will be dropped and
103 spaces will be substituted for underscores
104 """
105 # TODO : deal with CamelCaseFilenames
93 106
94 def __call__(self, request, data): 107 def __call__(self, request, data):
95 for f in data['files']: 108 for f in data['files']:
96 if f['description'] is None: 109 if f['description'] is None:
97 description = f['name'] 110 description = f['name']
98 description = description.rsplit('.', 1)[0] 111 if '.' in description:
112 description = description.rsplit('.', 1)[0]
99 decription = description.strip('_') 113 decription = description.strip('_')
100 if '_' in description: 114 if '_' in description:
101 description = ' '.join([i.title() for i in description.split('_')]) 115 description = ' '.join([i.title() for i in description.split('_')])
102 f['description'] = description 116 f['description'] = description
103 117
104 118
105 class TitleDescription(FormatterBase): 119 class TitleDescription(FormatterBase):
106 """splits a description into a title and a description with a separator""" 120 """
107 121 splits a description into a title and a description via a separator in
122 the description. The template will now have an additional variable,
123 'title', per file
124 Arguments:
125 * separator: what separator to use (':' by default)
126 """
127 # XXX what about setting the page title?
128
108 defaults = { 'separator': ':' } 129 defaults = { 'separator': ':' }
109 130
110 def __call__(self, request, data): 131 def __call__(self, request, data):
111 for f in data['files']: 132 for f in data['files']:
112 if f['description'] and self.separator in f['description']: 133 if f['description'] and self.separator in f['description']:
134 links = [ link.split('=', 1) for link in links ] 155 links = [ link.split('=', 1) for link in links ]
135 f['links'] = [ { 'text': text, 'link': link } 156 f['links'] = [ { 'text': text, 'link': link }
136 for text, link in links ] 157 for text, link in links ]
137 158
138 class CSS(object): 159 class CSS(object):
139 """specify CSS for the page""" 160 """specify CSS used (whitespace separated list)"""
140 161
141 def __init__(self, arg): 162 def __init__(self, arg):
142 self.css = arg.split() 163 self.css = arg.split()
143 def __call__(self, request, data): 164 def __call__(self, request, data):
144 data['css'] = self.css 165 data['css'] = self.css