changeset 13593:cc4721ed7a2a

help: extract items doc generation function
author Patrick Mezard <pmezard@gmail.com>
date Sat, 12 Mar 2011 12:46:31 +0100
parents ad2ee188f4a5
children 241380fcc402
files mercurial/help.py mercurial/revset.py mercurial/templatefilters.py mercurial/templatekw.py
diffstat 4 files changed, 23 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/help.py	Sat Mar 12 12:46:31 2011 +0100
+++ b/mercurial/help.py	Sat Mar 12 12:46:31 2011 +0100
@@ -115,3 +115,19 @@
 
 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)
--- a/mercurial/revset.py	Sat Mar 12 12:46:31 2011 +0100
+++ b/mercurial/revset.py	Sat Mar 12 12:46:31 2011 +0100
@@ -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 @@
     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()
--- a/mercurial/templatefilters.py	Sat Mar 12 12:46:31 2011 +0100
+++ b/mercurial/templatefilters.py	Sat Mar 12 12:46:31 2011 +0100
@@ -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 "<br />" tag before the end of
@@ -353,19 +352,7 @@
 }
 
 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()
--- a/mercurial/templatekw.py	Sat Mar 12 12:46:31 2011 +0100
+++ b/mercurial/templatekw.py	Sat Mar 12 12:46:31 2011 +0100
@@ -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 @@
 }
 
 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()