<th> </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> </td>
+ <td style="width: auto">{{html .Synopsis}}</td>
+ </tr>
+ {{end}}
{{else}}
- {{repeat ` ` .Depth}}<a href="{{html .Path}}">{{html .Name}}</a>
+ <tr>
+ <td>{{repeat ` ` .Depth}}<a href="{{html .Path}}">{{html .Name}}</a></td>
+ <td> </td>
+ <td style="width: auto">{{html .Synopsis}}</td>
+ </tr>
{{end}}
- </td>
- <td> </td>
- <td style="width: auto">{{html .Synopsis}}</td>
- </tr>
{{end}}
</table>
{{end}}
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 {
// 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)
}
}
- 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
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 {
}
p.Path = path
p.Name = d.Name
- p.Synopsis = d.Text
+ p.HasPkg = d.HasPkg
+ p.Synopsis = d.Synopsis
i++
}