Show More
@@ -44,19 +44,21 b' Note that a filter is nothing more than ' | |||
|
44 | 44 | |
|
45 | 45 | In addition to filters, there are some basic built-in functions: |
|
46 | 46 | |
|
47 | - date(date[, fmt]) | |
|
48 | ||
|
49 | - fill(text[, width]) | |
|
50 | ||
|
51 | - get(dict, key) | |
|
52 | ||
|
47 | 53 | - if(expr, then[, else]) |
|
48 | 54 | |
|
49 | 55 | - ifeq(expr, expr, then[, else]) |
|
50 | 56 | |
|
51 | - sub(pat, repl, expr) | |
|
52 | ||
|
53 | 57 | - join(list, sep) |
|
54 | 58 | |
|
55 | 59 | - label(label, expr) |
|
56 | 60 | |
|
57 | - date(date[, fmt]) | |
|
58 | ||
|
59 | - fill(text[, width]) | |
|
61 | - sub(pat, repl, expr) | |
|
60 | 62 | |
|
61 | 63 | Also, for any expression that returns a list, there is a list operator: |
|
62 | 64 |
@@ -207,6 +207,19 b' def buildfunc(exp, context):' | |||
|
207 | 207 | f = context._filters[n] |
|
208 | 208 | return (runfilter, (args[0][0], args[0][1], f)) |
|
209 | 209 | |
|
210 | def get(context, mapping, args): | |
|
211 | if len(args) != 2: | |
|
212 | # i18n: "get" is a keyword | |
|
213 | raise error.ParseError(_("get() expects two arguments")) | |
|
214 | ||
|
215 | dictarg = args[0][0](context, mapping, args[0][1]) | |
|
216 | if not util.safehasattr(dictarg, 'get'): | |
|
217 | # i18n: "get" is a keyword | |
|
218 | raise error.ParseError(_("get() expects a dict as first argument")) | |
|
219 | ||
|
220 | key = args[1][0](context, mapping, args[1][1]) | |
|
221 | yield dictarg.get(key) | |
|
222 | ||
|
210 | 223 | def join(context, mapping, args): |
|
211 | 224 | if not (1 <= len(args) <= 2): |
|
212 | 225 | # i18n: "join" is a keyword |
@@ -285,11 +298,12 b' methods = {' | |||
|
285 | 298 | } |
|
286 | 299 | |
|
287 | 300 | funcs = { |
|
301 | "get": get, | |
|
288 | 302 | "if": if_, |
|
289 | 303 | "ifeq": ifeq, |
|
290 | 304 | "join": join, |
|
305 | "label": label, | |
|
291 | 306 | "sub": sub, |
|
292 | "label": label, | |
|
293 | 307 | } |
|
294 | 308 | |
|
295 | 309 | # template engine |
General Comments 0
You need to be logged in to leave comments.
Login now