diff --git a/app/app.yaml b/app/app.yaml index c72cd72..0824bd5 100644 --- a/app/app.yaml +++ b/app/app.yaml @@ -6,7 +6,6 @@ api_version: go1 handlers: - url: /static static_dir: static - application_readable: true - url: /digest/cron script: _go_app login: admin diff --git a/app/config/styles.json b/app/config/styles.json new file mode 100644 index 0000000..32d1a61 --- /dev/null +++ b/app/config/styles.json @@ -0,0 +1,61 @@ +{ + "digest": { + "font-family": "Helvetica, Arial, sans-serif", + "font-size": "10pt", + "color": "#000", + "max-width": "800px", + "margin": "0" + }, + "link": { + "text-decoration": "none", + "color": "#4183c4" + }, + "intro-paragraph": { + "font-size": "12pt", + "user-link": { + "font-weight": "bold", + "color": "#000" + }, + "user-avatar": { + "vertical-align": "bottom", + "padding-right": "3px" + } + }, + "interval-header": { + "font-size": "24pt", + "font-weight": "bold", + "margin": ".75em 0 .5em 0", + "border-bottom": "solid 1px #ddd" + }, + "repository-header": { + "font-size": "18pt", + "font-weight": "bold", + "margin": ".5em 0" + }, + "commit": { + "background": "#fafafa", + "border": "solid 1px #ccc", + "border-radius": "3px", + "margin": "1em 0", + "title": { + "padding": "8px", + "margin": "0" + }, + "message": { + "margin": "0", + "padding": "0 8px 8px" + }, + "footer": { + "background": "#fff", + "border-top": "solid 1px #ddd", + "padding": "8px", + "date": { + "color": "#666" + }, + "link": { + "font-family": "monospace", + "float": "right" + } + } + } +} diff --git a/app/githop.go b/app/githop.go index 96778eb..dc1d23c 100644 --- a/app/githop.go +++ b/app/githop.go @@ -74,6 +74,7 @@ func initGithubOAuthConfig() { } func initTemplates() { + styles := loadStyles() funcMap := template.FuncMap{ "routeUrl": func(name string) (string, error) { url, err := router.Get(name).URL() @@ -82,6 +83,12 @@ func initTemplates() { } return url.String(), nil }, + "style": func(names ...string) (result template.CSS) { + for _, name := range names { + result += styles[name] + } + return + }, } sharedFileNames, err := filepath.Glob("templates/shared/*.html") if err != nil { @@ -111,6 +118,39 @@ func initTemplates() { } } +func loadStyles() (result map[string]template.CSS) { + stylesBytes, err := ioutil.ReadFile("config/styles.json") + if err != nil { + log.Panicf("Could not read styles JSON: %s", err.Error()) + } + var stylesJson interface{} + err = json.Unmarshal(stylesBytes, &stylesJson) + if err != nil { + log.Panicf("Could not parse styles JSON %s: %s", stylesBytes, err.Error()) + } + result = make(map[string]template.CSS) + var parse func(string, map[string]interface{}, *string) + parse = func(path string, stylesJson map[string]interface{}, currentStyle *string) { + if path != "" { + path += "." + } + for k, v := range stylesJson { + switch v.(type) { + case string: + *currentStyle += k + ":" + v.(string) + ";" + case map[string]interface{}: + nestedStyle := "" + parse(path+k, v.(map[string]interface{}), &nestedStyle) + result[path+k] = template.CSS(nestedStyle) + default: + log.Panicf("Unexpected type for %s in styles JSON", k) + } + } + } + parse("", stylesJson.(map[string]interface{}), nil) + return +} + func signInHandler(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, githubOauthConfig.AuthCodeURL(""), http.StatusFound) } @@ -231,7 +271,6 @@ func sendDigestForAccount(account *Account, c appengine.Context) (bool, error) { } var data = map[string]interface{}{ - "Styles": getDigestStyles(), "Digest": digest, } var digestHtml bytes.Buffer @@ -265,14 +304,6 @@ func sendDigestForAccount(account *Account, c appengine.Context) (bool, error) { return true, err } -func getDigestStyles() template.CSS { - b, err := ioutil.ReadFile("static/digest.css") - if err != nil { - log.Panicf("Could not read digest CSS: %s", err.Error()) - } - return template.CSS(string(b[:])) -} - func githubOAuthCallbackHandler(w http.ResponseWriter, r *http.Request) { code := r.FormValue("code") c := appengine.NewContext(r) diff --git a/app/static/digest.css b/app/static/digest.css deleted file mode 100644 index 8c04dbe..0000000 --- a/app/static/digest.css +++ /dev/null @@ -1,83 +0,0 @@ -/* The strange format of these selectors is due to Gmail's limited CSS support --- only tag names may be used. Therefore the entire digest is in a mostly- -harmless
GitHub activity time machine for {{.User.Login}}.
+ GitHub activity time machine for
+
+ {{.User.Login}}
+ .
+
{{.Description}}
{{range .RepoDigests}} -{{.Message}}
+ {{.Message}}
{{end}}
-