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}} +
+ +{{node_html . $.FSet}}+{{end}} + +{{with .PList}} +
+ {{/* PList entries are strings - no need for FSet */}}
+ {{range .}}
+ {{html .}}
+ {{end}}
+
Name | ++ | Synopsis | +
---|---|---|
.. | +||
{{html .Path}} | ++ | {{html .Synopsis}} | +
{{repeat ` ` .Depth}}{{html .Name}} | ++ | {{html .Synopsis}} | +
Need more packages? Take a look at the Go Project Dashboard.
+ {{end}} +{{end}}