Show More
@@ -1478,6 +1478,7 b' class changeset_templater(changeset_prin' | |||
|
1478 | 1478 | def __init__(self, ui, repo, matchfn, diffopts, tmpl, mapfile, buffered): |
|
1479 | 1479 | changeset_printer.__init__(self, ui, repo, matchfn, diffopts, buffered) |
|
1480 | 1480 | formatnode = ui.debugflag and (lambda x: x) or (lambda x: x[:12]) |
|
1481 | filters = {'formatnode': formatnode} | |
|
1481 | 1482 | defaulttempl = { |
|
1482 | 1483 | 'parent': '{rev}:{node|formatnode} ', |
|
1483 | 1484 | 'manifest': '{rev}:{node|formatnode}', |
@@ -1486,10 +1487,14 b' class changeset_templater(changeset_prin' | |||
|
1486 | 1487 | } |
|
1487 | 1488 | # filecopy is preserved for compatibility reasons |
|
1488 | 1489 | defaulttempl['filecopy'] = defaulttempl['file_copy'] |
|
1489 | self.t = templater.templater(mapfile, {'formatnode': formatnode}, | |
|
1490 | cache=defaulttempl) | |
|
1491 | if tmpl: | |
|
1492 | self.t.cache['changeset'] = tmpl | |
|
1490 | assert not (tmpl and mapfile) | |
|
1491 | if mapfile: | |
|
1492 | self.t = templater.templater.frommapfile(mapfile, filters=filters, | |
|
1493 | cache=defaulttempl) | |
|
1494 | else: | |
|
1495 | self.t = templater.templater(filters=filters, cache=defaulttempl) | |
|
1496 | if tmpl: | |
|
1497 | self.t.cache['changeset'] = tmpl | |
|
1493 | 1498 | |
|
1494 | 1499 | self.cache = {} |
|
1495 | 1500 |
@@ -2770,7 +2770,7 b' def debuginstall(ui, **opts):' | |||
|
2770 | 2770 | # template found, check if it is working |
|
2771 | 2771 | err = None |
|
2772 | 2772 | try: |
|
2773 | templater.templater(m) | |
|
2773 | templater.templater.frommapfile(m) | |
|
2774 | 2774 | except Exception as inst: |
|
2775 | 2775 | err = inst |
|
2776 | 2776 | p = None |
@@ -3681,7 +3681,7 b' def debugtemplate(ui, repo, tmpl, **opts' | |||
|
3681 | 3681 | mapfile = None |
|
3682 | 3682 | if revs is None: |
|
3683 | 3683 | k = 'debugtemplate' |
|
3684 |
t = templater.templater( |
|
|
3684 | t = templater.templater() | |
|
3685 | 3685 | t.cache[k] = tmpl |
|
3686 | 3686 | ui.write(templater.stringify(t(k, **props))) |
|
3687 | 3687 | else: |
@@ -526,7 +526,7 b' def _formatlabels(repo, fcd, fco, fca, l' | |||
|
526 | 526 | |
|
527 | 527 | ui = repo.ui |
|
528 | 528 | template = ui.config('ui', 'mergemarkertemplate', _defaultconflictmarker) |
|
529 |
tmpl = templater.templater( |
|
|
529 | tmpl = templater.templater(cache={'conflictmarker': template}) | |
|
530 | 530 | |
|
531 | 531 | pad = max(len(l) for l in labels) |
|
532 | 532 |
@@ -190,7 +190,10 b' def lookuptemplate(ui, topic, tmpl):' | |||
|
190 | 190 | |
|
191 | 191 | def gettemplater(ui, topic, spec): |
|
192 | 192 | tmpl, mapfile = lookuptemplate(ui, topic, spec) |
|
193 | t = templater.templater(mapfile, {}) | |
|
193 | assert not (tmpl and mapfile) | |
|
194 | if mapfile: | |
|
195 | return templater.templater.frommapfile(mapfile) | |
|
196 | t = templater.templater() | |
|
194 | 197 | if tmpl: |
|
195 | 198 | t.cache[topic] = tmpl |
|
196 | 199 | return t |
@@ -188,20 +188,22 b' class requestcontext(object):' | |||
|
188 | 188 | |
|
189 | 189 | # create the templater |
|
190 | 190 | |
|
191 | tmpl = templater.templater(mapfile, | |
|
192 | filters={'websub': websubfilter}, | |
|
193 | defaults={'url': req.url, | |
|
194 | 'logourl': logourl, | |
|
195 | 'logoimg': logoimg, | |
|
196 | 'staticurl': staticurl, | |
|
197 | 'urlbase': urlbase, | |
|
198 | 'repo': self.reponame, | |
|
199 | 'encoding': encoding.encoding, | |
|
200 | 'motd': motd, | |
|
201 | 'sessionvars': sessionvars, | |
|
202 | 'pathdef': makebreadcrumb(req.url), | |
|
203 | 'style': style, | |
|
204 | }) | |
|
191 | defaults = { | |
|
192 | 'url': req.url, | |
|
193 | 'logourl': logourl, | |
|
194 | 'logoimg': logoimg, | |
|
195 | 'staticurl': staticurl, | |
|
196 | 'urlbase': urlbase, | |
|
197 | 'repo': self.reponame, | |
|
198 | 'encoding': encoding.encoding, | |
|
199 | 'motd': motd, | |
|
200 | 'sessionvars': sessionvars, | |
|
201 | 'pathdef': makebreadcrumb(req.url), | |
|
202 | 'style': style, | |
|
203 | } | |
|
204 | tmpl = templater.templater.frommapfile(mapfile, | |
|
205 | filters={'websub': websubfilter}, | |
|
206 | defaults=defaults) | |
|
205 | 207 | return tmpl |
|
206 | 208 | |
|
207 | 209 |
@@ -491,16 +491,17 b' class hgwebdir(object):' | |||
|
491 | 491 | if not staticurl.endswith('/'): |
|
492 | 492 | staticurl += '/' |
|
493 | 493 | |
|
494 | tmpl = templater.templater(mapfile, | |
|
495 |
|
|
|
496 |
|
|
|
497 | "url": url, | |
|
498 |
|
|
|
499 |
|
|
|
500 |
|
|
|
501 |
|
|
|
502 |
|
|
|
503 | }) | |
|
494 | defaults = { | |
|
495 | "encoding": encoding.encoding, | |
|
496 | "motd": motd, | |
|
497 | "url": url, | |
|
498 | "logourl": logourl, | |
|
499 | "logoimg": logoimg, | |
|
500 | "staticurl": staticurl, | |
|
501 | "sessionvars": sessionvars, | |
|
502 | "style": style, | |
|
503 | } | |
|
504 | tmpl = templater.templater.frommapfile(mapfile, defaults=defaults) | |
|
504 | 505 | return tmpl |
|
505 | 506 | |
|
506 | 507 | def updatereqenv(self, env): |
@@ -1016,10 +1016,9 b' class TemplateNotFound(error.Abort):' | |||
|
1016 | 1016 | |
|
1017 | 1017 | class templater(object): |
|
1018 | 1018 | |
|
1019 |
def __init__(self |
|
|
1019 | def __init__(self, filters=None, defaults=None, cache=None, | |
|
1020 | 1020 | minchunk=1024, maxchunk=65536): |
|
1021 | 1021 | '''set up template engine. |
|
1022 | mapfile is name of file to read map definitions from. | |
|
1023 | 1022 | filters is dict of functions. each transforms a value into another. |
|
1024 | 1023 | defaults is dict of default map definitions.''' |
|
1025 | 1024 | if filters is None: |
@@ -1036,11 +1035,15 b' class templater(object):' | |||
|
1036 | 1035 | self.minchunk, self.maxchunk = minchunk, maxchunk |
|
1037 | 1036 | self.ecache = {} |
|
1038 | 1037 | |
|
1039 | if not mapfile: | |
|
1040 | return | |
|
1038 | @classmethod | |
|
1039 | def frommapfile(cls, mapfile, filters=None, defaults=None, cache=None, | |
|
1040 | minchunk=1024, maxchunk=65536): | |
|
1041 | """Create templater from the specified map file""" | |
|
1042 | t = cls(filters, defaults, cache, minchunk, maxchunk) | |
|
1041 | 1043 | cache, tmap = _readmapfile(mapfile) |
|
1042 |
|
|
|
1043 |
|
|
|
1044 | t.cache.update(cache) | |
|
1045 | t.map = tmap | |
|
1046 | return t | |
|
1044 | 1047 | |
|
1045 | 1048 | def __contains__(self, key): |
|
1046 | 1049 | return key in self.cache or key in self.map |
General Comments 0
You need to be logged in to leave comments.
Login now