# HG changeset patch # User Patrick Mezard # Date 2011-03-12 11:46:31 # Node ID cc4721ed7a2a71b2dc6aba965aa114721932f737 # Parent ad2ee188f4a5840b21126a0d50275ed6b49a4649 help: extract items doc generation function diff --git a/mercurial/help.py b/mercurial/help.py --- a/mercurial/help.py +++ b/mercurial/help.py @@ -115,3 +115,19 @@ helphooks = { def addtopichook(topic, rewriter): helphooks.setdefault(topic, []).append(rewriter) + +def makeitemsdoc(topic, doc, marker, items): + """Extract docstring from the items key to function mapping, build a + .single documentation block and use it to overwrite the marker in doc + """ + entries = [] + for name in sorted(items): + text = (items[name].__doc__ or '').rstrip() + if not text: + continue + text = gettext(text) + lines = text.splitlines() + lines[1:] = [(' ' + l.strip()) for l in lines[1:]] + entries.append('\n'.join(lines)) + entries = '\n\n'.join(entries) + return doc.replace(marker, entries) diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -6,10 +6,10 @@ # GNU General Public License version 2 or any later version. import re -import parser, util, error, discovery +import parser, util, error, discovery, help import bookmarks as bookmarksmod import match as matchmod -from i18n import _, gettext +from i18n import _ elements = { "(": (20, ("group", 1, ")"), ("func", 1, ")")), @@ -815,19 +815,7 @@ def match(spec): return mfunc def makedoc(topic, doc): - """Generate and include predicates help in revsets topic.""" - predicates = [] - for name in sorted(symbols): - text = symbols[name].__doc__ - if not text: - continue - text = gettext(text.rstrip()) - lines = text.splitlines() - lines[1:] = [(' ' + l.strip()) for l in lines[1:]] - predicates.append('\n'.join(lines)) - predicates = '\n\n'.join(predicates) - doc = doc.replace('.. predicatesmarker', predicates) - return doc + return help.makeitemsdoc(topic, doc, '.. predicatesmarker', symbols) # tell hggettext to extract docstrings from these functions: i18nfunctions = symbols.values() diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py --- a/mercurial/templatefilters.py +++ b/mercurial/templatefilters.py @@ -6,8 +6,7 @@ # GNU General Public License version 2 or any later version. import cgi, re, os, time, urllib -import encoding, node, util -from i18n import gettext +import encoding, node, util, help def addbreaks(text): """:addbreaks: Any text. Add an XHTML "
" tag before the end of @@ -353,19 +352,7 @@ filters = { } def makedoc(topic, doc): - """Generate and include templatefilters help in templating topic.""" - entries = [] - for name in sorted(filters): - text = (filters[name].__doc__ or '').rstrip() - if not text: - continue - text = gettext(text) - lines = text.splitlines() - lines[1:] = [(' ' + l.strip()) for l in lines[1:]] - entries.append('\n'.join(lines)) - entries = '\n\n'.join(entries) - doc = doc.replace('.. filtersmarker', entries) - return doc + return help.makeitemsdoc(topic, doc, '.. filtersmarker', filters) # tell hggettext to extract docstrings from these functions: i18nfunctions = filters.values() diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -6,8 +6,7 @@ # GNU General Public License version 2 or any later version. from node import hex -import encoding, patch, util, error -from i18n import gettext +import encoding, patch, util, error, help def showlist(name, values, plural=None, **args): '''expand set of values. @@ -316,19 +315,7 @@ keywords = { } def makedoc(topic, doc): - """Generate and include keyword help in templating topic.""" - kw = [] - for name in sorted(keywords): - text = (keywords[name].__doc__ or '').rstrip() - if not text: - continue - text = gettext(text) - lines = text.splitlines() - lines[1:] = [(' ' + l.strip()) for l in lines[1:]] - kw.append('\n'.join(lines)) - kw = '\n\n'.join(kw) - doc = doc.replace('.. keywordsmarker', kw) - return doc + return help.makeitemsdoc(topic, doc, '.. keywordsmarker', keywords) # tell hggettext to extract docstrings from these functions: i18nfunctions = keywords.values()