Commit ab169c6e authored by Robert Griesemer's avatar Robert Griesemer

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
parent 0706d00c
...@@ -167,21 +167,27 @@ ...@@ -167,21 +167,27 @@
<th>&nbsp;&nbsp;&nbsp;&nbsp;</th> <th>&nbsp;&nbsp;&nbsp;&nbsp;</th>
<th style="text-align: left; width: auto">Synopsis</th> <th style="text-align: left; width: auto">Synopsis</th>
</tr> </tr>
{{if not $.DirFlat}}
<tr> <tr>
<td><a href="..">..</a></td> <td><a href="..">..</a></td>
</tr> </tr>
{{end}}
{{range .List}} {{range .List}}
<tr>
<td>
{{if $.DirFlat}} {{if $.DirFlat}}
<a href="{{html .Path}}">{{html .Path}}</a> {{if .HasPkg}}
{{else}} <tr>
{{repeat `&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;` .Depth}}<a href="{{html .Path}}">{{html .Name}}</a> <td><a href="{{html .Path}}">{{html .Path}}</a></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td style="width: auto">{{html .Synopsis}}</td>
</tr>
{{end}} {{end}}
</td> {{else}}
<tr>
<td>{{repeat `&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;` .Depth}}<a href="{{html .Path}}">{{html .Name}}</a></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
<td style="width: auto">{{html .Synopsis}}</td> <td style="width: auto">{{html .Synopsis}}</td>
</tr> </tr>
{{end}} {{end}}
{{end}}
</table> </table>
{{end}} {{end}}
...@@ -76,8 +76,8 @@ OTHER PACKAGES ...@@ -76,8 +76,8 @@ OTHER PACKAGES
*/}}{{with .Dirs}} */}}{{with .Dirs}}
SUBDIRECTORIES SUBDIRECTORIES
{{if $.DirFlat}}{{range .List}} {{if $.DirFlat}}{{range .List}}{{if .HasPkg}}
{{.Path}}{{end}} {{.Path}}{{end}}{{end}}
{{else}}{{range .List}} {{else}}{{range .List}}
{{repeat `. ` .Depth}}{{.Name}}{{end}} {{repeat `. ` .Depth}}{{.Name}}{{end}}
{{end}}{{end}} {{end}}{{end}}
...@@ -24,9 +24,10 @@ const testdataDirName = "testdata" ...@@ -24,9 +24,10 @@ const testdataDirName = "testdata"
type Directory struct { type Directory struct {
Depth int Depth int
Path string // includes Name Path string // directory path; includes Name
Name string Name string // directory name
Text string // package documentation, if any HasPkg bool // true if the directory contains at least one package
Synopsis string // package documentation, if any
Dirs []*Directory // subdirectories Dirs []*Directory // subdirectories
} }
...@@ -62,7 +63,11 @@ func (b *treeBuilder) newDirTree(fset *token.FileSet, path, name string, depth i ...@@ -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 // return a dummy directory so that the parent directory
// doesn't get discarded just because we reached the max // doesn't get discarded just because we reached the max
// directory depth // directory depth
return &Directory{depth, path, name, "", nil} return &Directory{
Depth: depth,
Path: path,
Name: name,
}
} }
list, err := fs.ReadDir(path) list, err := fs.ReadDir(path)
...@@ -145,7 +150,14 @@ func (b *treeBuilder) newDirTree(fset *token.FileSet, path, name string, depth i ...@@ -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 // newDirectory creates a new package directory tree with at most maxDepth
...@@ -247,9 +259,10 @@ func (dir *Directory) lookup(path string) *Directory { ...@@ -247,9 +259,10 @@ func (dir *Directory) lookup(path string) *Directory {
type DirEntry struct { type DirEntry struct {
Depth int // >= 0 Depth int // >= 0
Height int // = DirList.MaxHeight - Depth, > 0 Height int // = DirList.MaxHeight - Depth, > 0
Path string // includes Name, relative to DirList root Path string // directory path; includes Name, relative to DirList root
Name string Name string // directory name
Synopsis string HasPkg bool // true if the directory contains at least one package
Synopsis string // package documentation, if any
} }
type DirList struct { type DirList struct {
...@@ -304,7 +317,8 @@ func (root *Directory) listing(skipRoot bool) *DirList { ...@@ -304,7 +317,8 @@ func (root *Directory) listing(skipRoot bool) *DirList {
} }
p.Path = path p.Path = path
p.Name = d.Name p.Name = d.Name
p.Synopsis = d.Text p.HasPkg = d.HasPkg
p.Synopsis = d.Synopsis
i++ i++
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment