comparison decoupage/formatters.py @ 32:983c13e1b71f

included a links formatter; restructure index template
author k0s <k0scist@gmail.com>
date Mon, 08 Feb 2010 11:10:54 -0500
parents 6b27461955d1
children e384d4569ac3
comparison
equal deleted inserted replaced
26:f306089d6def 32:983c13e1b71f
13 'arg1, arg2, arg3, kw1=foo, kw2=bar, kw3=baz 13 'arg1, arg2, arg3, kw1=foo, kw2=bar, kw3=baz
14 """ 14 """
15 15
16 defaults = {} # default values for attrs to be set on the instance 16 defaults = {} # default values for attrs to be set on the instance
17 17
18
19 def __init__(self, string): 18 def __init__(self, string):
20 args = [ i.strip() for i in string.split(',')] 19 args = [ i.strip() for i in string.split(',')]
21 for index, arg in enumerate(args): 20 for index, arg in enumerate(args):
22 if '=' in arg: 21 if '=' in arg:
23 break 22 break
35 34
36 ### formatters 35 ### formatters
37 36
38 class Ignore(object): 37 class Ignore(object):
39 """ignore files of a certain pattern""" 38 """ignore files of a certain pattern"""
40
41 39
42 def __init__(self, ignore): 40 def __init__(self, ignore):
43 self.match = ignore.split() 41 self.match = ignore.split()
44 42
45 def __call__(self, request, data): 43 def __call__(self, request, data):
60 calling all with no arguments means only files with descriptions are used 58 calling all with no arguments means only files with descriptions are used
61 """ 59 """
62 60
63 def __init__(self, pattern): 61 def __init__(self, pattern):
64 self.match = pattern.split() 62 self.match = pattern.split()
65
66 63
67 def __call__(self, request, data): 64 def __call__(self, request, data):
68 _files = [] 65 _files = []
69 for f in data['files']: 66 for f in data['files']:
70 if self.match: 67 if self.match:
106 103
107 104
108 class TitleDescription(FormatterBase): 105 class TitleDescription(FormatterBase):
109 """splits a description into a title and a description with a separator""" 106 """splits a description into a title and a description with a separator"""
110 107
111
112 defaults = { 'separator': ':' } 108 defaults = { 'separator': ':' }
113 109
114 def __call__(self, request, data): 110 def __call__(self, request, data):
115 for f in data['files']: 111 for f in data['files']:
116 if f['description'] and self.separator in f['description']: 112 if f['description'] and self.separator in f['description']:
119 f['description'] = description 115 f['description'] = description
120 else: 116 else:
121 f['title'] = f['description'] 117 f['title'] = f['description']
122 f['description'] = None 118 f['description'] = None
123 119
120 class Links(FormatterBase):
121 """
122 allow list of links per item:
123 foo.html = description of foo; [PDF]=foo.pdf; [TXT]=foo.txt
124 """
125
126 defaults = { 'separator': ';' }
127
128 def __call__(self, request, data):
129 for f in data['files']:
130 if f['description'] and self.separator in f['description']:
131 f['description'], links = f['description'].split(self.separator, 1)
132 links = links.split(self.separator)
133 assert min(['=' in link for link in links])
134 links = [ link.split('=', 1) for link in links ]
135 f['links'] = [ { 'text': text, 'link': link }
136 for text, link in links ]
137
124 class CSS(object): 138 class CSS(object):
125 """specify CSS""" 139 """specify CSS for the page"""
126 140
127 def __init__(self, arg): 141 def __init__(self, arg):
128 self.css = arg.split() 142 self.css = arg.split()
129 def __call__(self, request, data): 143 def __call__(self, request, data):
130 data['css'] = self.css 144 data['css'] = self.css