annotate decoupage/formatters.py @ 28:fc1c479296c3

more docmentation updates
author k0s <k0scist@gmail.com>
date Tue, 19 Jan 2010 09:15:35 -0500
parents 9e86c5cb111a
children 527ccb76d043
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
1 #!/usr/bin/env python
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
2
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
3 import sys
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
4 from fnmatch import fnmatch
9
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
5 from pkg_resources import iter_entry_points
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
6
1
93ab6d1968bd adding comments about what this file contains
jhammel@jhammel-laptop
parents: 0
diff changeset
7 ### abstract base classes for formatters
93ab6d1968bd adding comments about what this file contains
jhammel@jhammel-laptop
parents: 0
diff changeset
8
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
9 class FormatterBase(object):
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
10 """
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
11 abstract base class if you want to use __init__ methods
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
12 in the form of
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
13 'arg1, arg2, arg3, kw1=foo, kw2=bar, kw3=baz
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
14 """
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
15
10
a328cc9d2c74 * fix formatters
k0s <k0scist@gmail.com>
parents: 9
diff changeset
16 defaults = {} # default values for attrs to be set on the instance
a328cc9d2c74 * fix formatters
k0s <k0scist@gmail.com>
parents: 9
diff changeset
17
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
18
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
19 def __init__(self, string):
10
a328cc9d2c74 * fix formatters
k0s <k0scist@gmail.com>
parents: 9
diff changeset
20 args = [ i.strip() for i in string.split(',')]
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
21 for index, arg in enumerate(args):
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
22 if '=' in arg:
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
23 break
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
24 else:
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
25 self.args = args
10
a328cc9d2c74 * fix formatters
k0s <k0scist@gmail.com>
parents: 9
diff changeset
26 for key, default in self.defaults.items():
a328cc9d2c74 * fix formatters
k0s <k0scist@gmail.com>
parents: 9
diff changeset
27 setattr(self, key, default)
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
28 return
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
29 self.args = args[:index]
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
30 self.kw = dict([i.split('=', 1) for i in args[index:]])
10
a328cc9d2c74 * fix formatters
k0s <k0scist@gmail.com>
parents: 9
diff changeset
31 for key, default in self.defaults.items():
a328cc9d2c74 * fix formatters
k0s <k0scist@gmail.com>
parents: 9
diff changeset
32 value = self.kw.pop(key, default)
a328cc9d2c74 * fix formatters
k0s <k0scist@gmail.com>
parents: 9
diff changeset
33 setattr(self, key, value)
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
34
1
93ab6d1968bd adding comments about what this file contains
jhammel@jhammel-laptop
parents: 0
diff changeset
35
93ab6d1968bd adding comments about what this file contains
jhammel@jhammel-laptop
parents: 0
diff changeset
36 ### formatters
93ab6d1968bd adding comments about what this file contains
jhammel@jhammel-laptop
parents: 0
diff changeset
37
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
38 class Ignore(object):
27
9e86c5cb111a minor documentation updates
k0s <k0scist@gmail.com>
parents: 24
diff changeset
39 """
28
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
40 ignore files of a glob patterns.
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
41 These files will not be linked to in the template.
27
9e86c5cb111a minor documentation updates
k0s <k0scist@gmail.com>
parents: 24
diff changeset
42 e.g. /ignore = .* *.pdf # don't list dotfiles and PDFs
9e86c5cb111a minor documentation updates
k0s <k0scist@gmail.com>
parents: 24
diff changeset
43 """
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
44
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
45
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
46 def __init__(self, ignore):
12
9f91acf9874c * split on space in formatters to be consist with everything else
k0s <k0scist@gmail.com>
parents: 10
diff changeset
47 self.match = ignore.split()
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
48
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
49 def __call__(self, request, data):
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
50 _files = []
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
51 for f in data['files']:
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
52 for pattern in self.match:
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
53 if fnmatch(f['name'], pattern):
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
54 break
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
55 else:
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
56 _files.append(f)
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
57 data['files'] = _files
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
58
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
59
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
60 class All(object):
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
61 """
9
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
62 only pass files of a certain pattern;
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
63 the inverse of ignore
12
9f91acf9874c * split on space in formatters to be consist with everything else
k0s <k0scist@gmail.com>
parents: 10
diff changeset
64 calling all with no arguments means only files with descriptions are used
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
65 """
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
66
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
67 def __init__(self, pattern):
12
9f91acf9874c * split on space in formatters to be consist with everything else
k0s <k0scist@gmail.com>
parents: 10
diff changeset
68 self.match = pattern.split()
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
69
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
70
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
71 def __call__(self, request, data):
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
72 _files = []
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
73 for f in data['files']:
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
74 if self.match:
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
75 for pattern in self.match:
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
76 if fnmatch(f['name'], pattern):
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
77 _files.append(f)
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
78 break
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
79 else:
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
80 # use only files where the description is not None
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
81 if f['description'] is not None:
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
82 _files.append(f)
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
83 data['files'] = _files
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
84
22
a8d36caa8f09 add formatter
egj@socialplanning.org
parents: 17
diff changeset
85 class Sort(object):
27
9e86c5cb111a minor documentation updates
k0s <k0scist@gmail.com>
parents: 24
diff changeset
86 """
9e86c5cb111a minor documentation updates
k0s <k0scist@gmail.com>
parents: 24
diff changeset
87 determines how to sort the files in a directory;
9e86c5cb111a minor documentation updates
k0s <k0scist@gmail.com>
parents: 24
diff changeset
88 right now only by case-insensitive alphabetically
28
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
89 * reverse : reverse the order of the sorting
27
9e86c5cb111a minor documentation updates
k0s <k0scist@gmail.com>
parents: 24
diff changeset
90 """
22
a8d36caa8f09 add formatter
egj@socialplanning.org
parents: 17
diff changeset
91 def __init__(self, pattern):
a8d36caa8f09 add formatter
egj@socialplanning.org
parents: 17
diff changeset
92 self.args = [i.strip() for i in pattern.split(',')]
a8d36caa8f09 add formatter
egj@socialplanning.org
parents: 17
diff changeset
93
a8d36caa8f09 add formatter
egj@socialplanning.org
parents: 17
diff changeset
94 def __call__(self, request, data):
a8d36caa8f09 add formatter
egj@socialplanning.org
parents: 17
diff changeset
95
a8d36caa8f09 add formatter
egj@socialplanning.org
parents: 17
diff changeset
96 data['files'] = sorted(data['files'], key=lambda x: x['name'].lower())
a8d36caa8f09 add formatter
egj@socialplanning.org
parents: 17
diff changeset
97
a8d36caa8f09 add formatter
egj@socialplanning.org
parents: 17
diff changeset
98 if 'reverse' in self.args:
23
d1b1019d9254 unfold the list out of the reverseiterator which otherwise gets consumed and funky
egj@socialplanning.org
parents: 22
diff changeset
99 data['files'] = list(reversed(data['files']))
22
a8d36caa8f09 add formatter
egj@socialplanning.org
parents: 17
diff changeset
100
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
101
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
102 class FilenameDescription(FormatterBase):
28
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
103 """
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
104 obtain the description from the filename
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
105 the file extension (if any) will be dropped and
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
106 spaces will be substituted for underscores
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
107 """
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
108 # TODO : deal with CamelCaseFilenames
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
109
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
110 def __call__(self, request, data):
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
111 for f in data['files']:
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
112 if f['description'] is None:
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
113 description = f['name']
28
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
114 if '.' in description:
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
115 description = description.rsplit('.', 1)[0]
17
eab191e0b9b3 meaningful descriptions from filenames
k0s <k0scist@gmail.com>
parents: 16
diff changeset
116 decription = description.strip('_')
eab191e0b9b3 meaningful descriptions from filenames
k0s <k0scist@gmail.com>
parents: 16
diff changeset
117 if '_' in description:
eab191e0b9b3 meaningful descriptions from filenames
k0s <k0scist@gmail.com>
parents: 16
diff changeset
118 description = ' '.join([i.title() for i in description.split('_')])
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
119 f['description'] = description
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
120
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
121
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
122 class TitleDescription(FormatterBase):
28
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
123 """
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
124 splits a description into a title and a description via a separator in
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
125 the description. The template will now have an additional variable,
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
126 'title', per file
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
127 Arguments:
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
128 * separator: what separator to use (':' by default)
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
129 """
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
130 # XXX what about setting the page title?
9
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
131
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
132 defaults = { 'separator': ':' }
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
133
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
134 def __call__(self, request, data):
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
135 for f in data['files']:
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
136 if f['description'] and self.separator in f['description']:
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
137 title, description = f['description'].split(self.separator, 1)
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
138 f['title'] = title
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
139 f['description'] = description
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
140 else:
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
141 f['title'] = f['description']
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
142 f['description'] = None
10
a328cc9d2c74 * fix formatters
k0s <k0scist@gmail.com>
parents: 9
diff changeset
143
16
985b3a7e0e88 add formatters to include css and genshi templates
k0s <k0scist@gmail.com>
parents: 12
diff changeset
144 class CSS(object):
28
fc1c479296c3 more docmentation updates
k0s <k0scist@gmail.com>
parents: 27
diff changeset
145 """specify CSS used (whitespace separated list)"""
16
985b3a7e0e88 add formatters to include css and genshi templates
k0s <k0scist@gmail.com>
parents: 12
diff changeset
146
985b3a7e0e88 add formatters to include css and genshi templates
k0s <k0scist@gmail.com>
parents: 12
diff changeset
147 def __init__(self, arg):
985b3a7e0e88 add formatters to include css and genshi templates
k0s <k0scist@gmail.com>
parents: 12
diff changeset
148 self.css = arg.split()
985b3a7e0e88 add formatters to include css and genshi templates
k0s <k0scist@gmail.com>
parents: 12
diff changeset
149 def __call__(self, request, data):
24
6b27461955d1 correct variable name
k0s <k0scist@gmail.com>
parents: 23
diff changeset
150 data['css'] = self.css
16
985b3a7e0e88 add formatters to include css and genshi templates
k0s <k0scist@gmail.com>
parents: 12
diff changeset
151
985b3a7e0e88 add formatters to include css and genshi templates
k0s <k0scist@gmail.com>
parents: 12
diff changeset
152 class Include(object):
985b3a7e0e88 add formatters to include css and genshi templates
k0s <k0scist@gmail.com>
parents: 12
diff changeset
153 """include a file at the top of the body"""
985b3a7e0e88 add formatters to include css and genshi templates
k0s <k0scist@gmail.com>
parents: 12
diff changeset
154
985b3a7e0e88 add formatters to include css and genshi templates
k0s <k0scist@gmail.com>
parents: 12
diff changeset
155 def __init__(self, arg):
985b3a7e0e88 add formatters to include css and genshi templates
k0s <k0scist@gmail.com>
parents: 12
diff changeset
156 self.include = arg
985b3a7e0e88 add formatters to include css and genshi templates
k0s <k0scist@gmail.com>
parents: 12
diff changeset
157 def __call__(self, request, data):
985b3a7e0e88 add formatters to include css and genshi templates
k0s <k0scist@gmail.com>
parents: 12
diff changeset
158 data['include'] = self.include
985b3a7e0e88 add formatters to include css and genshi templates
k0s <k0scist@gmail.com>
parents: 12
diff changeset
159
0
fa2005f769eb adding decoupage from http://my-svn.assembla.com/svn/arbez/decoupage r355
k0s <k0scist@gmail.com>
parents:
diff changeset
160
9
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
161 def formatters():
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
162 formatters = {}
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
163 for entry_point in iter_entry_points('decoupage.formatters'):
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
164 try:
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
165 formatter = entry_point.load()
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
166 except:
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
167 continue
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
168 formatters[entry_point.name] = formatter
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
169 return formatters
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
170
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
171 def main(args=sys.argv[1:]):
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
172 for name, formatter in formatters().items():
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
173 print '%s%s' % (name, formatter.__doc__ and ': ' + formatter.__doc__ or '')
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
174
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
175 if __name__ == '__main__':
ec2d0d850b83 add ability to print formatters with decoupage-formatters console_script
k0s <k0scist@gmail.com>
parents: 1
diff changeset
176 main()