From: Russ Cox Date: Tue, 18 Oct 2011 20:23:35 +0000 (-0400) Subject: godoc: generate package toc in template, not in JavaScript X-Git-Tag: weekly.2011-10-18~8 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=cb2f6cb05d205a6b55ac1a4055a66de4178e3d53;p=gostls13.git 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 --- diff --git a/doc/godocs.js b/doc/godocs.js index 58ce52f85d..bbf5ea2893 100644 --- a/doc/godocs.js +++ b/doc/godocs.js @@ -57,6 +57,7 @@ function godocs_bindSearchEvents() { * links. "Decorates" the element with id=="nav" with this table of contents. */ function godocs_generateTOC() { + if (document.getElementById('manual-nav')) { return; } var navbar = document.getElementById('nav'); if (!navbar) { return; } diff --git a/lib/godoc/package.html b/lib/godoc/package.html index 55812d17bc..e2889f5934 100644 --- a/lib/godoc/package.html +++ b/lib/godoc/package.html @@ -3,10 +3,47 @@ Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> + +
+{{with .PDoc}} +
+
Overview
+ {{if .Consts}} +
Constants
+ {{end}} + {{if .Vars}} +
Variables
+ {{end}} + {{range .Funcs}} + {{$name_html := html .Name}} +
{{node_html .Decl $.FSet}}
+ {{end}} + {{range .Types}} + {{$tname := printf "%s" .Type.Name}} + {{$tname_html := node_html .Type.Name $.FSet}} +
type {{$tname_html}}
+ {{range .Factories}} + {{$name_html := html .Name}} +
    {{node_html .Decl $.FSet}}
+ {{end}} + {{range .Methods}} + {{$name_html := html .Name}} +
    {{node_html .Decl $.FSet}}
+ {{end}} + {{end}} + {{if .Bugs}} +
Bugs
+ {{end}} +
+{{end}} +
+ + {{with .PAst}}
{{node_html . $.FSet}}
{{end}} {{with .PDoc}} +

Overview

{{if $.IsPkg}}

import "{{html .ImportPath}}"

@@ -38,47 +75,43 @@
{{node_html .Decl $.FSet}}
{{end}} {{end}} - {{with .Funcs}} - {{range .}} - {{/* Name is a string - no need for FSet */}} + {{range .Funcs}} + {{/* Name is a string - no need for FSet */}} + {{$name_html := html .Name}} +

func {{$name_html}}

+

{{node_html .Decl $.FSet}}

+ {{comment_html .Doc}} + {{example_html .Name $.Examples $.FSet}} + {{end}} + {{range .Types}} + {{$tname := printf "%s" .Type.Name}} + {{$tname_html := node_html .Type.Name $.FSet}} +

type {{$tname_html}}

+ {{comment_html .Doc}} +

{{node_html .Decl $.FSet}}

+ {{example_html $tname $.Examples $.FSet}} + {{range .Consts}} + {{comment_html .Doc}} +
{{node_html .Decl $.FSet}}
+ {{end}} + {{range .Vars}} + {{comment_html .Doc}} +
{{node_html .Decl $.FSet}}
+ {{end}} + {{range .Factories}} {{$name_html := html .Name}} -

func {{$name_html}}

+

func {{$name_html}}

{{node_html .Decl $.FSet}}

{{comment_html .Doc}} {{example_html .Name $.Examples $.FSet}} {{end}} - {{end}} - {{with .Types}} - {{range .}} - {{$tname := printf "%s" .Type.Name}} - {{$tname_html := node_html .Type.Name $.FSet}} -

type {{$tname_html}}

+ {{range .Methods}} + {{$name_html := html .Name}} +

func ({{node_html .Recv $.FSet}}) {{$name_html}}

+

{{node_html .Decl $.FSet}}

{{comment_html .Doc}} -

{{node_html .Decl $.FSet}}

- {{example_html $tname $.Examples $.FSet}} - {{range .Consts}} - {{comment_html .Doc}} -
{{node_html .Decl $.FSet}}
- {{end}} - {{range .Vars}} - {{comment_html .Doc}} -
{{node_html .Decl $.FSet}}
- {{end}} - {{range .Factories}} - {{$name_html := html .Name}} -

func {{$name_html}}

-

{{node_html .Decl $.FSet}}

- {{comment_html .Doc}} - {{example_html .Name $.Examples $.FSet}} - {{end}} - {{range .Methods}} - {{$name_html := html .Name}} -

func ({{node_html .Recv $.FSet}}) {{$name_html}}

-

{{node_html .Decl $.FSet}}

- {{comment_html .Doc}} - {{$name := printf "%s_%s" $tname .Name}} - {{example_html $name $.Examples $.FSet}} - {{end}} + {{$name := printf "%s_%s" $tname .Name}} + {{example_html $name $.Examples $.FSet}} {{end}} {{end}} {{with .Bugs}}