##// END OF EJS Templates
template: add ifcontains template function...
Durham Goode -
r20518:1e43f15a default
parent child Browse files
Show More
@@ -301,6 +301,19 b' def if_(context, mapping, args):'
301 elif len(args) == 3:
301 elif len(args) == 3:
302 yield _evalifliteral(args[2], context, mapping)
302 yield _evalifliteral(args[2], context, mapping)
303
303
304 def ifcontains(context, mapping, args):
305 if not (3 <= len(args) <= 4):
306 # i18n: "ifcontains" is a keyword
307 raise error.ParseError(_("ifcontains expects three or four arguments"))
308
309 item = stringify(args[0][0](context, mapping, args[0][1]))
310 items = args[1][0](context, mapping, args[1][1])
311
312 if item in items:
313 yield _evalifliteral(args[2], context, mapping)
314 elif len(args) == 4:
315 yield _evalifliteral(args[3], context, mapping)
316
304 def ifeq(context, mapping, args):
317 def ifeq(context, mapping, args):
305 if not (3 <= len(args) <= 4):
318 if not (3 <= len(args) <= 4):
306 # i18n: "ifeq" is a keyword
319 # i18n: "ifeq" is a keyword
@@ -436,6 +449,7 b' funcs = {'
436 "fill": fill,
449 "fill": fill,
437 "get": get,
450 "get": get,
438 "if": if_,
451 "if": if_,
452 "ifcontains": ifcontains,
439 "ifeq": ifeq,
453 "ifeq": ifeq,
440 "join": join,
454 "join": join,
441 "label": label,
455 "label": label,
@@ -1651,3 +1651,9 b' Test pad function'
1651 $ hg log --template '{pad(rev, 20, "-", False)} {author|user}\n'
1651 $ hg log --template '{pad(rev, 20, "-", False)} {author|user}\n'
1652 1------------------- test
1652 1------------------- test
1653 0------------------- test
1653 0------------------- test
1654
1655 Test ifcontains function
1656
1657 $ hg log --template '{rev} {ifcontains("a", file_adds, "added a", "did not add a")}\n'
1658 1 did not add a
1659 0 added a
General Comments 0
You need to be logged in to leave comments. Login now