##// END OF EJS Templates
templater: extend dot operator as a short for get(dict, key)
Yuya Nishihara -
r34537:4c1cfe54 default
parent child Browse files
Show More
@@ -76,6 +76,7 b' The dot operator can be used as a shorth'
76
76
77 - ``expr.member`` is roughly equivalent to ``expr % "{member}"`` if ``expr``
77 - ``expr.member`` is roughly equivalent to ``expr % "{member}"`` if ``expr``
78 returns a non-list/dict. The returned value is not stringified.
78 returns a non-list/dict. The returned value is not stringified.
79 - ``dict.key`` is identical to ``get(dict, "key")``.
79
80
80 Aliases
81 Aliases
81 =======
82 =======
@@ -463,7 +463,8 b' def runmember(context, mapping, data):'
463 lm = mapping.copy()
463 lm = mapping.copy()
464 lm.update(d.tomap())
464 lm.update(d.tomap())
465 return runsymbol(context, lm, memb)
465 return runsymbol(context, lm, memb)
466 # TODO: d.get(memb) if dict-like?
466 if util.safehasattr(d, 'get'):
467 return _getdictitem(d, memb)
467
468
468 sym = findsymbolicname(darg)
469 sym = findsymbolicname(darg)
469 if sym:
470 if sym:
@@ -751,6 +752,9 b' def get(context, mapping, args):'
751 raise error.ParseError(_("get() expects a dict as first argument"))
752 raise error.ParseError(_("get() expects a dict as first argument"))
752
753
753 key = evalfuncarg(context, mapping, args[1])
754 key = evalfuncarg(context, mapping, args[1])
755 return _getdictitem(dictarg, key)
756
757 def _getdictitem(dictarg, key):
754 val = dictarg.get(key)
758 val = dictarg.get(key)
755 if val is None:
759 if val is None:
756 return
760 return
@@ -3184,6 +3184,8 b' Test evaluation of dot operator:'
3184
3184
3185 $ hg log -R latesttag -l1 -T '{min(revset("0:9")).node}\n'
3185 $ hg log -R latesttag -l1 -T '{min(revset("0:9")).node}\n'
3186 ce3cec86e6c26bd9bdfc590a6b92abc9680f1796
3186 ce3cec86e6c26bd9bdfc590a6b92abc9680f1796
3187 $ hg log -R latesttag -r0 -T '{extras.branch}\n'
3188 default
3187
3189
3188 $ hg log -R latesttag -l1 -T '{author.invalid}\n'
3190 $ hg log -R latesttag -l1 -T '{author.invalid}\n'
3189 hg: parse error: keyword 'author' has no member
3191 hg: parse error: keyword 'author' has no member
General Comments 0
You need to be logged in to leave comments. Login now