changeset 6335:897f5bb96d60

fixed generated package-summary.html files to put the complete package description at the top of the page
author Doug Simon <doug.simon@oracle.com>
date Fri, 07 Sep 2012 16:55:07 +0200
parents f8ba3bb81f6f
children b4b58b810f01 464e8da34ba5
files mxtool/mx.py
diffstat 1 files changed, 104 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- 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, """<div class="header">
+<div class="subTitle">
+<div class="block">""", """</div>
+</div>
+<p>See: <a href="#overview_description">Description</a></p>
+</div>""")
+
+    chunk2 = Chunk(content, """<div class="footer"><a name="overview_description">
+<!--   -->
+</a>
+<div class="subTitle">
+<div class="block">""", """</div>
+</div>
+</div>
+<!-- ======= START OF BOTTOM NAVBAR ====== -->""")
+
+    assert chunk1.text, 'Could not find header section in ' + path
+    assert chunk2.text, 'Could not find footer section in ' + path
+
+    content = chunk1.replace(content, '<div class="header"><div class="subTitle"><div class="block">' + topLink + chunk2.text +'</div></div></div>')
+    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, """<div class="header">
+<h1 title="Package" class="title">Package""", """<p>See:&nbsp;<a href="#package_description">Description</a></p>
+</div>""")
+
+    chunk2 = Chunk(content, """<a name="package_description">
+<!--   -->
+</a>""", """</div>
+</div>
+<!-- ======= START OF BOTTOM NAVBAR ====== -->""")
+
+    if chunk1.text:
+        if chunk2.text:
+            repl = re.sub(r'<h2 title=(.*) Description</h2>', r'<h1 title=\1</h1>', chunk2.text, 1)
+            content = chunk1.replace(content, '<div class="header">' + repl +'</div></div>')
+            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, '<html><body><object data="modules.svg" type="image/svg+xml"></object></body></html>'
 
-        # 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, """<div class="header">
-<div class="subTitle">
-<div class="block">""", """</div>
-</div>
-<p>See: <a href="#overview_description">Description</a></p>
-</div>""")
-        
-            chunk2 = Chunk(content, """<div class="footer"><a name="overview_description">
-<!--   -->
-</a>
-<div class="subTitle">
-<div class="block">""", """</div>
-</div>
-</div>
-<!-- ======= START OF BOTTOM NAVBAR ====== -->""")
-        
-            assert chunk1.text, 'Could not find header section in ' + path
-            assert chunk2.text, 'Could not find footer section in ' + path
-        
-            content = chunk1.replace(content, '<div class="header"><div class="subTitle"><div class="block">' + topLink + chunk2.text +'</div></div></div>')
-            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 = '<p><a href="' + link + '", target="_top"><b>[return to the overall ' + args.name + ' documentation]</b></a></p>'
-                    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):