Mercurial > hg > decoupage
comparison 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 |
comparison
equal
deleted
inserted
replaced
87:ced29a73c561 | 88:c382bdd01751 |
---|---|
135 file_hash = dict([(i['name'], i) for i in data['files']]) | 135 file_hash = dict([(i['name'], i) for i in data['files']]) |
136 for f in self.order: | 136 for f in self.order: |
137 files.append(file_hash.get(f, None)) | 137 files.append(file_hash.get(f, None)) |
138 files = [ i for i in files if i is not None ] | 138 files = [ i for i in files if i is not None ] |
139 | 139 |
140 class DirectoryIndicator(FormatterBase): | |
141 """indicate a directory""" | |
142 indicator = '/' | |
143 def __init__(self, indicator): | |
144 self.indicator = indicator.strip() or self.indicator | |
145 def __call__(self, request, data): | |
146 for f in data['files']: | |
147 if f.get('type') == 'directory': | |
148 title = f.get('title') | |
149 if title is not None: | |
150 f['title'] = '%s %s' % (title, self.indicator) | |
151 else: | |
152 description = f.get('description') or f['name'] | |
153 f['description'] = '%s %s' % (description, self.indicator) | |
140 | 154 |
141 class FilenameDescription(FormatterBase): | 155 class FilenameDescription(FormatterBase): |
142 """ | 156 """ |
143 obtain the description from the filename | 157 obtain the description from the filename |
144 the file extension (if any) will be dropped and | 158 the file extension (if any) will be dropped and |
145 spaces will be substituted for underscores | 159 spaces will be substituted for underscores |
146 """ | 160 """ |
161 | |
147 # TODO : deal with CamelCaseFilenames | 162 # TODO : deal with CamelCaseFilenames |
148 | 163 |
149 separators = ['_', '-'] # space substitute separators | 164 separators = ['_', '-'] # space substitute separators |
150 lesser_words = [ 'or', 'a', 'the', 'on', 'of' ] # unimportant words | 165 lesser_words = [ 'or', 'a', 'the', 'on', 'of' ] # unimportant words |
151 | 166 |
236 """ | 251 """ |
237 | 252 |
238 fatal = False | 253 fatal = False |
239 defaults = {'separator': ';'} | 254 defaults = {'separator': ';'} |
240 | 255 |
241 | |
242 def __call__(self, request, data): | 256 def __call__(self, request, data): |
243 for f in data['files']: | 257 for f in data['files']: |
244 if f['description'] and self.separator in f['description']: | 258 if f['description'] and self.separator in f['description']: |
245 description, links = f['description'].split(self.separator, 1) | 259 description, links = f['description'].split(self.separator, 1) |
246 links = links.rstrip().split(self.separator) | 260 links = links.rstrip().split(self.separator) |
312 def __init__(self, arg): | 326 def __init__(self, arg): |
313 self.include = arg | 327 self.include = arg |
314 def __call__(self, request, data): | 328 def __call__(self, request, data): |
315 data['include'] = self.include | 329 data['include'] = self.include |
316 | 330 |
317 ### | 331 |
332 ### general purpose functions for formatters | |
318 | 333 |
319 def formatters(): | 334 def formatters(): |
320 formatters = {} | 335 formatters = {} |
321 for entry_point in iter_entry_points('decoupage.formatters'): | 336 for entry_point in iter_entry_points('decoupage.formatters'): |
322 try: | 337 try: |