Mercurial > hg > decoupage
changeset 45:650e1b62a628
add order formatter (untested)
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 08 Sep 2010 23:12:57 -0700 |
parents | 445af840aa5c |
children | 127843e097b3 |
files | decoupage/formatters.py setup.py |
diffstat | 2 files changed, 25 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/decoupage/formatters.py Mon Sep 06 15:25:44 2010 -0700 +++ b/decoupage/formatters.py Wed Sep 08 23:12:57 2010 -0700 @@ -96,6 +96,30 @@ data['files'] = list(reversed(data['files'])) +class Order(object): + """ + put the files in a particular order + """ + def __init__(self, pattern): + if '=' in pattern: + key, value = pattern.split('=', 1) + assert key == 'file' + self.file = value + else: + self.order = [i.strip() for i in pattern.split(',')] + + def __call__(self, request, data): + + if self.file: + raise NotImplementedError + + files = [] + file_hash = dict([(i['name'], i) for i in data['files']]) + for f in self.order: + files.append(file_hash.get(f, None)) + files = [ i for i in files if i is not None ] + + class FilenameDescription(FormatterBase): """ obtain the description from the filename
--- a/setup.py Mon Sep 06 15:25:44 2010 -0700 +++ b/setup.py Wed Sep 08 23:12:57 2010 -0700 @@ -46,6 +46,7 @@ ignore = decoupage.formatters:Ignore include = decoupage.formatters:Include links = decoupage.formatters:Links + order = decoupage.formatters:Order scripts = decoupage.formatters:JavaScript sort = decoupage.formatters:Sort title = decoupage.formatters:TitleDescription