Mercurial > hg
comparison mercurial/templater.py @ 31926:932241b8c644
templater: add dict() constructor
It's troublesome to build JSON by template, so let's add programmatic way.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 03 Apr 2017 22:54:06 +0900 |
parents | 0f41f1e3c75c |
children | 2abc556dbe92 |
comparison
equal
deleted
inserted
replaced
31925:5b2241e84982 | 31926:932241b8c644 |
---|---|
530 return util.datestr(date, fmt) | 530 return util.datestr(date, fmt) |
531 except (TypeError, ValueError): | 531 except (TypeError, ValueError): |
532 # i18n: "date" is a keyword | 532 # i18n: "date" is a keyword |
533 raise error.ParseError(_("date expects a date information")) | 533 raise error.ParseError(_("date expects a date information")) |
534 | 534 |
535 @templatefunc('dict([key=value...])', argspec='**kwargs') | |
536 def dict_(context, mapping, args): | |
537 """Construct a dict from key-value pairs.""" | |
538 data = util.sortdict() | |
539 data.update((k, evalfuncarg(context, mapping, v)) | |
540 for k, v in args['kwargs'].iteritems()) | |
541 return templatekw.hybriddict(data) | |
542 | |
535 @templatefunc('diff([includepattern [, excludepattern]])') | 543 @templatefunc('diff([includepattern [, excludepattern]])') |
536 def diff(context, mapping, args): | 544 def diff(context, mapping, args): |
537 """Show a diff, optionally | 545 """Show a diff, optionally |
538 specifying files to include or exclude.""" | 546 specifying files to include or exclude.""" |
539 if len(args) > 2: | 547 if len(args) > 2: |