]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: don't show directories w/o packages in flat dir mode
authorRobert Griesemer <gri@golang.org>
Mon, 27 Feb 2012 19:18:00 +0000 (11:18 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 27 Feb 2012 19:18:00 +0000 (11:18 -0800)
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
lib/godoc/package.txt
src/cmd/godoc/dirtrees.go

index 2e1be5104a6e938c2ac75a7a014f5795639d0575..cdebd4fc4a0169a2b3eb6459b88021115114bd7b 100644 (file)
        <th>&nbsp;&nbsp;&nbsp;&nbsp;</th>
        <th style="text-align: left; width: auto">Synopsis</th>
        </tr>
-       <tr>
-       <td><a href="..">..</a></td>
-       </tr>
+       {{if not $.DirFlat}}
+               <tr>
+               <td><a href="..">..</a></td>
+               </tr>
+       {{end}}
        {{range .List}}
-       <tr>
-               <td>
                {{if $.DirFlat}}
-                       <a href="{{html .Path}}">{{html .Path}}</a>
+                       {{if .HasPkg}}
+                               <tr>
+                               <td><a href="{{html .Path}}">{{html .Path}}</a></td>
+                               <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
+                               <td style="width: auto">{{html .Synopsis}}</td>
+                               </tr>
+                       {{end}}
                {{else}}
-                       {{repeat `&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;` .Depth}}<a href="{{html .Path}}">{{html .Name}}</a>
+                       <tr>
+                       <td>{{repeat `&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;` .Depth}}<a href="{{html .Path}}">{{html .Name}}</a></td>
+                       <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
+                       <td style="width: auto">{{html .Synopsis}}</td>
+                       </tr>
                {{end}}
-               </td>
-               <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
-               <td style="width: auto">{{html .Synopsis}}</td>
-       </tr>
        {{end}}
        </table>
 {{end}}
index d88cda79fedae918bb896471c8362688223c88bd..3f3c396f0cb04832f0995dff80ace2b4cb11118f 100644 (file)
@@ -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}}
index 703c46272f4c495369f34ea7defe34f1f9018945..1acde99bd2cb850f65dcb8f2376f2f48bfaa6710 100644 (file)
@@ -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++
        }