From 508186a7653be66b05ea9a5820a14ab55f93875c Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Thu, 1 Aug 2013 11:01:10 +1000 Subject: [PATCH] go.tools/cmd/godoc: copy templates from $GOROOT/lib/godoc R=golang-dev, r CC=golang-dev https://golang.org/cl/12209043 --- cmd/godoc/main.go | 16 +- cmd/godoc/template/codewalk.html | 56 +++++++ cmd/godoc/template/codewalkdir.html | 16 ++ cmd/godoc/template/dirlist.html | 31 ++++ cmd/godoc/template/error.html | 9 ++ cmd/godoc/template/example.html | 28 ++++ cmd/godoc/template/godoc.html | 94 ++++++++++++ cmd/godoc/template/opensearch.xml | 11 ++ cmd/godoc/template/package.html | 226 ++++++++++++++++++++++++++++ cmd/godoc/template/package.txt | 80 ++++++++++ cmd/godoc/template/search.html | 109 ++++++++++++++ cmd/godoc/template/search.txt | 47 ++++++ 12 files changed, 719 insertions(+), 4 deletions(-) create mode 100644 cmd/godoc/template/codewalk.html create mode 100644 cmd/godoc/template/codewalkdir.html create mode 100644 cmd/godoc/template/dirlist.html create mode 100644 cmd/godoc/template/error.html create mode 100644 cmd/godoc/template/example.html create mode 100644 cmd/godoc/template/godoc.html create mode 100644 cmd/godoc/template/opensearch.xml create mode 100644 cmd/godoc/template/package.html create mode 100644 cmd/godoc/template/package.txt create mode 100644 cmd/godoc/template/search.html create mode 100644 cmd/godoc/template/search.txt diff --git a/cmd/godoc/main.go b/cmd/godoc/main.go index b0f6f01a82..1593bbd624 100644 --- a/cmd/godoc/main.go +++ b/cmd/godoc/main.go @@ -53,7 +53,10 @@ import ( "code.google.com/p/go.tools/godoc/vfs/zipfs" ) -const defaultAddr = ":6060" // default webserver address +const ( + defaultAddr = ":6060" // default webserver address + templatePath = "code.google.com/p/go.tools/cmd/godoc/template" +) var ( // file system to serve @@ -187,14 +190,19 @@ func main() { } // Determine file system to use. - // TODO(gri) - fs and fsHttp should really be the same. Try to unify. - // - fsHttp doesn't need to be set up in command-line mode, - // same is true for the http handlers in initHandlers. if *zipfile == "" { // use file system of underlying OS fs.Bind("/", vfs.OS(*goroot), "/", vfs.BindReplace) if *templateDir != "" { fs.Bind("/lib/godoc", vfs.OS(*templateDir), "/", vfs.BindBefore) + } else { + // Read templates from go.tools repository; if not + // found there, fall back on $GOROOT/lib/godoc + // which will be present in binary distributions. + pkg, err := build.Import(templatePath, "", build.FindOnly) + if err == nil { + fs.Bind("/lib/godoc", vfs.OS(pkg.Dir), "/", vfs.BindReplace) + } } } else { // use file system specified via .zip file (path separator must be '/') diff --git a/cmd/godoc/template/codewalk.html b/cmd/godoc/template/codewalk.html new file mode 100644 index 0000000000..313f1f6631 --- /dev/null +++ b/cmd/godoc/template/codewalk.html @@ -0,0 +1,56 @@ + + + + + +
+
+
+
+
+ + Pop Out Code + + +
+
+ +
+
+
+ code on leftright + code width 70% + filepaths shownhidden +
+
+
+
+ {{range .Step}} +
+ +
{{html .Title}}
+
+ {{with .Err}} + ERROR LOADING FILE: {{html .}}

+ {{end}} + {{.XML}} +
+
{{html .}}
+
+ {{end}} +
+
+ previous step + • + next step +
+
+
diff --git a/cmd/godoc/template/codewalkdir.html b/cmd/godoc/template/codewalkdir.html new file mode 100644 index 0000000000..b7674c6ce9 --- /dev/null +++ b/cmd/godoc/template/codewalkdir.html @@ -0,0 +1,16 @@ + + + +{{range .}} + + {{$name_html := html .Name}} + + + + +{{end}} +
{{$name_html}} {{html .Title}}
diff --git a/cmd/godoc/template/dirlist.html b/cmd/godoc/template/dirlist.html new file mode 100644 index 0000000000..a3e1a2fa88 --- /dev/null +++ b/cmd/godoc/template/dirlist.html @@ -0,0 +1,31 @@ + + +

+ + + + + + + + + + + +{{range .}} + + {{$name_html := fileInfoName . | html}} + + + + + + +{{end}} + +
File Bytes Modified
..
{{$name_html}}{{html .Size}}{{fileInfoTime . | html}}
+

diff --git a/cmd/godoc/template/error.html b/cmd/godoc/template/error.html new file mode 100644 index 0000000000..7573aa2367 --- /dev/null +++ b/cmd/godoc/template/error.html @@ -0,0 +1,9 @@ + + +

+{{html .}} +

diff --git a/cmd/godoc/template/example.html b/cmd/godoc/template/example.html new file mode 100644 index 0000000000..cda2a8491e --- /dev/null +++ b/cmd/godoc/template/example.html @@ -0,0 +1,28 @@ +
+ +
+

Example{{example_suffix .Name}}

+ {{with .Doc}}

{{html .}}

{{end}} + {{$output := .Output}} + {{with .Play}} +
+
+
{{html $output}}
+
+ Run + Format + +
+
+ {{else}} +

Code:

+
{{.Code}}
+ {{with .Output}} +

Output:

+
{{html .}}
+ {{end}} + {{end}} +
+
diff --git a/cmd/godoc/template/godoc.html b/cmd/godoc/template/godoc.html new file mode 100644 index 0000000000..ccf5b6ed6a --- /dev/null +++ b/cmd/godoc/template/godoc.html @@ -0,0 +1,94 @@ + + + + +{{with .Tabtitle}} + {{html .}} - The Go Programming Language +{{else}} + The Go Programming Language +{{end}} + +{{if .SearchBox}} + +{{end}} + + + + +
+ +
+ + +
+ +
+ +{{if .Playground}} +
+
+
+
+ Run + Format + +
+
+{{end}} + +
+
+ +{{with .Title}} +
+

{{html .}}

+{{end}} +{{with .Subtitle}} +

{{html .}}

+{{end}} + +{{/* The Table of Contents is automatically inserted in this
. + Do not delete this
. */}} + + +{{/* Body is HTML-escaped elsewhere */}} +{{printf "%s" .Body}} + + + +
+
+ + +{{if .Playground}} + +{{end}} + + + + + diff --git a/cmd/godoc/template/opensearch.xml b/cmd/godoc/template/opensearch.xml new file mode 100644 index 0000000000..1b652db376 --- /dev/null +++ b/cmd/godoc/template/opensearch.xml @@ -0,0 +1,11 @@ + + + godoc + The Go Programming Language + go golang + + + /favicon.ico + UTF-8 + UTF-8 + diff --git a/cmd/godoc/template/package.html b/cmd/godoc/template/package.html new file mode 100644 index 0000000000..8d28652fc3 --- /dev/null +++ b/cmd/godoc/template/package.html @@ -0,0 +1,226 @@ + + +{{with .PDoc}} + {{if $.IsMain}} + {{/* command documentation */}} + {{comment_html .Doc}} + {{else}} + {{/* package documentation */}} +
+
+
import "{{html .ImportPath}}"
+
+
+
Overview
+
Index
+ {{if $.Examples}} +
Examples
+ {{end}} + {{if $.Dirs}} +
Subdirectories
+ {{end}} +
+
+ +
+ +
+

Overview ▾

+ {{comment_html .Doc}} +
+
+ {{example_html $ ""}} + +
+ +
+

Index ▾

+ + +
+
+ {{if .Consts}} +
Constants
+ {{end}} + {{if .Vars}} +
Variables
+ {{end}} + {{range .Funcs}} + {{$name_html := html .Name}} +
{{node_html $ .Decl false}}
+ {{end}} + {{range .Types}} + {{$tname_html := html .Name}} +
type {{$tname_html}}
+ {{range .Funcs}} + {{$name_html := html .Name}} +
    {{node_html $ .Decl false}}
+ {{end}} + {{range .Methods}} + {{$name_html := html .Name}} +
    {{node_html $ .Decl false}}
+ {{end}} + {{end}} + {{if $.Notes}} + {{range $marker, $item := $.Notes}} +
{{noteTitle $marker | html}}s
+ {{end}} + {{end}} +
+
+ + {{if $.Examples}} +
+

Examples

+
+ {{range $.Examples}} +
{{example_name .Name}}
+ {{end}} +
+
+ {{end}} + + {{with .Filenames}} +

Package files

+

+ + {{range .}} + {{.|filename|html}} + {{end}} + +

+ {{end}} +
+
+ + {{with .Consts}} +

Constants

+ {{range .}} +
{{node_html $ .Decl true}}
+ {{comment_html .Doc}} + {{end}} + {{end}} + {{with .Vars}} +

Variables

+ {{range .}} +
{{node_html $ .Decl true}}
+ {{comment_html .Doc}} + {{end}} + {{end}} + {{range .Funcs}} + {{/* Name is a string - no need for FSet */}} + {{$name_html := html .Name}} +

func {{$name_html}}

+
{{node_html $ .Decl true}}
+ {{comment_html .Doc}} + {{example_html $ .Name}} + {{end}} + {{range .Types}} + {{$tname := .Name}} + {{$tname_html := html .Name}} +

type {{$tname_html}}

+
{{node_html $ .Decl true}}
+ {{comment_html .Doc}} + + {{range .Consts}} +
{{node_html $ .Decl true}}
+ {{comment_html .Doc}} + {{end}} + + {{range .Vars}} +
{{node_html $ .Decl true}}
+ {{comment_html .Doc}} + {{end}} + + {{example_html $ $tname}} + + {{range .Funcs}} + {{$name_html := html .Name}} +

func {{$name_html}}

+
{{node_html $ .Decl true}}
+ {{comment_html .Doc}} + {{example_html $ .Name}} + {{end}} + + {{range .Methods}} + {{$name_html := html .Name}} +

func ({{html .Recv}}) {{$name_html}}

+
{{node_html $ .Decl true}}
+ {{comment_html .Doc}} + {{$name := printf "%s_%s" $tname .Name}} + {{example_html $ $name}} + {{end}} + {{end}} + {{end}} + + {{with $.Notes}} + {{range $marker, $content := .}} +

{{noteTitle $marker | html}}s

+
    + {{range .}} +
  • {{html .Body}}
  • + {{end}} +
+ {{end}} + {{end}} +{{end}} + +{{with .PAst}} +
{{node_html $ . false}}
+{{end}} + +{{with .Dirs}} + {{/* DirList entries are numbers and strings - no need for FSet */}} + {{if $.PDoc}} +

Subdirectories

+ {{else}} +
+ +
+ {{end}} + + + + + + + {{if not $.DirFlat}} + + + + {{end}} + {{range .List}} + {{if $.DirFlat}} + {{if .HasPkg}} + + + + + + {{end}} + {{else}} + + + + + + {{end}} + {{end}} +
Name    Synopsis
..
{{html .Path}}    {{html .Synopsis}}
{{repeat `     ` .Depth}}{{html .Name}}    {{html .Synopsis}}
+ {{if $.PDoc}}{{else}} +

Need more packages? Take a look at the Go Projects wiki page.

+ {{end}} +{{end}} diff --git a/cmd/godoc/template/package.txt b/cmd/godoc/template/package.txt new file mode 100644 index 0000000000..d191621c00 --- /dev/null +++ b/cmd/godoc/template/package.txt @@ -0,0 +1,80 @@ +{{with .PAst}}{{node $ .}}{{end}}{{/* + +--------------------------------------- + +*/}}{{with .PDoc}}{{if $.IsMain}}COMMAND DOCUMENTATION + +{{comment_text .Doc " " "\t"}} +{{else}}PACKAGE DOCUMENTATION + +package {{.Name}} + import "{{.ImportPath}}" + +{{comment_text .Doc " " "\t"}} +{{example_text $ "" " "}}{{/* + +--------------------------------------- + +*/}}{{with .Consts}} +CONSTANTS + +{{range .}}{{node $ .Decl}} +{{comment_text .Doc " " "\t"}} +{{end}}{{end}}{{/* + +--------------------------------------- + +*/}}{{with .Vars}} +VARIABLES + +{{range .}}{{node $ .Decl}} +{{comment_text .Doc " " "\t"}} +{{end}}{{end}}{{/* + +--------------------------------------- + +*/}}{{with .Funcs}} +FUNCTIONS + +{{range .}}{{node $ .Decl}} +{{comment_text .Doc " " "\t"}} +{{example_text $ .Name " "}}{{end}}{{end}}{{/* + +--------------------------------------- + +*/}}{{with .Types}} +TYPES + +{{range .}}{{$tname := .Name}}{{node $ .Decl}} +{{comment_text .Doc " " "\t"}} +{{range .Consts}}{{node $ .Decl}} +{{comment_text .Doc " " "\t"}} +{{end}}{{range .Vars}}{{node $ .Decl}} +{{comment_text .Doc " " "\t"}} +{{end}}{{example_text $ .Name " "}} +{{range .Funcs}}{{node $ .Decl}} +{{comment_text .Doc " " "\t"}} +{{example_text $ .Name " "}} +{{end}}{{range .Methods}}{{node $ .Decl}} +{{comment_text .Doc " " "\t"}} +{{$name := printf "%s_%s" $tname .Name}}{{example_text $ $name " "}}{{end}} +{{end}}{{end}}{{end}}{{/* + +--------------------------------------- + +*/}}{{with $.Notes}} +{{range $marker, $content := .}} +{{$marker}}S + +{{range $content}}{{comment_text .Body " " "\t"}} +{{end}}{{end}}{{end}}{{end}}{{/* + +--------------------------------------- + +*/}}{{with .Dirs}} +SUBDIRECTORIES +{{if $.DirFlat}}{{range .List}}{{if .HasPkg}} + {{.Path}}{{end}}{{end}} +{{else}}{{range .List}} + {{repeat `. ` .Depth}}{{.Name}}{{end}} +{{end}}{{end}} diff --git a/cmd/godoc/template/search.html b/cmd/godoc/template/search.html new file mode 100644 index 0000000000..5b54d71267 --- /dev/null +++ b/cmd/godoc/template/search.html @@ -0,0 +1,109 @@ + +{{$query_url := urlquery .Query}} +{{with .Alert}} +

+ {{html .}} +

+{{end}} +{{with .Alt}} +

+ Did you mean: + {{range .Alts}} + {{html .}} + {{end}} +

+{{end}} +{{with .Pak}} +

Package {{html $.Query}}

+

+ + {{range .}} + {{$pkg_html := pkgLink .Pak.Path | html}} + + {{end}} +
{{$pkg_html}}
+

+{{end}} +{{with .Hit}} + {{with .Decls}} +

Package-level declarations

+ {{range .}} + {{$pkg_html := pkgLink .Pak.Path | html}} +

package {{html .Pak.Name}}

+ {{range .Files}} + {{$src_html := srcLink .File.Path | html}} + {{range .Groups}} + {{range .}} + {{$src_html}}:{{infoLine .}} + {{infoSnippet_html .}} + {{end}} + {{end}} + {{end}} + {{end}} + {{end}} + {{with .Others}} +

Local declarations and uses

+ {{range .}} + {{$pkg_html := pkgLink .Pak.Path | html}} +

package {{html .Pak.Name}}

+ {{range .Files}} + {{$src_html := srcLink .File.Path | html}} + {{$src_html}} + + {{range .Groups}} + + + + + + + {{end}} +
{{index . 0 | infoKind_html}} + {{range .}} + {{infoLine .}} + {{end}} +
+ {{end}} + {{end}} + {{end}} +{{end}} +{{with .Textual}} + {{if $.Complete}} +

{{html $.Found}} textual occurrences

+ {{else}} +

More than {{html $.Found}} textual occurrences

+

+ Not all files or lines containing "{{html $.Query}}" are shown. +

+ {{end}} +

+ + {{range .}} + {{$src_html := srcLink .Filename | html}} + + + + + + + + {{end}} + {{if not $.Complete}} + + {{end}} +
+ {{$src_html}}: + {{len .Lines}} + {{range .Lines}} + {{html .}} + {{end}} + {{if not $.Complete}} + ... + {{end}} +
...
+

+{{end}} diff --git a/cmd/godoc/template/search.txt b/cmd/godoc/template/search.txt new file mode 100644 index 0000000000..5251a388e0 --- /dev/null +++ b/cmd/godoc/template/search.txt @@ -0,0 +1,47 @@ +QUERY + {{.Query}} + +{{with .Alert}}{{.}} +{{end}}{{/* .Alert */}}{{/* + +--------------------------------------- + +*/}}{{with .Alt}}DID YOU MEAN + +{{range .Alts}} {{.}} +{{end}} +{{end}}{{/* .Alt */}}{{/* + +--------------------------------------- + +*/}}{{with .Pak}}PACKAGE {{$.Query}} + +{{range .}} {{pkgLink .Pak.Path}} +{{end}} +{{end}}{{/* .Pak */}}{{/* + +--------------------------------------- + +*/}}{{with .Hit}}{{with .Decls}}PACKAGE-LEVEL DECLARATIONS + +{{range .}}package {{.Pak.Name}} +{{range $file := .Files}}{{range .Groups}}{{range .}} {{srcLink $file.File.Path}}:{{infoLine .}}{{end}} +{{end}}{{end}}{{/* .Files */}} +{{end}}{{end}}{{/* .Decls */}}{{/* + +--------------------------------------- + +*/}}{{with .Others}}LOCAL DECLARATIONS AND USES + +{{range .}}package {{.Pak.Name}} +{{range $file := .Files}}{{range .Groups}}{{range .}} {{srcLink $file.File.Path}}:{{infoLine .}} +{{end}}{{end}}{{end}}{{/* .Files */}} +{{end}}{{end}}{{/* .Others */}}{{end}}{{/* .Hit */}}{{/* + +--------------------------------------- + +*/}}{{if .Textual}}{{if .Complete}}{{.Found}} TEXTUAL OCCURRENCES{{else}}MORE THAN {{.Found}} TEXTUAL OCCURRENCES{{end}} + +{{range .Textual}}{{len .Lines}} {{srcLink .Filename}} +{{end}}{{if not .Complete}}... ... +{{end}}{{end}}