Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/help.py @ 26414:c44b507e7c78
help: pass around ui to rewriter hooks (API)
makeitemsdoc() will hide DEPRECATED items conditionally.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 26 Sep 2015 12:11:46 +0900 |
parents | e0c572d4d112 |
children | 46af0adb5c37 |
comparison
equal
deleted
inserted
replaced
26413:e0c572d4d112 | 26414:c44b507e7c78 |
---|---|
142 def loader(ui): | 142 def loader(ui): |
143 docdir = os.path.join(util.datapath, 'help') | 143 docdir = os.path.join(util.datapath, 'help') |
144 path = os.path.join(docdir, topic + ".txt") | 144 path = os.path.join(docdir, topic + ".txt") |
145 doc = gettext(util.readfile(path)) | 145 doc = gettext(util.readfile(path)) |
146 for rewriter in helphooks.get(topic, []): | 146 for rewriter in helphooks.get(topic, []): |
147 doc = rewriter(topic, doc) | 147 doc = rewriter(ui, topic, doc) |
148 return doc | 148 return doc |
149 | 149 |
150 return loader | 150 return loader |
151 | 151 |
152 helptable = sorted([ | 152 helptable = sorted([ |
182 helphooks = {} | 182 helphooks = {} |
183 | 183 |
184 def addtopichook(topic, rewriter): | 184 def addtopichook(topic, rewriter): |
185 helphooks.setdefault(topic, []).append(rewriter) | 185 helphooks.setdefault(topic, []).append(rewriter) |
186 | 186 |
187 def makeitemsdoc(topic, doc, marker, items, dedent=False): | 187 def makeitemsdoc(ui, topic, doc, marker, items, dedent=False): |
188 """Extract docstring from the items key to function mapping, build a | 188 """Extract docstring from the items key to function mapping, build a |
189 single documentation block and use it to overwrite the marker in doc. | 189 single documentation block and use it to overwrite the marker in doc. |
190 """ | 190 """ |
191 entries = [] | 191 entries = [] |
192 for name in sorted(items): | 192 for name in sorted(items): |
209 entries.append('\n'.join(doclines)) | 209 entries.append('\n'.join(doclines)) |
210 entries = '\n\n'.join(entries) | 210 entries = '\n\n'.join(entries) |
211 return doc.replace(marker, entries) | 211 return doc.replace(marker, entries) |
212 | 212 |
213 def addtopicsymbols(topic, marker, symbols, dedent=False): | 213 def addtopicsymbols(topic, marker, symbols, dedent=False): |
214 def add(topic, doc): | 214 def add(ui, topic, doc): |
215 return makeitemsdoc(topic, doc, marker, symbols, dedent=dedent) | 215 return makeitemsdoc(ui, topic, doc, marker, symbols, dedent=dedent) |
216 addtopichook(topic, add) | 216 addtopichook(topic, add) |
217 | 217 |
218 addtopicsymbols('filesets', '.. predicatesmarker', fileset.symbols) | 218 addtopicsymbols('filesets', '.. predicatesmarker', fileset.symbols) |
219 addtopicsymbols('merge-tools', '.. internaltoolsmarker', | 219 addtopicsymbols('merge-tools', '.. internaltoolsmarker', |
220 filemerge.internalsdoc) | 220 filemerge.internalsdoc) |