Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1055)

Unified Diff: milo/appengine/settings/funcs.go

Issue 2718373004: Milo: Print raw json for buildbot build properties (Closed)
Patch Set: train Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « milo/appengine/frontend/templates/buildbot/pages/build.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: milo/appengine/settings/funcs.go
diff --git a/milo/appengine/settings/funcs.go b/milo/appengine/settings/funcs.go
index 822456043aa22f7735db6d43164d84c686fd91a6..e9d21e794779ea201e4bdf426a5d01c91fa93cfa 100644
--- a/milo/appengine/settings/funcs.go
+++ b/milo/appengine/settings/funcs.go
@@ -6,6 +6,7 @@ package settings
import (
"bytes"
+ "encoding/json"
"fmt"
"html/template"
"strings"
@@ -27,6 +28,7 @@ var funcMap = template.FuncMap{
"startswith": strings.HasPrefix,
"sub": sub,
"consoleHeader": consoleHeader,
+ "formatJson": formatJson,
nodir 2017/03/24 06:05:40 s/formatJson/formatJSON/g
}
// localTime returns a <span> element with t in human format
@@ -186,6 +188,30 @@ func shortHash(s string) string {
return s
}
+// If the string s is a JSON map, then pretty print it.
+func formatJson(s string) template.HTML {
nodir 2017/03/24 06:05:40 formatJSON In Go acronyms are written all caps
+ var o interface{}
+ err := json.Unmarshal([]byte(s), &o)
+ if err != nil {
+ return template.HTML(template.HTMLEscapeString(s))
+ }
+ switch t := o.(type) {
+ case string:
+ return template.HTML(template.HTMLEscapeString(t))
+ case map[string]interface{}:
+ s, err := json.MarshalIndent(t, "", " ")
+ if err == nil {
+ es := strings.Split(string(s), "\n")
+ var result string
+ for _, line := range es {
+ result += strings.Replace(template.HTMLEscapeString(line), " ", "&nbsp;", -1) + "<br>"
+ }
+ return template.HTML("<div class=\"left\">" + result + "</span>")
+ }
+ }
+ return template.HTML(template.HTMLEscapeString(s))
+}
+
func init() {
linkifyTemplate = template.Must(
template.New("linkify").
« no previous file with comments | « milo/appengine/frontend/templates/buildbot/pages/build.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698