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 @@ + + + + + +
{{$name_html}} | ++ | {{html .Title}} | +
+
File | ++ | Bytes | ++ | Modified | +
---|---|---|---|---|
.. | +||||
{{$name_html}} | ++ | {{html .Size}} | ++ | {{fileInfoTime . | html}} | +
+{{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}}
+{{node_html $ .Decl true}}+ {{comment_html .Doc}} + {{end}} + {{end}} + {{with .Vars}} +
{{node_html $ .Decl true}}+ {{comment_html .Doc}} + {{end}} + {{end}} + {{range .Funcs}} + {{/* Name is a string - no need for FSet */}} + {{$name_html := html .Name}} +
{{node_html $ .Decl true}}+ {{comment_html .Doc}} + {{example_html $ .Name}} + {{end}} + {{range .Types}} + {{$tname := .Name}} + {{$tname_html := html .Name}} +
{{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}} +
{{node_html $ .Decl true}}+ {{comment_html .Doc}} + {{example_html $ .Name}} + {{end}} + + {{range .Methods}} + {{$name_html := html .Name}} +
{{node_html $ .Decl true}}+ {{comment_html .Doc}} + {{$name := printf "%s_%s" $tname .Name}} + {{example_html $ $name}} + {{end}} + {{end}} + {{end}} + + {{with $.Notes}} + {{range $marker, $content := .}} +
{{node_html $ . false}}+{{end}} + +{{with .Dirs}} + {{/* DirList entries are numbers and strings - no need for FSet */}} + {{if $.PDoc}} +
Name | ++ | Synopsis | +
---|---|---|
.. | +||
{{html .Path}} | ++ | {{html .Synopsis}} | +
{{repeat ` ` .Depth}}{{html .Name}} | ++ | {{html .Synopsis}} | +
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}} ++
{{$pkg_html}} |
+ | {{index . 0 | infoKind_html}} | ++ | + {{range .}} + {{infoLine .}} + {{end}} + | +
---|
+ Not all files or lines containing "{{html $.Query}}" are shown. +
+ {{end}} ++
+ {{$src_html}}: + | ++ | {{len .Lines}} | ++ | + {{range .Lines}} + {{html .}} + {{end}} + {{if not $.Complete}} + ... + {{end}} + | +
---|---|---|---|---|
... |
+ {{end}} + {{.XML}} +