# HG changeset patch # User Doug Simon # Date 1347029707 -7200 # Node ID 897f5bb96d607efd56dcf568d9e52bd9da284f01 # Parent f8ba3bb81f6f8da0d72742a1351f3b6d894dd647 fixed generated package-summary.html files to put the complete package description at the top of the page diff -r f8ba3bb81f6f -r 897f5bb96d60 mxtool/mx.py --- a/mxtool/mx.py Fri Sep 07 16:25:49 2012 +0200 +++ b/mxtool/mx.py Fri Sep 07 16:55:07 2012 +0200 @@ -2278,6 +2278,106 @@ list(pkgs)) log('Generated {2} for {0} in {1}'.format(', '.join(names), out, docDir)) +class Chunk: + def __init__(self, content, ldelim, rdelim=None): + lindex = content.find(ldelim) + if rdelim is not None: + rindex = content.find(rdelim) + else: + rindex = lindex + len(ldelim) + self.ldelim = ldelim + self.rdelim = rdelim + if lindex != -1 and rindex != -1 and rindex > lindex: + self.text = content[lindex + len(ldelim):rindex] + else: + self.text = None + + def replace(self, content, repl): + lindex = content.find(self.ldelim) + if self.rdelim is not None: + rindex = content.find(self.rdelim) + rdelimLen = len(self.rdelim) + else: + rindex = lindex + len(self.ldelim) + rdelimLen = 0 + old = content[lindex:rindex + rdelimLen] + return content.replace(old, repl) + +# Post-process an overview-summary.html file to move the +# complete overview to the top of the page +def _fix_overview_summary(path, topLink): + """ + Processes an "overview-summary.html" generated by javadoc to put the complete + summary text above the Packages table. + """ + + # This uses scraping and so will break if the relevant content produced by javadoc changes in any way! + with open(path) as fp: + content = fp.read() + + chunk1 = Chunk(content, """
+
+
""", """
+
+

See: Description

+
""") + + chunk2 = Chunk(content, """ +""") + + assert chunk1.text, 'Could not find header section in ' + path + assert chunk2.text, 'Could not find footer section in ' + path + + content = chunk1.replace(content, '
' + topLink + chunk2.text +'
') + content = chunk2.replace(content, '') + + with open(path, 'w') as fp: + fp.write(content) + + +# Post-process a package-summary.html file to move the +# complete package description to the top of the page +def _fix_package_summary(path): + """ + Processes an "overview-summary.html" generated by javadoc to put the complete + summary text above the Packages table. + """ + + # This uses scraping and so will break if the relevant content produced by javadoc changes in any way! + with open(path) as fp: + content = fp.read() + + chunk1 = Chunk(content, """
+

Package""", """

See: Description

+

""") + + chunk2 = Chunk(content, """ + +""", """ + +""") + + if chunk1.text: + if chunk2.text: + repl = re.sub(r'

', r'

', chunk2.text, 1) + content = chunk1.replace(content, '
' + repl +'
') + content = chunk2.replace(content, '') + + with open(path, 'w') as fp: + fp.write(content) + else: + log('warning: Could not find package description detail section in ' + path) + + else: + # no package description given + pass + def site(args): """creates a website containing javadoc and the project dependency graph""" @@ -2363,59 +2463,6 @@ with open(html, 'w') as fp: print >> fp, '' - # Post-process generated overview-summary.html files - def fix_overview_summary(path, topLink): - """ - Processes an "overview-summary.html" generated by javadoc to put the complete - summary text above the Packages table. - """ - - # This uses scraping and so will break if the relevant content produced by javadoc changes in any way! - with open(path) as fp: - content = fp.read() - - class Chunk: - def __init__(self, content, ldelim, rdelim): - lindex = content.find(ldelim) - rindex = content.find(rdelim) - self.ldelim = ldelim - self.rdelim = rdelim - if lindex != -1 and rindex != -1 and rindex > lindex: - self.text = content[lindex + len(ldelim):rindex] - else: - self.text = None - - def replace(self, content, repl): - lindex = content.find(self.ldelim) - rindex = content.find(self.rdelim) - old = content[lindex:rindex + len(self.rdelim)] - return content.replace(old, repl) - - chunk1 = Chunk(content, """
-
-
""", """
-
-

See: Description

-
""") - - chunk2 = Chunk(content, """ -""") - - assert chunk1.text, 'Could not find header section in ' + path - assert chunk2.text, 'Could not find footer section in ' + path - - content = chunk1.replace(content, '
' + topLink + chunk2.text +'
') - content = chunk2.replace(content, '') - - with open(path, 'w') as fp: - fp.write(content) - top = join(tmpbase, 'all', 'overview-summary.html') for root, _, files in os.walk(tmpbase): for f in files: @@ -2425,7 +2472,10 @@ if top != path: link = os.path.relpath(join(tmpbase, 'all', 'index.html'), dirname(path)) topLink = '

[return to the overall ' + args.name + ' documentation]

' - fix_overview_summary(path, topLink) + _fix_overview_summary(path, topLink) + elif f == 'package-summary.html': + path = join(root, f) + _fix_package_summary(path) if exists(args.base):