Show More
@@ -67,9 +67,9 b' class templater(object):' | |||
|
67 | 67 | tmpl = self.cache[t] = file(self.map[t]).read() |
|
68 | 68 | return self.template(tmpl, self.filters, **m) |
|
69 | 69 | |
|
70 | template_re = re.compile(r"#([a-zA-Z_][a-zA-Z0-9_]*)" | |
|
70 | template_re = re.compile(r"[#{]([a-zA-Z_][a-zA-Z0-9_]*)" | |
|
71 | 71 | r"((%[a-zA-Z_][a-zA-Z0-9_]*)*)" |
|
72 | r"((\|[a-zA-Z_][a-zA-Z0-9_]*)*)#") | |
|
72 | r"((\|[a-zA-Z_][a-zA-Z0-9_]*)*)[#}]") | |
|
73 | 73 | |
|
74 | 74 | def template(self, tmpl, filters={}, **map): |
|
75 | 75 | lm = map.copy() |
@@ -136,18 +136,34 b' def nl2br(text):' | |||
|
136 | 136 | def obfuscate(text): |
|
137 | 137 | return ''.join(['&#%d;' % ord(c) for c in text]) |
|
138 | 138 | |
|
139 | def domain(author): | |
|
140 | f = author.find('@') | |
|
141 | if f == -1: return '' | |
|
142 | author = author[f+1:] | |
|
143 | f = author.find('>') | |
|
144 | if f >= 0: author = author[:f] | |
|
145 | return author | |
|
146 | ||
|
147 | def person(author): | |
|
148 | f = author.find('<') | |
|
149 | if f == -1: return util.shortuser(author) | |
|
150 | return author[:f].rstrip() | |
|
151 | ||
|
139 | 152 | common_filters = { |
|
140 | "escape": lambda x: cgi.escape(x, True), | |
|
141 | "urlescape": urllib.quote, | |
|
142 | "strip": lambda x: x.strip(), | |
|
153 | "addbreaks": nl2br, | |
|
143 | 154 | "age": age, |
|
144 | 155 | "date": lambda x: util.datestr(x), |
|
145 | "addbreaks": nl2br, | |
|
156 | "escape": lambda x: cgi.escape(x, True), | |
|
157 | "firstline": (lambda x: x.splitlines(1)[0]), | |
|
158 | "domain": domain, | |
|
146 | 159 | "obfuscate": obfuscate, |
|
160 | "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"), | |
|
161 | "person": person, | |
|
162 | "rfc822date": lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S"), | |
|
147 | 163 | "short": (lambda x: x[:12]), |
|
148 |
" |
|
|
149 | "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"), | |
|
150 | "rfc822date": lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S"), | |
|
164 | "strip": lambda x: x.strip(), | |
|
165 | "urlescape": urllib.quote, | |
|
166 | "user": util.shortuser, | |
|
151 | 167 | } |
|
152 | 168 | |
|
153 | 169 | def templatepath(name=None): |
General Comments 0
You need to be logged in to leave comments.
Login now