Mercurial > hg
changeset 10853:b6f6d9fd53d6
templater: drop raw method
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 05 Apr 2010 15:25:08 -0500 |
parents | 0d50586a9d31 |
children | 4036634560d6 |
files | mercurial/templater.py |
diffstat | 1 files changed, 14 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templater.py Mon Apr 05 15:25:08 2010 -0500 +++ b/mercurial/templater.py Mon Apr 05 15:25:08 2010 -0500 @@ -66,19 +66,18 @@ self._defaults = defaults self._cache = {} + def process(self, t, mapping): + '''Perform expansion. t is name of map element to expand. + mapping contains added elements for use during expansion. Is a + generator.''' + return _flatten(self._process(self._load(t), mapping)) + def _load(self, t): '''load, parse, and cache a template''' if t not in self._cache: self._cache[t] = self._parse(self._loader(t)) return self._cache[t] - def process(self, t, mapping): - '''Perform expansion. t is name of map element to expand. - mapping contains added elements for use during expansion. Is a - generator.''' - - return _flatten(self._process(self._load(t), mapping)) - def _get(self, mapping, key): v = mapping.get(key) if v is None: @@ -87,9 +86,6 @@ v = v(**mapping) return v - def _raw(self, mapping, x): - return x - def _filter(self, mapping, parts): filters, val = parts x = self._get(mapping, val) @@ -116,27 +112,26 @@ def _parse(self, tmpl): '''preparse a template''' - parsed = [] pos, stop = 0, len(tmpl) while pos < stop: n = tmpl.find('{', pos) if n < 0: - parsed.append((self._raw, tmpl[pos:stop])) + parsed.append((None, tmpl[pos:stop])) break if n > 0 and tmpl[n - 1] == '\\': # escaped - parsed.append((self._raw, tmpl[pos:n + 1])) + parsed.append((None, tmpl[pos:n + 1])) pos = n + 1 continue if n > pos: - parsed.append((self._raw, tmpl[pos:n])) + parsed.append((None, tmpl[pos:n])) pos = n n = tmpl.find('}', pos) if n < 0: # no closing - parsed.append((self._raw, tmpl[pos:stop])) + parsed.append((None, tmpl[pos:stop])) break expr = tmpl[pos + 1:n] @@ -161,7 +156,10 @@ def _process(self, parsed, mapping): '''Render a template. Returns a generator.''' for f, e in parsed: - yield f(mapping, e) + if f: + yield f(mapping, e) + else: + yield e engines = {'default': engine}