Commits

bworkman  committed 874cbe1

finish support for single & multi-file

  • Participants
  • Parent commits b9043eb

Comments (0)

Files changed (1)

                 if (alt is True) :
                         row["class"] = ' class="alt"'
                 row["type"] = variable_type(item[0])
-                row["name"] = escape(item[1])
-                row["desc"] = escape(item[2])
+                row["name"] = escape_html(item[1])
+                row["desc"] = escape_html(item[2])
 
                 html += Template(tr).safe_substitute(row)
                 alt = not alt
 
         dct = dict()
 
-        d["name"] = escape(procedure.proc_name)
+        dct["name"] = escape_html(procedure.proc_name)
+        dct["authors"] = "<br>".join(map(lambda author: escape_html(author.strip()),procedure.proc_author.split(',')))
 
-        "<br>".join(map(escape_html,procedure.proc_author.split(',')))
+        dct["date"] = escape_html(procedure.proc_date)
+        dct["copyright"] = escape_html(procedure.proc_copyright)
+        dct["blurb"] = escape_html(procedure.proc_blurb)
+        dct["help"] = escape_html(procedure.proc_help)
+        dct["type"] = procedure_type(escape_html(procedure.proc_type))
 
-        d["authors"] = ""
-        authors = 
-        for author in authors :
-                d["authors"] += "%s<br>"%escape(author.strip())
-
-        d["date"] = escape(procedure.proc_date)
-        d["copyright"] = escape(procedure.proc_copyright)
-        d["blurb"] = escape(procedure.proc_blurb)
-        d["help"] = escape(procedure.proc_help)
-        d["type"] = procedure_type(escape(procedure.proc_type))
-
-        d["parameters"] = alt_table(procedure.params)
-        d["results"] = alt_table(procedure.return_vals)
-
+        dct["parameters"] = alt_table(procedure.params)
+        dct["results"] = alt_table(procedure.return_vals)
 
         return dct
 
-def link(singleFile) :
-        def link_transform(pname):
-                if(singleFile):
-                        return {"name":pname,"href":"#%s"%slugify(pname)}
-                return {"name":pname,"href":"pdb/%s.html"%slugify(pname)}
+def procedure_body(procedure):
+        return Template("""
+                <hr style="margin-bottom:0px;"/>
+                <div style="display:inline-block;">
+                        <h1>${name}</h1>
+                        <div id="author">${authors}</div>
+                </div>
+                <hr style="margin-bottom:0px;"/>
+                <p id="copyright" style="margin:0">
+                        <span class="date">${date}</span><br>
+                        ${copyright}
+                </p>
+                <h4>Description</h4>
+                <p id="description">${blurb}</p>
+                <h4>Help</h4>
+                <p id="help">${help}</p>
+                <hr />
+                <h4>Type</h4>
+                <p id="type">${type}</p>
+                <h4>Parameters</h4>
+                ${parameters}
+                <h4>Return</h4>
+                ${results}
+                <hr style="margin-bottom:0px;" />""").safe_substitute(transform(procedure))
 
-        return link_transform
+def make_linker(base="",ext=".html") :
+        def linker(pname):
+                return {"name":pname,"href":"%s%s%s"%(base, slugify(pname), ext)}
+        return linker
 
 def dump_pdb(minSize, singleFile) :
 
         index_buf += "\n\t\t</nav>\n\t\t<hr>\n"
         proc_buf = ""
 
+        if singleFile is True:
+                linker = make_linker("#","")
+        else:
+                linker = make_linker("pdb/")
+                proc_linker = make_linker()
+
         # for every namespace, create a heading, anchor and index table
         for heading in heading_list :
 
 
                 space = filter(lambda pname: pname.startswith(heading),procedure_names)
 
-                index_buf += index_table(map(link(singleFile),space))
+                index_buf += index_table(map(linker,space))
                 index_buf += '\n\t\t<nav><a href="#top">top</a></nav>\n'
 
                 # buffer procedure output for this namespace
-                for pname in space:
+                for i in range(len(space)):
 
-                        proc_buf += "<h1>%s</h1><p><h4>face-palm</h4></p>"%pname
+                        if (singleFile is True):
+                                proc_buf += Template('<a id="${anchor}"></a>').safe_substitute({"anchor":space[i]})
+                                proc_buf += procedure_body(pdb[space[i]])
 
-                        if (singleFile is not True):
-                                with open(os.path.join(root,"pdb","%s.html"%slugify(pname)), "w+") as f :
+                                tmp = linker(heading)
+                                tmp["offset"] = "\n\t\t\t"
+                                proc_buf += Template('${offset}<nav>\n${offset}\t<a href="#top" style="display:inline-block; margin-right:40px;">top</a><a href="${href}">namespace</a>\n${offset}</nav>\n').safe_substitute(tmp)
+
+                        else:
+                                tmp = "\n\t\t\t<nav>\n"
+                                if(i > 0):
+                                        tmp += Template('\t\t\t\t<a href="${href}" style="float:left;">previous</a>').safe_substitute(proc_linker(space[i-1]))
+
+                                tmp += '<a href="../index.html">index</a>'
+
+                                if(i < (len(space) - 1)):
+                                        tmp += Template('<a href="${href}" style="float:right;">next</a>').safe_substitute(proc_linker(space[i+1]))
+
+                                tmp += "\n\t\t\t</nav>\n"
+
+                                proc_buf = tmp + procedure_body(pdb[space[i]]) + tmp
+
+                                with open(os.path.join(root,"pdb","%s.html"%slugify(space[i])), "w+") as f :
                                         f.write(Template(__PROC_HTML).safe_substitute({"body":proc_buf}))
-                                        proc_buf = ""
+
+                                proc_buf = ""
+
                 # end procedure buffering
 
                 # mark all procedures in this namespace as done
-                procedure_names = filter(lambda pname: pname not in space,procedure_names)
+                procedure_names = filter(lambda pname: pname not in space, procedure_names)
         # end index buffering
 
         # write index, if not singleFile, proc_buff will be empty!
         with open(os.path.join(root,"index.html"), "w+") as f :
                 f.write(Template(__INDEX_HTML).safe_substitute({"date":now,"body":index_buf + proc_buf, "css":css}))
 
-        """
-                <nav>
-                        <a href="${prev_link}" style="float:left;">previous</a>
-                        <a href="${index_link}">index</a>
-                        <a href="${next_link}" style="float:right;">next</a>
-                </nav>
 
 
-                <hr style="margin-bottom:0px;"/>
-                <div style="display:inline-block;">
-                        <h1>
-                                ${name}
-                        </h1>
-                        <div id="author">
-                                ${authors}
-                        </div>
-                </div>
-                <hr style="margin-bottom:0px;"/>
-                <p id="copyright" style="margin:0">
-                        <span class="date">${date}</span><br>
-                        ${copyright}
-                </p>
-                <h4>Description</h4>
-                <p id="description">
-                        ${blurb}
-                </p>
-                <h4>Help</h4>
-                <p id="help">
-                        ${help}
-                </p>
-                <hr />
-                <h4>Type</h4>
-                <p id="type">
-                        ${type}
-                </p>
-                <h4>Parameters</h4>
-                ${parameters}
-                <h4>Return</h4>
-                ${results}
-                <hr style="margin-bottom:0px;" />
-
-
-
-
-
-                <nav>
-                        <a href="${prev_link}" style="float:left;">previous</a>
-                        <a href="${index_link}">index</a>
-                        <a href="${next_link}" style="float:right;">next</a>
-                </nav>
-
-        """
-
 
 
         return None
         dump_pdb
 )
 
-main()
+main()