From ab169c6e3f3acfdf9e9176968825d398820f40f1 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 27 Feb 2012 11:18:00 -0800 Subject: [PATCH] godoc: don't show directories w/o packages in flat dir mode The main change is simple: Both the Directory and DirEntry struct have an extra field 'HasPkg' indicating whether the directory contains any package files. The remaining changes are more comments and adjustments to the template files. Fixes #3121. R=golang-dev, bradfitz, sameer CC=golang-dev https://golang.org/cl/5699072 --- lib/godoc/package.html | 28 +++++++++++++++++----------- lib/godoc/package.txt | 4 ++-- src/cmd/godoc/dirtrees.go | 36 +++++++++++++++++++++++++----------- 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/lib/godoc/package.html b/lib/godoc/package.html index 2e1be5104a..cdebd4fc4a 100644 --- a/lib/godoc/package.html +++ b/lib/godoc/package.html @@ -167,21 +167,27 @@      Synopsis - - .. - + {{if not $.DirFlat}} + + .. + + {{end}} {{range .List}} - - {{if $.DirFlat}} - {{html .Path}} + {{if .HasPkg}} + + {{html .Path}} +      + {{html .Synopsis}} + + {{end}} {{else}} - {{repeat `     ` .Depth}}{{html .Name}} + + {{repeat `     ` .Depth}}{{html .Name}} +      + {{html .Synopsis}} + {{end}} - -      - {{html .Synopsis}} - {{end}} {{end}} diff --git a/lib/godoc/package.txt b/lib/godoc/package.txt index d88cda79fe..3f3c396f0c 100644 --- a/lib/godoc/package.txt +++ b/lib/godoc/package.txt @@ -76,8 +76,8 @@ OTHER PACKAGES */}}{{with .Dirs}} SUBDIRECTORIES -{{if $.DirFlat}}{{range .List}} - {{.Path}}{{end}} +{{if $.DirFlat}}{{range .List}}{{if .HasPkg}} + {{.Path}}{{end}}{{end}} {{else}}{{range .List}} {{repeat `. ` .Depth}}{{.Name}}{{end}} {{end}}{{end}} diff --git a/src/cmd/godoc/dirtrees.go b/src/cmd/godoc/dirtrees.go index 703c46272f..1acde99bd2 100644 --- a/src/cmd/godoc/dirtrees.go +++ b/src/cmd/godoc/dirtrees.go @@ -23,11 +23,12 @@ import ( const testdataDirName = "testdata" type Directory struct { - Depth int - Path string // includes Name - Name string - Text string // package documentation, if any - Dirs []*Directory // subdirectories + Depth int + Path string // directory path; includes Name + Name string // directory name + HasPkg bool // true if the directory contains at least one package + Synopsis string // package documentation, if any + Dirs []*Directory // subdirectories } func isGoFile(fi os.FileInfo) bool { @@ -62,7 +63,11 @@ func (b *treeBuilder) newDirTree(fset *token.FileSet, path, name string, depth i // return a dummy directory so that the parent directory // doesn't get discarded just because we reached the max // directory depth - return &Directory{depth, path, name, "", nil} + return &Directory{ + Depth: depth, + Path: path, + Name: name, + } } list, err := fs.ReadDir(path) @@ -145,7 +150,14 @@ func (b *treeBuilder) newDirTree(fset *token.FileSet, path, name string, depth i } } - return &Directory{depth, path, name, synopsis, dirs} + return &Directory{ + Depth: depth, + Path: path, + Name: name, + HasPkg: hasPkgFiles, + Synopsis: synopsis, + Dirs: dirs, + } } // newDirectory creates a new package directory tree with at most maxDepth @@ -247,9 +259,10 @@ func (dir *Directory) lookup(path string) *Directory { type DirEntry struct { Depth int // >= 0 Height int // = DirList.MaxHeight - Depth, > 0 - Path string // includes Name, relative to DirList root - Name string - Synopsis string + Path string // directory path; includes Name, relative to DirList root + Name string // directory name + HasPkg bool // true if the directory contains at least one package + Synopsis string // package documentation, if any } type DirList struct { @@ -304,7 +317,8 @@ func (root *Directory) listing(skipRoot bool) *DirList { } p.Path = path p.Name = d.Name - p.Synopsis = d.Text + p.HasPkg = d.HasPkg + p.Synopsis = d.Synopsis i++ } -- 2.48.1