Show More
@@ -114,7 +114,7 b' schemes = {' | |||||
114 |
|
114 | |||
115 | def extsetup(ui): |
|
115 | def extsetup(ui): | |
116 | schemes.update(dict(ui.configitems('schemes'))) |
|
116 | schemes.update(dict(ui.configitems('schemes'))) | |
117 |
t = templater.engine( |
|
117 | t = templater.engine(templater.parse) | |
118 | for scheme, url in schemes.items(): |
|
118 | for scheme, url in schemes.items(): | |
119 | if (pycompat.iswindows and len(scheme) == 1 and scheme.isalpha() |
|
119 | if (pycompat.iswindows and len(scheme) == 1 and scheme.isalpha() | |
120 | and os.path.exists('%s:\\' % scheme)): |
|
120 | and os.path.exists('%s:\\' % scheme)): |
@@ -597,8 +597,7 b' class engine(object):' | |||||
597 | filter uses function to transform value. syntax is |
|
597 | filter uses function to transform value. syntax is | |
598 | {key|filter1|filter2|...}.''' |
|
598 | {key|filter1|filter2|...}.''' | |
599 |
|
599 | |||
600 |
def __init__(self, loader, filters=None, defaults=None, resources=None |
|
600 | def __init__(self, loader, filters=None, defaults=None, resources=None): | |
601 | aliases=()): |
|
|||
602 | self._loader = loader |
|
601 | self._loader = loader | |
603 | if filters is None: |
|
602 | if filters is None: | |
604 | filters = {} |
|
603 | filters = {} | |
@@ -610,7 +609,6 b' class engine(object):' | |||||
610 | resources = nullresourcemapper() |
|
609 | resources = nullresourcemapper() | |
611 | self._defaults = defaults |
|
610 | self._defaults = defaults | |
612 | self._resources = resources |
|
611 | self._resources = resources | |
613 | self._aliasmap = _aliasrules.buildmap(aliases) |
|
|||
614 | self._cache = {} # key: (func, data) |
|
612 | self._cache = {} # key: (func, data) | |
615 | self._tmplcache = {} # literal template: (func, data) |
|
613 | self._tmplcache = {} # literal template: (func, data) | |
616 |
|
614 | |||
@@ -665,9 +663,7 b' class engine(object):' | |||||
665 | def _load(self, t): |
|
663 | def _load(self, t): | |
666 | '''load, parse, and cache a template''' |
|
664 | '''load, parse, and cache a template''' | |
667 | if t not in self._cache: |
|
665 | if t not in self._cache: | |
668 |
x = |
|
666 | x = self._loader(t) | |
669 | if self._aliasmap: |
|
|||
670 | x = _aliasrules.expand(self._aliasmap, x) |
|
|||
671 | # put poison to cut recursion while compiling 't' |
|
667 | # put poison to cut recursion while compiling 't' | |
672 | self._cache[t] = (_runrecursivesymbol, t) |
|
668 | self._cache[t] = (_runrecursivesymbol, t) | |
673 | try: |
|
669 | try: | |
@@ -808,7 +804,7 b' class templater(object):' | |||||
808 | self._filters.update(filters) |
|
804 | self._filters.update(filters) | |
809 | self.defaults = defaults |
|
805 | self.defaults = defaults | |
810 | self._resources = resources |
|
806 | self._resources = resources | |
811 |
self._alias |
|
807 | self._aliasmap = _aliasrules.buildmap(aliases) | |
812 | self._minchunk, self._maxchunk = minchunk, maxchunk |
|
808 | self._minchunk, self._maxchunk = minchunk, maxchunk | |
813 |
|
809 | |||
814 | @classmethod |
|
810 | @classmethod | |
@@ -819,14 +815,14 b' class templater(object):' | |||||
819 | cache, tmap, aliases = _readmapfile(mapfile) |
|
815 | cache, tmap, aliases = _readmapfile(mapfile) | |
820 | t.cache.update(cache) |
|
816 | t.cache.update(cache) | |
821 | t._map = tmap |
|
817 | t._map = tmap | |
822 |
t._alias |
|
818 | t._aliasmap = _aliasrules.buildmap(aliases) | |
823 | return t |
|
819 | return t | |
824 |
|
820 | |||
825 | def __contains__(self, key): |
|
821 | def __contains__(self, key): | |
826 | return key in self.cache or key in self._map |
|
822 | return key in self.cache or key in self._map | |
827 |
|
823 | |||
828 | def load(self, t): |
|
824 | def load(self, t): | |
829 |
|
|
825 | """Get parsed tree for the given template name. Use a local cache.""" | |
830 | if t not in self.cache: |
|
826 | if t not in self.cache: | |
831 | try: |
|
827 | try: | |
832 | self.cache[t] = util.readfile(self._map[t]) |
|
828 | self.cache[t] = util.readfile(self._map[t]) | |
@@ -838,7 +834,13 b' class templater(object):' | |||||
838 | % (self._map[t], |
|
834 | % (self._map[t], | |
839 | stringutil.forcebytestr(inst.args[1]))) |
|
835 | stringutil.forcebytestr(inst.args[1]))) | |
840 | raise IOError(inst.args[0], encoding.strfromlocal(reason)) |
|
836 | raise IOError(inst.args[0], encoding.strfromlocal(reason)) | |
841 | return self.cache[t] |
|
837 | return self._parse(self.cache[t]) | |
|
838 | ||||
|
839 | def _parse(self, tmpl): | |||
|
840 | x = parse(tmpl) | |||
|
841 | if self._aliasmap: | |||
|
842 | x = _aliasrules.expand(self._aliasmap, x) | |||
|
843 | return x | |||
842 |
|
844 | |||
843 | def renderdefault(self, mapping): |
|
845 | def renderdefault(self, mapping): | |
844 | """Render the default unnamed template and return result as string""" |
|
846 | """Render the default unnamed template and return result as string""" | |
@@ -851,8 +853,7 b' class templater(object):' | |||||
851 | def generate(self, t, mapping): |
|
853 | def generate(self, t, mapping): | |
852 | """Return a generator that renders the specified named template and |
|
854 | """Return a generator that renders the specified named template and | |
853 | yields chunks""" |
|
855 | yields chunks""" | |
854 |
proc = engine(self.load, self._filters, self.defaults, self._resources |
|
856 | proc = engine(self.load, self._filters, self.defaults, self._resources) | |
855 | self._aliases) |
|
|||
856 | stream = proc.process(t, mapping) |
|
857 | stream = proc.process(t, mapping) | |
857 | if self._minchunk: |
|
858 | if self._minchunk: | |
858 | stream = util.increasingchunks(stream, min=self._minchunk, |
|
859 | stream = util.increasingchunks(stream, min=self._minchunk, |
General Comments 0
You need to be logged in to leave comments.
Login now