# HG changeset patch # User Jeff Hammel # Date 1344062789 25200 # Node ID 4094bee1315439504fc7142402d9cdbf67f1af1f # Parent fdb77c57bd22956bfcb60af31001da79971876d1 quick cleanup diff -r fdb77c57bd22 -r 4094bee13154 decoupage/formatters.py --- a/decoupage/formatters.py Fri Nov 18 22:34:08 2011 -0800 +++ b/decoupage/formatters.py Fri Aug 03 23:46:29 2012 -0700 @@ -9,13 +9,13 @@ class FormatterBase(object): """ - abstract base class if you want to use __init__ methods - in the form of + abstract base class if you want to use __init__ methods + in the form of 'arg1, arg2, arg3, kw1=foo, kw2=bar, kw3=baz """ 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 +37,7 @@ class Ignore(object): """ - ignore files of a glob patterns. + ignore files of a glob patterns. These files will not be linked to in the template. e.g. /ignore = .* *.pdf # don't list dotfiles and PDFs """ @@ -58,11 +58,11 @@ class All(object): """ - only pass files of a certain pattern; + only pass files of a certain pattern; the inverse of ignore calling all with no arguments means only files with descriptions are used """ - + def __init__(self, pattern): self.match = pattern.split() @@ -79,21 +79,22 @@ if f['description'] is not None: _files.append(f) data['files'] = _files - + class Sort(FormatterBase): """ - determines how to sort the files in a directory; + determines how to sort the files in a directory; right now only by case-insensitive alphabetically * reverse : reverse the order of the sorting """ defaults = {'order': 'name'} - + def __init__(self, pattern): FormatterBase.__init__(self, pattern) self.orders = {'name': self.name, 'random': self.random, } - + # TODO: date + def __call__(self, request, data): sort = self.orders.get(request.GET.get('order', self.order), self.name) @@ -121,7 +122,7 @@ self.file = value else: self.order = [i.strip() for i in pattern.split(',')] - + def __call__(self, request, data): if self.file: @@ -162,8 +163,8 @@ class TitleDescription(FormatterBase): """ - splits a description into a title and a description via a separator in - the description. The template will now have an additional variable, + splits a description into a title and a description via a separator in + the description. The template will now have an additional variable, 'title', per file Arguments: * separator: what separator to use (':' by default) @@ -171,7 +172,7 @@ # XXX what about setting the page title? defaults = { 'separator': ':' } - + def __call__(self, request, data): for f in data['files']: if f['description'] and self.separator in f['description']: @@ -191,7 +192,7 @@ allow list of links per item: foo.html = description of foo; [PDF]=foo.pdf; [TXT]=foo.txt """ - + defaults = { 'separator': ';' } def __call__(self, request, data): @@ -213,7 +214,7 @@ def __init__(self, arg): self.up = arg.strip() - + def __call__(self, request, data): path = request.path_info if (path != '/') and self.up: @@ -254,7 +255,7 @@ def __call__(self, request, data): data['include'] = self.include - + def formatters(): formatters = {} for entry_point in iter_entry_points('decoupage.formatters'):