mirror of
https://github.com/golang/go
synced 2024-11-25 06:57:58 -07:00
godoc: generate package toc in template, not in JavaScript
1. Generate TOC for package pages using template, instead of using JavaScript magic. This makes the pages generated by godoc -html easier to export to other systems. 2. Make TOC one column. It's hard to do two columns portably without invoking JavaScript. 3. Since the TOC is only one column, show full type signatures for functions and methods. Many times that's all you need to see anyway. 4. Name the section after the TOC "Overview". Naming it something is important, to set it off from the TOC and so that there's a quick link to it in the TOC. For now, some illustrative examples: http://swtch.com:6060/pkg/io/ http://swtch.com:6060/pkg/strings/ http://swtch.com:6060/pkg/tabwriter/ http://swtch.com:6060/pkg/unicode/ Fixes #1982. R=gri, bradfitz, r CC=golang-dev https://golang.org/cl/5303044
This commit is contained in:
parent
7ecf6c997e
commit
cb2f6cb05d
@ -57,6 +57,7 @@ function godocs_bindSearchEvents() {
|
|||||||
* links. "Decorates" the element with id=="nav" with this table of contents.
|
* links. "Decorates" the element with id=="nav" with this table of contents.
|
||||||
*/
|
*/
|
||||||
function godocs_generateTOC() {
|
function godocs_generateTOC() {
|
||||||
|
if (document.getElementById('manual-nav')) { return; }
|
||||||
var navbar = document.getElementById('nav');
|
var navbar = document.getElementById('nav');
|
||||||
if (!navbar) { return; }
|
if (!navbar) { return; }
|
||||||
|
|
||||||
|
@ -3,10 +3,47 @@
|
|||||||
Use of this source code is governed by a BSD-style
|
Use of this source code is governed by a BSD-style
|
||||||
license that can be found in the LICENSE file.
|
license that can be found in the LICENSE file.
|
||||||
-->
|
-->
|
||||||
|
<!-- Table of contents; must be named manual-nav to turn off auto nav. -->
|
||||||
|
<div id="manual-nav">
|
||||||
|
{{with .PDoc}}
|
||||||
|
<dl>
|
||||||
|
<dd><a href="#Overview">Overview</a></dd>
|
||||||
|
{{if .Consts}}
|
||||||
|
<dd><a href="#Constants">Constants</a></dd>
|
||||||
|
{{end}}
|
||||||
|
{{if .Vars}}
|
||||||
|
<dd><a href="#Variables">Variables</a></dd>
|
||||||
|
{{end}}
|
||||||
|
{{range .Funcs}}
|
||||||
|
{{$name_html := html .Name}}
|
||||||
|
<dd><a href="#{{$name_html}}">{{node_html .Decl $.FSet}}</a></dd>
|
||||||
|
{{end}}
|
||||||
|
{{range .Types}}
|
||||||
|
{{$tname := printf "%s" .Type.Name}}
|
||||||
|
{{$tname_html := node_html .Type.Name $.FSet}}
|
||||||
|
<dd><a href="#{{$tname_html}}">type {{$tname_html}}</a></dd>
|
||||||
|
{{range .Factories}}
|
||||||
|
{{$name_html := html .Name}}
|
||||||
|
<dd> <a href="#{{$name_html}}">{{node_html .Decl $.FSet}}</a></dd>
|
||||||
|
{{end}}
|
||||||
|
{{range .Methods}}
|
||||||
|
{{$name_html := html .Name}}
|
||||||
|
<dd> <a href="#{{$tname_html}}.{{$name_html}}">{{node_html .Decl $.FSet}}</a></dd>
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
{{if .Bugs}}
|
||||||
|
<dd><a href="#Bugs">Bugs</a></dd>
|
||||||
|
{{end}}
|
||||||
|
</dl>
|
||||||
|
{{end}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Main page -->
|
||||||
{{with .PAst}}
|
{{with .PAst}}
|
||||||
<pre>{{node_html . $.FSet}}</pre>
|
<pre>{{node_html . $.FSet}}</pre>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{with .PDoc}}
|
{{with .PDoc}}
|
||||||
|
<h2 id="Overview">Overview</h2>
|
||||||
<!-- PackageName is printed as title by the top-level template -->
|
<!-- PackageName is printed as title by the top-level template -->
|
||||||
{{if $.IsPkg}}
|
{{if $.IsPkg}}
|
||||||
<p><code>import "{{html .ImportPath}}"</code></p>
|
<p><code>import "{{html .ImportPath}}"</code></p>
|
||||||
@ -38,47 +75,43 @@
|
|||||||
<pre>{{node_html .Decl $.FSet}}</pre>
|
<pre>{{node_html .Decl $.FSet}}</pre>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{with .Funcs}}
|
{{range .Funcs}}
|
||||||
{{range .}}
|
{{/* Name is a string - no need for FSet */}}
|
||||||
{{/* Name is a string - no need for FSet */}}
|
{{$name_html := html .Name}}
|
||||||
|
<h2 id="{{$name_html}}">func <a href="/{{posLink_url .Decl $.FSet}}">{{$name_html}}</a></h2>
|
||||||
|
<p><code>{{node_html .Decl $.FSet}}</code></p>
|
||||||
|
{{comment_html .Doc}}
|
||||||
|
{{example_html .Name $.Examples $.FSet}}
|
||||||
|
{{end}}
|
||||||
|
{{range .Types}}
|
||||||
|
{{$tname := printf "%s" .Type.Name}}
|
||||||
|
{{$tname_html := node_html .Type.Name $.FSet}}
|
||||||
|
<h2 id="{{$tname_html}}">type <a href="/{{posLink_url .Decl $.FSet}}">{{$tname_html}}</a></h2>
|
||||||
|
{{comment_html .Doc}}
|
||||||
|
<p><pre>{{node_html .Decl $.FSet}}</pre></p>
|
||||||
|
{{example_html $tname $.Examples $.FSet}}
|
||||||
|
{{range .Consts}}
|
||||||
|
{{comment_html .Doc}}
|
||||||
|
<pre>{{node_html .Decl $.FSet}}</pre>
|
||||||
|
{{end}}
|
||||||
|
{{range .Vars}}
|
||||||
|
{{comment_html .Doc}}
|
||||||
|
<pre>{{node_html .Decl $.FSet}}</pre>
|
||||||
|
{{end}}
|
||||||
|
{{range .Factories}}
|
||||||
{{$name_html := html .Name}}
|
{{$name_html := html .Name}}
|
||||||
<h2 id="{{$name_html}}">func <a href="/{{posLink_url .Decl $.FSet}}">{{$name_html}}</a></h2>
|
<h3 id="{{$name_html}}">func <a href="/{{posLink_url .Decl $.FSet}}">{{$name_html}}</a></h3>
|
||||||
<p><code>{{node_html .Decl $.FSet}}</code></p>
|
<p><code>{{node_html .Decl $.FSet}}</code></p>
|
||||||
{{comment_html .Doc}}
|
{{comment_html .Doc}}
|
||||||
{{example_html .Name $.Examples $.FSet}}
|
{{example_html .Name $.Examples $.FSet}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{range .Methods}}
|
||||||
{{with .Types}}
|
{{$name_html := html .Name}}
|
||||||
{{range .}}
|
<h3 id="{{$tname_html}}.{{$name_html}}">func ({{node_html .Recv $.FSet}}) <a href="/{{posLink_url .Decl $.FSet}}">{{$name_html}}</a></h3>
|
||||||
{{$tname := printf "%s" .Type.Name}}
|
<p><code>{{node_html .Decl $.FSet}}</code></p>
|
||||||
{{$tname_html := node_html .Type.Name $.FSet}}
|
|
||||||
<h2 id="{{$tname_html}}">type <a href="/{{posLink_url .Decl $.FSet}}">{{$tname_html}}</a></h2>
|
|
||||||
{{comment_html .Doc}}
|
{{comment_html .Doc}}
|
||||||
<p><pre>{{node_html .Decl $.FSet}}</pre></p>
|
{{$name := printf "%s_%s" $tname .Name}}
|
||||||
{{example_html $tname $.Examples $.FSet}}
|
{{example_html $name $.Examples $.FSet}}
|
||||||
{{range .Consts}}
|
|
||||||
{{comment_html .Doc}}
|
|
||||||
<pre>{{node_html .Decl $.FSet}}</pre>
|
|
||||||
{{end}}
|
|
||||||
{{range .Vars}}
|
|
||||||
{{comment_html .Doc}}
|
|
||||||
<pre>{{node_html .Decl $.FSet}}</pre>
|
|
||||||
{{end}}
|
|
||||||
{{range .Factories}}
|
|
||||||
{{$name_html := html .Name}}
|
|
||||||
<h3 id="{{$name_html}}">func <a href="/{{posLink_url .Decl $.FSet}}">{{$name_html}}</a></h3>
|
|
||||||
<p><code>{{node_html .Decl $.FSet}}</code></p>
|
|
||||||
{{comment_html .Doc}}
|
|
||||||
{{example_html .Name $.Examples $.FSet}}
|
|
||||||
{{end}}
|
|
||||||
{{range .Methods}}
|
|
||||||
{{$name_html := html .Name}}
|
|
||||||
<h3 id="{{$tname_html}}.{{$name_html}}">func ({{node_html .Recv $.FSet}}) <a href="/{{posLink_url .Decl $.FSet}}">{{$name_html}}</a></h3>
|
|
||||||
<p><code>{{node_html .Decl $.FSet}}</code></p>
|
|
||||||
{{comment_html .Doc}}
|
|
||||||
{{$name := printf "%s_%s" $tname .Name}}
|
|
||||||
{{example_html $name $.Examples $.FSet}}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{with .Bugs}}
|
{{with .Bugs}}
|
||||||
|
Loading…
Reference in New Issue
Block a user