comparison mercurial/help.py @ 12820:0edc0aa7432d stable

help: add topic rewriting hooks They are useful when updating help topics dynamically from extensions.
author Patrick Mezard <pmezard@gmail.com>
date Sat, 23 Oct 2010 19:21:49 +0200
parents 019b8e1e0402
children af1006d2f970
comparison
equal deleted inserted replaced
12819:5082e2f3f8e0 12820:0edc0aa7432d
77 docdir = os.path.join(base, dir, 'help') 77 docdir = os.path.join(base, dir, 'help')
78 if os.path.isdir(docdir): 78 if os.path.isdir(docdir):
79 break 79 break
80 80
81 path = os.path.join(docdir, topic + ".txt") 81 path = os.path.join(docdir, topic + ".txt")
82 return gettext(open(path).read()) 82 doc = gettext(open(path).read())
83 for rewriter in helphooks.get(topic, []):
84 doc = rewriter(topic, doc)
85 return doc
86
83 return loader 87 return loader
84 88
85 helptable = [ 89 helptable = [
86 (["config", "hgrc"], _("Configuration Files"), loaddoc('config')), 90 (["config", "hgrc"], _("Configuration Files"), loaddoc('config')),
87 (["dates"], _("Date Formats"), loaddoc('dates')), 91 (["dates"], _("Date Formats"), loaddoc('dates')),
100 (['urls'], _('URL Paths'), loaddoc('urls')), 104 (['urls'], _('URL Paths'), loaddoc('urls')),
101 (["extensions"], _("Using additional features"), extshelp), 105 (["extensions"], _("Using additional features"), extshelp),
102 (["hgweb"], _("Configuring hgweb"), loaddoc('hgweb')), 106 (["hgweb"], _("Configuring hgweb"), loaddoc('hgweb')),
103 (["glossary"], _("Glossary"), loaddoc('glossary')), 107 (["glossary"], _("Glossary"), loaddoc('glossary')),
104 ] 108 ]
109
110 # Map topics to lists of callable taking the current topic help and
111 # returning the updated version
112 helphooks = {
113 }
114
115 def addtopichook(topic, rewriter):
116 helphooks.setdefault(topic, []).append(rewriter)