##// END OF EJS Templates
templatekw: add public function to wrap a list by _hybrid object
Yuya Nishihara -
r31924:21f12935 default
parent child Browse files
Show More
@@ -329,8 +329,7 b' class _templateconverter(object):'
329 data = list(data)
329 data = list(data)
330 def f():
330 def f():
331 yield _plainconverter.formatlist(data, name, fmt, sep)
331 yield _plainconverter.formatlist(data, name, fmt, sep)
332 return templatekw._hybrid(f(), data, lambda x: {name: x},
332 return templatekw.hybridlist(data, name=name, fmt=fmt, gen=f())
333 lambda d: fmt % d[name])
334
333
335 class templateformatter(baseformatter):
334 class templateformatter(baseformatter):
336 def __init__(self, ui, out, topic, opts):
335 def __init__(self, ui, out, topic, opts):
@@ -62,6 +62,10 b' class _hybrid(object):'
62 raise AttributeError(name)
62 raise AttributeError(name)
63 return getattr(self._values, name)
63 return getattr(self._values, name)
64
64
65 def hybridlist(data, name, fmt='%s', gen=None):
66 """Wrap data to support both list-like and string-like operations"""
67 return _hybrid(gen, data, lambda x: {name: x}, lambda d: fmt % d[name])
68
65 def unwraphybrid(thing):
69 def unwraphybrid(thing):
66 """Return an object which can be stringified possibly by using a legacy
70 """Return an object which can be stringified possibly by using a legacy
67 template"""
71 template"""
@@ -73,7 +77,7 b' def showlist(name, values, plural=None, '
73 if not element:
77 if not element:
74 element = name
78 element = name
75 f = _showlist(name, values, plural, separator, **args)
79 f = _showlist(name, values, plural, separator, **args)
76 return _hybrid(f, values, lambda x: {element: x}, lambda d: d[element])
80 return hybridlist(values, name=element, gen=f)
77
81
78 def _showlist(name, values, plural=None, separator=' ', **args):
82 def _showlist(name, values, plural=None, separator=' ', **args):
79 '''expand set of values.
83 '''expand set of values.
General Comments 0
You need to be logged in to leave comments. Login now