From 9859af879bb303acfb37300e314d3057e98a5eaf Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 17 Nov 2011 14:47:49 -0800 Subject: [PATCH] godoc: provide mode for flat (non-indented) directory listings This feature should make it easier to look at very large directory trees. - a new mode (URL: /pkg/?m=flat) shows directory listings w/o indentation and entries with full path (html and text mode) - in text mode, hierarchical (non-flat) directory listings are now presented with indentation (/pkg/?m=text) - in html mode, hierarchical (non-flat) directory listings are presented with slightly less indentation - there is an internal hook for programmatic control of the display mode (for specialized versions of godoc). R=bradfitz CC=golang-dev, rsc https://golang.org/cl/5410043 --- lib/godoc/package.html | 18 +++++++++++++----- lib/godoc/package.txt | 9 +++++---- src/cmd/godoc/doc.go | 7 ++++--- src/cmd/godoc/godoc.go | 30 ++++++++++++++++++++++++++---- 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/lib/godoc/package.html b/lib/godoc/package.html index e2889f5934e..6c7be705885 100644 --- a/lib/godoc/package.html +++ b/lib/godoc/package.html @@ -141,17 +141,25 @@

- - + {{if $.DirFlat}} + + {{else}} + + {{end}} + - + {{range .List}} - {{repeat `` .Depth}} - + {{if $.DirFlat}} + + {{else}} + {{repeat `` .Depth}} + + {{end}} diff --git a/lib/godoc/package.txt b/lib/godoc/package.txt index 179b33493dd..90d1dda1030 100644 --- a/lib/godoc/package.txt +++ b/lib/godoc/package.txt @@ -76,7 +76,8 @@ OTHER PACKAGES */}}{{with .Dirs}} SUBDIRECTORIES - -{{range .List}} - {{.Name}}{{end}} -{{end}} +{{if $.DirFlat}}{{range .List}} + {{.Path}}{{end}} +{{else}}{{range .List}} + {{repeat `. ` .Depth}}{{.Name}}{{end}} +{{end}}{{end}} diff --git a/src/cmd/godoc/doc.go b/src/cmd/godoc/doc.go index 53104152d9a..acea2b5d06c 100644 --- a/src/cmd/godoc/doc.go +++ b/src/cmd/godoc/doc.go @@ -134,10 +134,11 @@ The presentation mode of web pages served by godoc can be controlled with the all show documentation for all (not just exported) declarations src show the original source code rather then the extracted documentation text present the page in textual (command-line) form rather than HTML + flat present flat (not indented) directory listings using full paths -For instance, http://golang.org/pkg/big/?m=all,text shows the documentation for -all (not just the exported) declarations of package big, in textual form (as -it would appear when using godoc from the command line: "godoc -src big .*"). +For instance, http://golang.org/pkg/math/big/?m=all,text shows the documentation +for all (not just the exported) declarations of package big, in textual form (as +it would appear when using godoc from the command line: "godoc -src math/big .*"). By default, godoc serves files from the file system of the underlying OS. Instead, a .zip file may be provided via the -zip flag, which contains diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go index 9cc0352504b..b66617431e9 100644 --- a/src/cmd/godoc/godoc.go +++ b/src/cmd/godoc/godoc.go @@ -825,6 +825,7 @@ const ( noFiltering PageInfoMode = 1 << iota // do not filter exports showSource // show source code, do not extract documentation noHtml // show result in textual form, do not generate HTML + flatDir // show directory in a flat (non-indented) manner ) // modeNames defines names for each PageInfoMode flag. @@ -832,18 +833,26 @@ var modeNames = map[string]PageInfoMode{ "all": noFiltering, "src": showSource, "text": noHtml, + "flat": flatDir, } // getPageInfoMode computes the PageInfoMode flags by analyzing the request // URL form value "m". It is value is a comma-separated list of mode names // as defined by modeNames (e.g.: m=src,text). -func getPageInfoMode(r *http.Request) (mode PageInfoMode) { +func getPageInfoMode(r *http.Request) PageInfoMode { + var mode PageInfoMode for _, k := range strings.Split(r.FormValue("m"), ",") { if m, found := modeNames[strings.TrimSpace(k)]; found { mode |= m } } - return + return adjustPageInfoMode(r, mode) +} + +// Specialized versions of godoc may adjust the PageInfoMode by overriding +// this variable. +var adjustPageInfoMode = func(_ *http.Request, mode PageInfoMode) PageInfoMode { + return mode } // remoteSearchURL returns the search URL for a given query as needed by @@ -868,8 +877,9 @@ type PageInfo struct { Examples []*doc.Example // nil if no example code Dirs *DirList // nil if no directory information DirTime int64 // directory time stamp in seconds since epoch + DirFlat bool // if set, show directory in a flat (non-indented) manner IsPkg bool // false if this is not documenting a real package - Err error // directory read error or nil + Err error // I/O error or nil } func (info *PageInfo) IsEmpty() bool { @@ -1105,7 +1115,19 @@ func (h *httpHandler) getPageInfo(abspath, relpath, pkgname string, mode PageInf timestamp = time.Seconds() } - return PageInfo{abspath, plist, fset, past, pdoc, examples, dir.listing(true), timestamp, h.isPkg, nil} + return PageInfo{ + Dirname: abspath, + PList: plist, + FSet: fset, + PAst: past, + PDoc: pdoc, + Examples: examples, + Dirs: dir.listing(true), + DirTime: timestamp, + DirFlat: mode&flatDir != 0, + IsPkg: h.isPkg, + Err: nil, + } } func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Name NameName Synopsis
....
{{html .Name}}{{html .Path}}{{html .Name}} {{html .Synopsis}}