[GRASS-SVN] r65855 - grass/branches/releasebranch_7_0/man

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Aug 8 03:20:29 PDT 2015


Author: neteler
Date: 2015-08-08 03:20:29 -0700 (Sat, 08 Aug 2015)
New Revision: 65855

Modified:
   grass/branches/releasebranch_7_0/man/build_keywords.py
Log:
added TOC to keywords page (trunk, r65713)

Modified: grass/branches/releasebranch_7_0/man/build_keywords.py
===================================================================
--- grass/branches/releasebranch_7_0/man/build_keywords.py	2015-08-08 10:15:13 UTC (rev 65854)
+++ grass/branches/releasebranch_7_0/man/build_keywords.py	2015-08-08 10:20:29 UTC (rev 65855)
@@ -19,6 +19,8 @@
 
 htmlfiles = glob.glob1(path, '*.html')
 
+char_list = {}
+
 for fname in htmlfiles:
     fil = open(os.path.join(path, fname))
     # TODO maybe move to Python re (regex)
@@ -40,7 +42,6 @@
             key = key.split('>')[1].split('<')[0]
         except:
             pass
-        #key = "%s%s" % (key[0].upper(), key[1:])
         if key not in keywords.keys():
             keywords[key] = []
             keywords[key].append(fname)
@@ -51,22 +52,57 @@
     try:
         del keywords[black]
     except:
-        continue
+        try:
+            del keywords[black.lower()]
+        except:
+            continue
 
+for key in sorted(keywords.keys()):
+    # this list it is useful to create the TOC using only the first
+    # character for keyword
+    firstchar = key[0].lower()
+    if firstchar not in char_list.keys():
+        char_list[str(firstchar)] = key
+    elif firstchar in char_list.keys():
+        if key.lower() < char_list[str(firstchar)].lower():
+            char_list[str(firstchar.lower())] = key
+
 keywordsfile = open(os.path.join(path, 'keywords.html'), 'w')
-keywordsfile.write(header1_tmpl.substitute(title = "GRASS GIS " \
-                        "%s Reference Manual: Keywords index" % grass_version))
+keywordsfile.write(header1_tmpl.substitute(title="GRASS GIS %s Reference "
+                                           "Manual: Keywords index" % grass_version))
 keywordsfile.write(headerkeywords_tmpl)
 keywordsfile.write('<dl>')
-for key, values in sorted(keywords.iteritems()):
-    keyword_line = '<dt><b><a name="%s" class="urlblack">%s</a></b></dt><dd>' % (key, key)
-    for value in sorted(values):
-        keyword_line += ' <a href="%s">%s</a>,' % (value, value.replace('.html',
-                                                                        ''))
+
+sortedKeys = keywords.keys()
+sortedKeys.sort(key=lambda s: s.lower())
+
+for key in sortedKeys:
+    keyword_line = '<dt><b><a name="%s" class="urlblack">%s</a></b></dt>' \
+                   '<dd>' % (key, key)
+    for value in sorted(keywords[key]):
+        keyword_line += ' <a href="%s">%s</a>,' % (value,
+                                                   value.replace('.html', ''))
     keyword_line = keyword_line.rstrip(',')
     keyword_line += '</dd>\n'
     keywordsfile.write(keyword_line)
+keywordsfile.write("</dl>\n")
+# create toc
+toc = '<div class="toc">\n<h4 class="toc">Table of contents</h4><p class="toc">'
+test_lenght = 0
+all_keys = len(char_list.keys())
+for k in sorted(char_list.keys()):
+    test_lenght += 1
+#    toc += '<li><a href="#%s" class="toc">%s</a></li>' % (char_list[k], k)
+    if test_lenght % 4 == 0 and not test_lenght == all_keys:
+        toc += '\n<a href="#%s" class="toc">%s</a>, ' % (char_list[k], k)
+    elif test_lenght % 4 == 0 and test_lenght == all_keys:
+        toc += '\n<a href="#%s" class="toc">%s</a>' % (char_list[k], k)
+    elif test_lenght == all_keys:
+        toc += '<a href="#%s" class="toc">%s</a>' % (char_list[k], k)
+    else:
+        toc += '<a href="#%s" class="toc">%s</a>, ' % (char_list[k], k)
+toc += '</p></div>\n'
+keywordsfile.write(toc)
 
-keywordsfile.write("</dl>\n")
 write_html_footer(keywordsfile, "index.html", year)
 keywordsfile.close()



More information about the grass-commit mailing list