diff --git a/website/camweb.go b/website/camweb.go index e344af680..b6d88780e 100644 --- a/website/camweb.go +++ b/website/camweb.go @@ -33,6 +33,7 @@ import ( "path/filepath" "regexp" "strings" + txttemplate "text/template" "time" ) @@ -55,6 +56,7 @@ var ( buildbotBackend = flag.String("buildbot_backend", "", "Build bot status backend URL") buildbotHost = flag.String("buildbot_host", "", "Hostname to map to the buildbot_backend. If an HTTP request with this hostname is received, it proxies to buildbot_backend.") pageHtml, errorHtml *template.Template + packageHTML *txttemplate.Template ) var fmap = template.FuncMap{ @@ -158,6 +160,8 @@ func readTemplate(name string) *template.Template { func readTemplates() { pageHtml = readTemplate("page.html") errorHtml = readTemplate("error.html") + // TODO(mpl): see about not using text template anymore? + packageHTML = readTextTemplate("package.html") } func serveError(w http.ResponseWriter, r *http.Request, relpath string, err error) { @@ -270,7 +274,6 @@ func fixupGitwebFiles() { func main() { flag.Parse() - readTemplates() if *root == "" { var err error @@ -279,7 +282,7 @@ func main() { log.Fatalf("Failed to getwd: %v", err) } } - + readTemplates() fixupGitwebFiles() latestGits := filepath.Join(*root, "latestgits") diff --git a/website/godoc.go b/website/godoc.go index e791d15d7..0b8419197 100644 --- a/website/godoc.go +++ b/website/godoc.go @@ -36,7 +36,6 @@ import ( pathpkg "path" "path/filepath" "regexp" - "runtime" "strings" "text/template" "time" @@ -223,25 +222,6 @@ func srcLinkFunc(s string) string { return pathpkg.Clean(s[idx+len(domainName):]) } -var packageHTML = readGodocTemplate("package.html") - -func readGodocTemplate(name string) *template.Template { - path := runtime.GOROOT() + "/lib/godoc/" + name - - // use underlying file system fs to read the template file - // (cannot use template ParseFile functions directly) - data, err := ioutil.ReadFile(path) - if err != nil { - log.Fatal("readTemplate: ", err) - } - // be explicit with errors (for app engine use) - t, err := template.New(name).Funcs(godocFmap).Parse(string(data)) - if err != nil { - log.Fatal("readTemplate: ", err) - } - return t -} - func (pi *PageInfo) populateDirs(diskPath string, depth int) { var dir *Directory dir = newDirectory(diskPath, depth) @@ -254,6 +234,8 @@ func getPageInfo(pkgName, diskPath string) (pi PageInfo, err error) { pkgName == pathpkg.Join(domainName, cmdPattern) { pi.Dirname = diskPath pi.populateDirs(diskPath, 2) + // TODO(mpl): trim down our now local package.html to avoid that, + // among other things. // hack; setting PDoc so that we can keep using directly // $GOROOT/lib/godoc/package.html, while avoiding the // missing gopher png and the "ad" for the go dashboard. @@ -370,6 +352,19 @@ func (p *tconv) Write(data []byte) (n int, err error) { return } +func readTextTemplate(name string) *template.Template { + fileName := filepath.Join(*root, "tmpl", name) + data, err := ioutil.ReadFile(fileName) + if err != nil { + log.Fatalf("ReadFile %s: %v", fileName, err) + } + t, err := template.New(name).Funcs(godocFmap).Parse(string(data)) + if err != nil { + log.Fatalf("%s: %v", fileName, err) + } + return t +} + func applyTextTemplate(t *template.Template, name string, data interface{}) []byte { var buf bytes.Buffer if err := t.Execute(&buf, data); err != nil { diff --git a/website/tmpl/package.html b/website/tmpl/package.html new file mode 100644 index 000000000..ab9e521c3 --- /dev/null +++ b/website/tmpl/package.html @@ -0,0 +1,221 @@ + + +{{with .PDoc}} + {{if $.IsPkg}} +
+
+
import "{{html .ImportPath}}"
+
+
+
Overview
+
Index
+ {{if $.Examples}} +
Examples
+ {{end}} + {{if $.PList}} +
Other packages
+ {{end}} + {{if $.Dirs}} +
Subdirectories
+ {{end}} +
+
+ +
+ +
+

Overview ▾

+ {{comment_html .Doc}} +
+
+ {{example_html "" $.Examples $.FSet}} + +

Index

+ +
+
+ {{if .Consts}} +
Constants
+ {{end}} + {{if .Vars}} +
Variables
+ {{end}} + {{range .Funcs}} + {{$name_html := html .Name}} +
{{node_html .Decl $.FSet}}
+ {{end}} + {{range .Types}} + {{$tname_html := html .Name}} +
type {{$tname_html}}
+ {{range .Funcs}} + {{$name_html := html .Name}} +
    {{node_html .Decl $.FSet}}
+ {{end}} + {{range .Methods}} + {{$name_html := html .Name}} +
    {{node_html .Decl $.FSet}}
+ {{end}} + {{end}} + {{if .Bugs}} +
Bugs
+ {{end}} +
+ + {{if $.Examples}} +

Examples

+
+ {{range $.Examples}} +
{{example_name .Name}}
+ {{end}} +
+ {{end}} + + {{with .Filenames}} +

Package files

+

+ + {{range .}} + {{.|filename|html}} + {{end}} + +

+ {{end}} + + {{with .Consts}} +

Constants

+ {{range .}} +
{{node_html .Decl $.FSet}}
+ {{comment_html .Doc}} + {{end}} + {{end}} + {{with .Vars}} +

Variables

+ {{range .}} +
{{node_html .Decl $.FSet}}
+ {{comment_html .Doc}} + {{end}} + {{end}} + {{range .Funcs}} + {{/* Name is a string - no need for FSet */}} + {{$name_html := html .Name}} +

func {{$name_html}}

+
{{node_html .Decl $.FSet}}
+ {{comment_html .Doc}} + {{example_html .Name $.Examples $.FSet}} + {{end}} + {{range .Types}} + {{$tname := .Name}} + {{$tname_html := html .Name}} +

type {{$tname_html}}

+
{{node_html .Decl $.FSet}}
+ {{comment_html .Doc}} + + {{range .Consts}} +
{{node_html .Decl $.FSet}}
+ {{comment_html .Doc}} + {{end}} + + {{range .Vars}} +
{{node_html .Decl $.FSet}}
+ {{comment_html .Doc}} + {{end}} + + {{example_html $tname $.Examples $.FSet}} + + {{range .Funcs}} + {{$name_html := html .Name}} +

func {{$name_html}}

+
{{node_html .Decl $.FSet}}
+ {{comment_html .Doc}} + {{example_html .Name $.Examples $.FSet}} + {{end}} + + {{range .Methods}} + {{$name_html := html .Name}} +

func ({{html .Recv}}) {{$name_html}}

+
{{node_html .Decl $.FSet}}
+ {{comment_html .Doc}} + {{$name := printf "%s_%s" $tname .Name}} + {{example_html $name $.Examples $.FSet}} + {{end}} + {{end}} +
+ {{else}} {{/* not a package; is a command */}} + {{comment_html .Doc}} + {{end}} + + {{with .Bugs}} +

Bugs

+ {{range .}} + {{comment_html .}} + {{end}} + {{end}} +{{end}} + +{{with .PAst}} +
{{node_html . $.FSet}}
+{{end}} + +{{with .PList}} +

Other packages

+

+ {{/* PList entries are strings - no need for FSet */}} + {{range .}} + {{html .}}
+ {{end}} +

+{{end}} + +{{with .Dirs}} + {{/* DirList entries are numbers and strings - no need for FSet */}} + {{if $.PDoc}} +

Subdirectories

+ {{else}} +
+ +
+ {{end}} + + + + + + + {{if not $.DirFlat}} + + + + {{end}} + {{range .List}} + {{if $.DirFlat}} + {{if .HasPkg}} + + + + + + {{end}} + {{else}} + + + + + + {{end}} + {{end}} +
Name    Synopsis
..
{{html .Path}}    {{html .Synopsis}}
{{repeat `     ` .Depth}}{{html .Name}}    {{html .Synopsis}}
+ {{if $.PDoc}}{{else}} +

Need more packages? Take a look at the Go Project Dashboard.

+ {{end}} +{{end}}