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