mirror of
https://github.com/golang/go.git
synced 2024-09-30 06:47:04 +00:00
show subdirectories if present in a package dir
R=rsc DELTA=184 (69 added, 73 deleted, 42 changed) OCL=29178 CL=29253
This commit is contained in:
parent
54b0065777
commit
7d4765e2d3
@ -1,3 +0,0 @@
|
||||
{.repeated section @}
|
||||
<a href="{Name|html}/">{Name|html}</a><br />
|
||||
{.end}
|
@ -1,4 +0,0 @@
|
||||
Directories:
|
||||
{.repeated section @}
|
||||
{Name}
|
||||
{.end}
|
@ -86,14 +86,19 @@ func init() {
|
||||
// ----------------------------------------------------------------------------
|
||||
// Support
|
||||
|
||||
func isDir(name string) bool {
|
||||
d, err := os.Stat(name);
|
||||
return err == nil && d.IsDirectory();
|
||||
}
|
||||
|
||||
|
||||
func isGoFile(dir *os.Dir) bool {
|
||||
return dir.IsRegular() && pathutil.Ext(dir.Name) == ".go";
|
||||
}
|
||||
|
||||
|
||||
func isDir(name string) bool {
|
||||
d, err := os.Stat(name);
|
||||
return err == nil && d.IsDirectory();
|
||||
func isPkgDir(dir *os.Dir) bool {
|
||||
return dir.IsDirectory() && dir.Name != "_obj";
|
||||
}
|
||||
|
||||
|
||||
@ -287,8 +292,6 @@ func readTemplate(name string) *template.Template {
|
||||
var godocHtml *template.Template
|
||||
var packageHtml *template.Template
|
||||
var packageText *template.Template
|
||||
var dirlistHtml *template.Template;
|
||||
var dirlistText *template.Template;
|
||||
var parseerrorHtml *template.Template;
|
||||
var parseerrorText *template.Template;
|
||||
|
||||
@ -298,8 +301,6 @@ func readTemplates() {
|
||||
godocHtml = readTemplate("godoc.html");
|
||||
packageHtml = readTemplate("package.html");
|
||||
packageText = readTemplate("package.txt");
|
||||
dirlistHtml = readTemplate("dirlist.html");
|
||||
dirlistText = readTemplate("dirlist.txt");
|
||||
parseerrorHtml = readTemplate("parseerror.html");
|
||||
parseerrorText = readTemplate("parseerror.txt");
|
||||
}
|
||||
@ -463,7 +464,7 @@ func findPackage(path string) (*pakDesc, dirList) {
|
||||
panic("internal error: same file added more than once: " + entry.Name);
|
||||
}
|
||||
filenames[entry.Name] = true;
|
||||
case entry.IsDirectory():
|
||||
case isPkgDir(&entry):
|
||||
nsub++;
|
||||
}
|
||||
}
|
||||
@ -474,7 +475,7 @@ func findPackage(path string) (*pakDesc, dirList) {
|
||||
subdirs = make(dirList, nsub);
|
||||
nsub = 0;
|
||||
for i, entry := range list {
|
||||
if entry.IsDirectory() {
|
||||
if isPkgDir(&entry) {
|
||||
// make a copy here so sorting (and other code) doesn't
|
||||
// have to make one every time an entry is moved
|
||||
copy := new(os.Dir);
|
||||
@ -496,6 +497,10 @@ func findPackage(path string) (*pakDesc, dirList) {
|
||||
|
||||
|
||||
func (p *pakDesc) Doc() (*doc.PackageDoc, *parseErrors) {
|
||||
if p == nil {
|
||||
return nil, nil;
|
||||
}
|
||||
|
||||
// compute documentation
|
||||
var r doc.DocReader;
|
||||
i := 0;
|
||||
@ -511,12 +516,35 @@ func (p *pakDesc) Doc() (*doc.PackageDoc, *parseErrors) {
|
||||
i++;
|
||||
r.AddProgram(prog);
|
||||
}
|
||||
|
||||
return r.Doc(), nil;
|
||||
}
|
||||
|
||||
|
||||
func servePackage(c *http.Conn, desc *pakDesc) {
|
||||
doc, errors := desc.Doc();
|
||||
type PageInfo struct {
|
||||
PDoc *doc.PackageDoc;
|
||||
Dirs dirList;
|
||||
}
|
||||
|
||||
func servePkg(c *http.Conn, r *http.Request) {
|
||||
path := r.Url.Path;
|
||||
path = path[len(Pkg) : len(path)];
|
||||
desc, dirs := findPackage(path);
|
||||
|
||||
if path == "" {
|
||||
path = "."; // don't display an empty path
|
||||
}
|
||||
|
||||
// TODO Decide what canonical URL is (w/ or w/o trailing slash)
|
||||
// and make sure it's the one used to get to the page.
|
||||
/*
|
||||
if r.Url.Path != Pkg + info.Path {
|
||||
http.Redirect(c, info.Path, http.StatusMovedPermanently);
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
pdoc, errors := desc.Doc();
|
||||
if errors != nil {
|
||||
serveParseErrors(c, errors);
|
||||
return;
|
||||
@ -524,53 +552,19 @@ func servePackage(c *http.Conn, desc *pakDesc) {
|
||||
|
||||
var buf io.ByteBuffer;
|
||||
if false { // TODO req.Params["format"] == "text"
|
||||
err := packageText.Execute(doc, &buf);
|
||||
err := packageText.Execute(PageInfo{pdoc, dirs}, &buf);
|
||||
if err != nil {
|
||||
log.Stderrf("packageText.Execute: %s", err);
|
||||
}
|
||||
serveText(c, buf.Data());
|
||||
return;
|
||||
}
|
||||
err := packageHtml.Execute(doc, &buf);
|
||||
|
||||
err := packageHtml.Execute(PageInfo{pdoc, dirs}, &buf);
|
||||
if err != nil {
|
||||
log.Stderrf("packageHtml.Execute: %s", err);
|
||||
}
|
||||
servePage(c, doc.ImportPath + " - Go package documentation", buf.Data());
|
||||
}
|
||||
|
||||
|
||||
func serveDirList(c *http.Conn, path string, dirs dirList) {
|
||||
var buf io.ByteBuffer;
|
||||
err := dirlistHtml.Execute(dirs, &buf);
|
||||
if err != nil {
|
||||
log.Stderrf("dirlist.Execute: %s", err);
|
||||
}
|
||||
servePage(c, path + " - Directories", buf.Data());
|
||||
}
|
||||
|
||||
|
||||
func servePkg(c *http.Conn, r *http.Request) {
|
||||
path := r.Url.Path;
|
||||
path = path[len(Pkg) : len(path)];
|
||||
desc, dirs := findPackage(path);
|
||||
/*
|
||||
// TODO do we still need this?
|
||||
if r.Url.Path != Pkg + info.Path {
|
||||
http.Redirect(c, info.Path, http.StatusMovedPermanently);
|
||||
return;
|
||||
}
|
||||
*/
|
||||
if desc != nil {
|
||||
servePackage(c, desc);
|
||||
// TODO should also serve sub-directories if there are any
|
||||
} else {
|
||||
// make sure path is not empty otherwise html links become rooted
|
||||
// and won't work correctly
|
||||
if path == "" {
|
||||
path = ".";
|
||||
}
|
||||
serveDirList(c, path, dirs);
|
||||
}
|
||||
servePage(c, path + " - Go package documentation", buf.Data());
|
||||
}
|
||||
|
||||
|
||||
@ -666,20 +660,11 @@ func main() {
|
||||
|
||||
if *html {
|
||||
packageText = packageHtml;
|
||||
dirlistText = dirlistHtml;
|
||||
parseerrorText = parseerrorHtml;
|
||||
}
|
||||
|
||||
desc, dirs := findPackage(flag.Arg(0));
|
||||
if desc == nil {
|
||||
err := dirlistText.Execute(dirs, os.Stdout);
|
||||
if err != nil {
|
||||
log.Stderrf("dirlistText.Execute: %s", err);
|
||||
}
|
||||
os.Exit(0);
|
||||
}
|
||||
|
||||
doc, errors := desc.Doc();
|
||||
pdoc, errors := desc.Doc();
|
||||
if errors != nil {
|
||||
err := parseerrorText.Execute(errors, os.Stderr);
|
||||
if err != nil {
|
||||
@ -688,10 +673,10 @@ func main() {
|
||||
os.Exit(1);
|
||||
}
|
||||
|
||||
if flag.NArg() > 1 {
|
||||
if pdoc != nil && flag.NArg() > 1 {
|
||||
args := flag.Args();
|
||||
doc.Filter(args[1 : len(args)]);
|
||||
pdoc.Filter(args[1 : len(args)]);
|
||||
}
|
||||
|
||||
packageText.Execute(doc, os.Stdout);
|
||||
packageText.Execute(PageInfo{pdoc, dirs}, os.Stdout);
|
||||
}
|
||||
|
@ -1,45 +1,54 @@
|
||||
<h1>package {PackageName|html}</h1>
|
||||
<p><code>import "{ImportPath|html}"</code></p>
|
||||
{.section Dirs}
|
||||
<h2>Subdirectories</h2>
|
||||
{.repeated section @}
|
||||
<a href="{Name|html}/">{Name|html}</a><br />
|
||||
{.end}
|
||||
<hr />
|
||||
{.end}
|
||||
{.section PDoc}
|
||||
<h1>package {PackageName|html}</h1>
|
||||
<p><code>import "{ImportPath|html}"</code></p>
|
||||
|
||||
{Doc|html-comment}
|
||||
{.section Consts}
|
||||
<h2>Constants</h2>
|
||||
{.repeated section @}
|
||||
{Doc|html-comment}
|
||||
<pre>{Decl|html}</pre>
|
||||
{Doc|html-comment}
|
||||
{.section Consts}
|
||||
<h2>Constants</h2>
|
||||
{.repeated section @}
|
||||
{Doc|html-comment}
|
||||
<pre>{Decl|html}</pre>
|
||||
{.end}
|
||||
{.end}
|
||||
{.end}
|
||||
{.section Vars}
|
||||
<hr />
|
||||
<h2>Variables</h2>
|
||||
{.repeated section @}
|
||||
{Doc|html-comment}
|
||||
<pre>{Decl|html}</pre>
|
||||
{.end}
|
||||
{.end}
|
||||
{.section Funcs}
|
||||
<hr />
|
||||
{.repeated section @}
|
||||
<h2>func {Name|html}</h2>
|
||||
<p><code>{Decl|html}</code></p>
|
||||
{Doc|html-comment}
|
||||
{.end}
|
||||
{.end}
|
||||
{.section Types}
|
||||
{.repeated section @}
|
||||
{.section Vars}
|
||||
<hr />
|
||||
<h2>type {.section Type}{Name|html}{.end}</h2>
|
||||
{Doc|html-comment}
|
||||
<p><pre>{Decl|html}</pre></p>
|
||||
{.repeated section Factories}
|
||||
<h3>func {Name|html}</h3>
|
||||
<p><code>{Decl|html}</code></p>
|
||||
<h2>Variables</h2>
|
||||
{.repeated section @}
|
||||
{Doc|html-comment}
|
||||
<pre>{Decl|html}</pre>
|
||||
{.end}
|
||||
{.repeated section Methods}
|
||||
<h3>func ({Recv|html}) {Name|html}</h3>
|
||||
{.end}
|
||||
{.section Funcs}
|
||||
<hr />
|
||||
{.repeated section @}
|
||||
<h2>func {Name|html}</h2>
|
||||
<p><code>{Decl|html}</code></p>
|
||||
{Doc|html-comment}
|
||||
{.end}
|
||||
{.end}
|
||||
{.section Types}
|
||||
{.repeated section @}
|
||||
<hr />
|
||||
<h2>type {.section Type}{Name|html}{.end}</h2>
|
||||
{Doc|html-comment}
|
||||
<p><pre>{Decl|html}</pre></p>
|
||||
{.repeated section Factories}
|
||||
<h3>func {Name|html}</h3>
|
||||
<p><code>{Decl|html}</code></p>
|
||||
{Doc|html-comment}
|
||||
{.end}
|
||||
{.repeated section Methods}
|
||||
<h3>func ({Recv|html}) {Name|html}</h3>
|
||||
<p><code>{Decl|html}</code></p>
|
||||
{Doc|html-comment}
|
||||
{.end}
|
||||
{.end}
|
||||
{.end}
|
||||
{.end}
|
||||
|
@ -1,3 +1,11 @@
|
||||
{.section Dirs}
|
||||
SUBDIRECTORIES
|
||||
{.repeated section @}
|
||||
{Name}
|
||||
{.end}
|
||||
|
||||
{.end}
|
||||
{.section PDoc}
|
||||
PACKAGE
|
||||
|
||||
package {PackageName}
|
||||
@ -59,3 +67,4 @@ TYPES
|
||||
{.end}
|
||||
{.end}
|
||||
{.end}
|
||||
{.end}
|
||||
|
Loading…
Reference in New Issue
Block a user