Show More
@@ -91,11 +91,23 b' class baseformatter(object):' | |||||
91 | def plain(self, text, **opts): |
|
91 | def plain(self, text, **opts): | |
92 | '''show raw text for non-templated mode''' |
|
92 | '''show raw text for non-templated mode''' | |
93 | pass |
|
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 | def end(self): |
|
98 | def end(self): | |
95 | '''end output for the formatter''' |
|
99 | '''end output for the formatter''' | |
96 | if self._item is not None: |
|
100 | if self._item is not None: | |
97 | self._showitem() |
|
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 | def _iteritems(data): |
|
111 | def _iteritems(data): | |
100 | '''iterate key-value pairs in stable order''' |
|
112 | '''iterate key-value pairs in stable order''' | |
101 | if isinstance(data, dict): |
|
113 | if isinstance(data, dict): | |
@@ -139,6 +151,9 b' class plainformatter(baseformatter):' | |||||
139 | self._ui.write(deftext % fielddata, **opts) |
|
151 | self._ui.write(deftext % fielddata, **opts) | |
140 | def plain(self, text, **opts): |
|
152 | def plain(self, text, **opts): | |
141 | self._ui.write(text, **opts) |
|
153 | self._ui.write(text, **opts) | |
|
154 | def nested(self, field): | |||
|
155 | # nested data will be directly written to ui | |||
|
156 | return self | |||
142 | def end(self): |
|
157 | def end(self): | |
143 | pass |
|
158 | pass | |
144 |
|
159 |
General Comments 0
You need to be logged in to leave comments.
Login now