##// END OF EJS Templates
templater: add if/ifeq conditionals
Matt Mackall -
r17636:ce18dbcd default
parent child Browse files
Show More
@@ -227,6 +227,31 b' def sub(context, mapping, args):'
227 227 src = stringify(args[2][0](context, mapping, args[2][1]))
228 228 yield re.sub(pat, rpl, src)
229 229
230 def if_(context, mapping, args):
231 if not (2 <= len(args) <= 3):
232 raise error.ParseError(_("if expects two or three arguments"))
233
234 test = stringify(args[0][0](context, mapping, args[0][1]))
235 if test:
236 t = stringify(args[1][0](context, mapping, args[1][1]))
237 yield runtemplate(context, mapping, compiletemplate(t, context))
238 elif len(args) == 3:
239 t = stringify(args[2][0](context, mapping, args[2][1]))
240 yield runtemplate(context, mapping, compiletemplate(t, context))
241
242 def ifeq(context, mapping, args):
243 if not (3 <= len(args) <= 4):
244 raise error.ParseError(_("ifeq expects three or four arguments"))
245
246 test = stringify(args[0][0](context, mapping, args[0][1]))
247 match = stringify(args[1][0](context, mapping, args[1][1]))
248 if test == match:
249 t = stringify(args[2][0](context, mapping, args[2][1]))
250 yield runtemplate(context, mapping, compiletemplate(t, context))
251 elif len(args) == 4:
252 t = stringify(args[3][0](context, mapping, args[3][1]))
253 yield runtemplate(context, mapping, compiletemplate(t, context))
254
230 255 methods = {
231 256 "string": lambda e, c: (runstring, e[1]),
232 257 "symbol": lambda e, c: (runsymbol, e[1]),
@@ -238,6 +263,8 b' methods = {'
238 263 }
239 264
240 265 funcs = {
266 "if": if_,
267 "ifeq": ifeq,
241 268 "join": join,
242 269 "sub": sub,
243 270 }
General Comments 0
You need to be logged in to leave comments. Login now