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

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

Issue 2718373004: Milo: Print raw json for buildbot build properties (Closed)
Patch Set: Rebase Created 3 years, 9 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
Index: milo/appengine/common/funcs.go
diff --git a/milo/appengine/common/funcs.go b/milo/appengine/common/funcs.go
index 041ce8f9d8256473415616f5a8fc5b55eec41cb1..014af7e336d895d6c035538168e5dcbc5d52a110 100644
--- a/milo/appengine/common/funcs.go
+++ b/milo/appengine/common/funcs.go
@@ -6,6 +6,7 @@ package common
import (
"bytes"
+ "encoding/json"
"fmt"
"html/template"
"strings"
@@ -28,6 +29,7 @@ var funcMap = template.FuncMap{
"startswith": strings.HasPrefix,
"sub": sub,
"consoleHeader": consoleHeader,
+ "formatJson": formatJson,
}
// localTime returns a <span> element with t in human format
@@ -201,6 +203,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 {
+ var o interface{}
+ err := json.Unmarshal([]byte(s), &o)
nodir 2017/03/24 06:05:40 here we parse a JSON-formatted value and then cond
+ 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, "", " ")
nodir 2017/03/24 06:05:40 AFAIR last time we talked about this I asked to re
nodir 2017/03/24 08:46:06 Obviously please update the code that is currently
+ 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() {
linkifySetTemplate = template.Must(
template.New("linkifySet").

Powered by Google App Engine
This is Rietveld 408576698