comparison mercurial/templater.py @ 14925:ab545a15d807

templater: use a global funcs table
author Matt Mackall <mpm@selenic.com>
date Sat, 23 Jul 2011 14:33:35 -0500
parents 135e244776f0
children 4a28cb4df1f8
comparison
equal deleted inserted replaced
14924:545e00279670 14925:ab545a15d807
170 yield i 170 yield i
171 171
172 def buildfunc(exp, context): 172 def buildfunc(exp, context):
173 n = getsymbol(exp[1]) 173 n = getsymbol(exp[1])
174 args = [compileexp(x, context) for x in getlist(exp[2])] 174 args = [compileexp(x, context) for x in getlist(exp[2])]
175 if n in funcs:
176 f = funcs[n]
177 return (f, args)
175 if n in context._filters: 178 if n in context._filters:
176 if len(args) != 1: 179 if len(args) != 1:
177 raise error.ParseError(_("filter %s expects one argument") % n) 180 raise error.ParseError(_("filter %s expects one argument") % n)
178 f = context._filters[n] 181 f = context._filters[n]
179 return (runfilter, (args[0][0], args[0][1], f)) 182 return (runfilter, (args[0][0], args[0][1], f))
180 elif n in context._funcs:
181 f = context._funcs[n]
182 return (f, args)
183 183
184 methods = { 184 methods = {
185 "string": lambda e, c: (runstring, e[1]), 185 "string": lambda e, c: (runstring, e[1]),
186 "symbol": lambda e, c: (runsymbol, e[1]), 186 "symbol": lambda e, c: (runsymbol, e[1]),
187 "group": lambda e, c: compileexp(e[1], c), 187 "group": lambda e, c: compileexp(e[1], c),
188 # ".": buildmember, 188 # ".": buildmember,
189 "|": buildfilter, 189 "|": buildfilter,
190 "%": buildmap, 190 "%": buildmap,
191 "func": buildfunc, 191 "func": buildfunc,
192 } 192 }
193
194 funcs = {
195 }
193 196
194 # template engine 197 # template engine
195 198
196 path = ['templates', '../templates'] 199 path = ['templates', '../templates']
197 stringify = templatefilters.stringify 200 stringify = templatefilters.stringify