comparison mercurial/templatekw.py @ 24241:e7baf88c29c3

templatekw: forward _hybrid.get to raw values so that get(extras, key) works ef78450c8df6 implies that the primary goal is to allow "{get(extras, key)}", but it didn't work. I'm not sure if _hybrid should forward all unknown attributes to values, so only "get" is forwarded for now.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 18 Feb 2015 23:17:52 +0900
parents bd504d90588d
children 696ab1a24ae0
comparison
equal deleted inserted replaced
24240:bd504d90588d 24241:e7baf88c29c3
12 # This helper class allows us to handle both: 12 # This helper class allows us to handle both:
13 # "{files}" (legacy command-line-specific list hack) and 13 # "{files}" (legacy command-line-specific list hack) and
14 # "{files % '{file}\n'}" (hgweb-style with inlining and function support) 14 # "{files % '{file}\n'}" (hgweb-style with inlining and function support)
15 # and to access raw values: 15 # and to access raw values:
16 # "{ifcontains(file, files, ...)}", "{ifcontains(key, extras, ...)}" 16 # "{ifcontains(file, files, ...)}", "{ifcontains(key, extras, ...)}"
17 # "{get(extras, key)}"
17 18
18 class _hybrid(object): 19 class _hybrid(object):
19 def __init__(self, gen, values, makemap, joinfmt=None): 20 def __init__(self, gen, values, makemap, joinfmt=None):
20 self.gen = gen 21 self.gen = gen
21 self.values = values 22 self.values = values
32 yield makemap(x) 33 yield makemap(x)
33 def __contains__(self, x): 34 def __contains__(self, x):
34 return x in self.values 35 return x in self.values
35 def __len__(self): 36 def __len__(self):
36 return len(self.values) 37 return len(self.values)
38 def __getattr__(self, name):
39 if name != 'get':
40 raise AttributeError(name)
41 return getattr(self.values, name)
37 42
38 def showlist(name, values, plural=None, element=None, **args): 43 def showlist(name, values, plural=None, element=None, **args):
39 if not element: 44 if not element:
40 element = name 45 element = name
41 f = _showlist(name, values, plural, **args) 46 f = _showlist(name, values, plural, **args)