##// END OF EJS Templates
templatekw: add public function to wrap a dict by _hybrid object
Yuya Nishihara -
r31925:5b2241e8 default
parent child Browse files
Show More
@@ -321,8 +321,8 b' class _templateconverter(object):'
321 321 data = util.sortdict(_iteritems(data))
322 322 def f():
323 323 yield _plainconverter.formatdict(data, key, value, fmt, sep)
324 return templatekw._hybrid(f(), data, lambda k: {key: k, value: data[k]},
325 lambda d: fmt % (d[key], d[value]))
324 return templatekw.hybriddict(data, key=key, value=value, fmt=fmt,
325 gen=f())
326 326 @staticmethod
327 327 def formatlist(data, name, fmt, sep):
328 328 '''build object that can be evaluated as either plain string or list'''
@@ -62,6 +62,11 b' class _hybrid(object):'
62 62 raise AttributeError(name)
63 63 return getattr(self._values, name)
64 64
65 def hybriddict(data, key='key', value='value', fmt='%s=%s', gen=None):
66 """Wrap data to support both dict-like and string-like operations"""
67 return _hybrid(gen, data, lambda k: {key: k, value: data[k]},
68 lambda d: fmt % (d[key], d[value]))
69
65 70 def hybridlist(data, name, fmt='%s', gen=None):
66 71 """Wrap data to support both list-like and string-like operations"""
67 72 return _hybrid(gen, data, lambda x: {name: x}, lambda d: fmt % d[name])
General Comments 0
You need to be logged in to leave comments. Login now