##// END OF EJS Templates
formatter: add fm.nested(field) to either write or build sub items...
Yuya Nishihara -
r29837:5b886289 default
parent child Browse files
Show More
@@ -91,11 +91,23 b' class baseformatter(object):'
91 91 def plain(self, text, **opts):
92 92 '''show raw text for non-templated mode'''
93 93 pass
94 def nested(self, field):
95 '''sub formatter to store nested data in the specified field'''
96 self._item[field] = data = []
97 return _nestedformatter(self._ui, self._converter, data)
94 98 def end(self):
95 99 '''end output for the formatter'''
96 100 if self._item is not None:
97 101 self._showitem()
98 102
103 class _nestedformatter(baseformatter):
104 '''build sub items and store them in the parent formatter'''
105 def __init__(self, ui, converter, data):
106 baseformatter.__init__(self, ui, topic='', opts={}, converter=converter)
107 self._data = data
108 def _showitem(self):
109 self._data.append(self._item)
110
99 111 def _iteritems(data):
100 112 '''iterate key-value pairs in stable order'''
101 113 if isinstance(data, dict):
@@ -139,6 +151,9 b' class plainformatter(baseformatter):'
139 151 self._ui.write(deftext % fielddata, **opts)
140 152 def plain(self, text, **opts):
141 153 self._ui.write(text, **opts)
154 def nested(self, field):
155 # nested data will be directly written to ui
156 return self
142 157 def end(self):
143 158 pass
144 159
General Comments 0
You need to be logged in to leave comments. Login now