mercurial/templater.py
changeset 10848 01346cea5485
parent 10847 90f4367535a5
child 10849 12ffc5ce1291
equal deleted inserted replaced
10847:90f4367535a5 10848:01346cea5485
    41 
    41 
    42     filter uses function to transform value. syntax is
    42     filter uses function to transform value. syntax is
    43     {key|filter1|filter2|...}.'''
    43     {key|filter1|filter2|...}.'''
    44 
    44 
    45     def __init__(self, loader, filters={}, defaults={}):
    45     def __init__(self, loader, filters={}, defaults={}):
    46         self.loader = loader
    46         self._loader = loader
    47         self.filters = filters
    47         self._filters = filters
    48         self.defaults = defaults
    48         self._defaults = defaults
    49         self.cache = {}
    49         self._cache = {}
    50         self.parsecache = {}
       
    51 
    50 
    52     def process(self, t, mapping):
    51     def process(self, t, mapping):
    53         '''Perform expansion. t is name of map element to expand. mapping contains
    52         '''Perform expansion. t is name of map element to expand. mapping contains
    54         added elements for use during expansion. Is a generator.'''
    53         added elements for use during expansion. Is a generator.'''
    55         if t not in self.parsecache:
    54         if t not in self._cache:
    56             tmpl = self.loader(t)
    55             self._cache[t] = self._parse(self._loader(t))
    57             self.parsecache[t] = self._parse(tmpl)
    56         parsed = self._cache[t]
    58         parsed = self.parsecache[t]
       
    59         iters = [self._process(parsed, mapping)]
    57         iters = [self._process(parsed, mapping)]
    60         while iters:
    58         while iters:
    61             try:
    59             try:
    62                 item = iters[0].next()
    60                 item = iters[0].next()
    63             except StopIteration:
    61             except StopIteration:
   137                 parsed.append((formatter, expr.split('%')))
   135                 parsed.append((formatter, expr.split('%')))
   138             elif '|' in expr:
   136             elif '|' in expr:
   139                 parts = expr.split('|')
   137                 parts = expr.split('|')
   140                 val = parts[0]
   138                 val = parts[0]
   141                 try:
   139                 try:
   142                     filters = [self.filters[f] for f in parts[1:]]
   140                     filters = [self._filters[f] for f in parts[1:]]
   143                 except KeyError, i:
   141                 except KeyError, i:
   144                     raise SyntaxError(_("unknown filter '%s'") % i[0])
   142                     raise SyntaxError(_("unknown filter '%s'") % i[0])
   145                 parsed.append((filt, (filters, val)))
   143                 parsed.append((filt, (filters, val)))
   146             else:
   144             else:
   147                 parsed.append((getter, expr))
   145                 parsed.append((getter, expr))