From 1087a9d8371b8da4582d2add26d9eb9f146ab4dd Mon Sep 17 00:00:00 2001 From: mpl Date: Sat, 18 Jun 2016 00:43:38 +0200 Subject: [PATCH] website: mv downloadBox to all.css Rids us of the IsMonthly hack. We still need to do something about AddTemplateTheme in handler.go though, see TODO there. In another change. Also, change servePage to take a struct for its args, more in line with Go style of few arguments. Context: issue #815 Change-Id: Ib6799be31b78af3010eee942034f2ac0e8e1d76e --- pkg/deploy/gce/handler.go | 8 ++++++-- website/camweb.go | 38 ++++++++++++++++++++++++++------------ website/contributors.go | 7 +++++-- website/godoc.go | 12 +++++++++--- website/static/all.css | 27 +++++++++++++++++++++++++++ website/tmpl/page.html | 33 --------------------------------- 6 files changed, 73 insertions(+), 52 deletions(-) diff --git a/pkg/deploy/gce/handler.go b/pkg/deploy/gce/handler.go index 6b31b49e0..259e70937 100644 --- a/pkg/deploy/gce/handler.go +++ b/pkg/deploy/gce/handler.go @@ -816,6 +816,12 @@ func dataStores() (blobserver.Storage, sorted.KeyValue, error) { return instConf, instState, nil } +// TODO(mpl): AddTemplateTheme is a mistake, since the text argument is user +// input and hence can contain just any field, that is not a known field of +// TemplateData. Which will make the execution of the template fail. We should +// probably just somehow hardcode website/tmpl/page.html as the template. +// See issue #815 + // AddTemplateTheme allows to enhance the aesthetics of the default template. To that // effect, text can provide the template definitions for "header", "banner", "toplinks", and // "footer". @@ -846,8 +852,6 @@ type TemplateData struct { ProjectConsoleURL string ZoneValues []string MachineValues []string - // TODO(mpl): Do something better than IsMonthly in camweb.go, and remove that below. - IsMonthly bool // To satisfy gross IsMonthly from website/tmpl/page.html } const toHyperlink = `$1$3` diff --git a/website/camweb.go b/website/camweb.go index 0963952df..1ddee1ac5 100644 --- a/website/camweb.go +++ b/website/camweb.go @@ -160,7 +160,14 @@ func applyTemplate(t *template.Template, name string, data interface{}) []byte { return buf.Bytes() } -func servePage(w http.ResponseWriter, title, subtitle string, content []byte) { +type pageParams struct { + title string // required + subtitle string // used by pkg doc + content []byte // required +} + +func servePage(w http.ResponseWriter, params pageParams) { + title, subtitle, content := params.title, params.subtitle, params.content // insert an "install command" if it applies if strings.Contains(title, cmdPattern) && subtitle != cmdPattern { toInsert := ` @@ -170,15 +177,13 @@ func servePage(w http.ResponseWriter, title, subtitle string, content []byte) { content = bytes.Replace(content, []byte("

"), []byte(toInsert), 1) } d := struct { - Title string - Subtitle string - Content template.HTML - IsMonthly bool + Title string + Subtitle string + Content template.HTML }{ title, subtitle, template.HTML(content), - strings.HasPrefix(title, "Monthly Release"), } if err := pageHTML.ExecuteTemplate(w, "page", &d); err != nil { @@ -210,7 +215,10 @@ func readTemplates() { func serveError(w http.ResponseWriter, r *http.Request, relpath string, err error) { contents := applyTemplate(errorHTML, "errorHTML", err) // err may contain an absolute path! w.WriteHeader(http.StatusNotFound) - servePage(w, "File "+relpath, "", contents) + servePage(w, pageParams{ + title: "File " + relpath, + content: contents, + }) } const gerritURLPrefix = "https://camlistore.googlesource.com/camlistore/+/" @@ -395,15 +403,15 @@ const ( var markdownRenderer = blackfriday.HtmlRenderer(markdownHTMLFlags, "", "") // serveFile serves a file from disk, converting any markdown to HTML. -func serveFile(rw http.ResponseWriter, req *http.Request, relPath, absPath string) { +func serveFile(w http.ResponseWriter, r *http.Request, relPath, absPath string) { if !strings.HasSuffix(absPath, ".html") && !strings.HasSuffix(absPath, ".md") { - http.ServeFile(rw, req, absPath) + http.ServeFile(w, r, absPath) return } data, err := ioutil.ReadFile(absPath) if err != nil { - serveError(rw, req, absPath, err) + serveError(w, r, absPath, err) return } @@ -414,7 +422,10 @@ func serveFile(rw http.ResponseWriter, req *http.Request, relPath, absPath strin title = string(m[1]) } - servePage(rw, title, "", data) + servePage(w, pageParams{ + title: title, + content: data, + }) } func isBot(r *http.Request) bool { @@ -1081,7 +1092,10 @@ func errHandler(w http.ResponseWriter, r *http.Request) { } contents := applyTemplate(camliErrorHTML, "camliErrorHTML", data) w.WriteHeader(http.StatusFound) - servePage(w, errString, "", contents) + servePage(w, pageParams{ + title: errString, + content: contents, + }) } func camSrcDir() string { diff --git a/website/contributors.go b/website/contributors.go index 568d51579..037db1c3d 100644 --- a/website/contributors.go +++ b/website/contributors.go @@ -186,7 +186,10 @@ func contribHandler() http.HandlerFunc { if m := h1TitlePattern.FindSubmatch(c); len(m) > 1 { title = string(m[1]) } - return func(rw http.ResponseWriter, req *http.Request) { - servePage(rw, title, "", c) + return func(w http.ResponseWriter, r *http.Request) { + servePage(w, pageParams{ + title: title, + content: c, + }) } } diff --git a/website/godoc.go b/website/godoc.go index e85f813e1..5e27f0195 100644 --- a/website/godoc.go +++ b/website/godoc.go @@ -389,8 +389,10 @@ func serveTextFile(w http.ResponseWriter, r *http.Request, abspath, relpath, tit buf.WriteString("

")
 	FormatText(&buf, src, 1, pathpkg.Ext(abspath) == ".go", r.FormValue("h"), rangeSelection(r.FormValue("s")))
 	buf.WriteString("
") - - servePage(w, title, "", buf.Bytes()) + servePage(w, pageParams{ + title: title, + content: buf.Bytes(), + }) } type godocHandler struct{} @@ -424,5 +426,9 @@ func (godocHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { subtitle := pathpkg.Base(diskPath) title := subtitle + " (" + pkgName + ")" - servePage(w, title, subtitle, applyTextTemplate(packageHTML, "packageHTML", pi)) + servePage(w, pageParams{ + title: title, + subtitle: subtitle, + content: applyTextTemplate(packageHTML, "packageHTML", pi), + }) } diff --git a/website/static/all.css b/website/static/all.css index a0d908dc7..1580b20c7 100644 --- a/website/static/all.css +++ b/website/static/all.css @@ -253,3 +253,30 @@ span.termhashlink a { .toggle .expanded { display: none; } .toggleVisible .collapsed { display: none; } .toggleVisible .expanded { display: block; } + +/* For monthly release page */ +a.downloadBox { + display: block; + color: #222; + border: 1px solid #375EAB; + border-radius: 5px; + background: #E0EBF5; + width: 280px; +} +a.downloadBox:hover { + text-decoration: none; +} +.downloadBox .platform { + font-size: large; +} +.downloadBox .filename { + color: #375EAB; + font-weight: bold; + line-height: 1.5em; +} +a.downloadBox:hover .filename { + text-decoration: underline; +} +.downloadBox .checksum { + font-size: 5pt; +} diff --git a/website/tmpl/page.html b/website/tmpl/page.html index 2cf574af4..33bca101e 100644 --- a/website/tmpl/page.html +++ b/website/tmpl/page.html @@ -27,42 +27,9 @@ -{{if .IsMonthly}} - {{template "downloadboxstyle" .}} -{{end}} {{end}} -{{define "downloadboxstyle"}} - -{{end}} - {{define "banner"}}