From 911c69646d906e6216264d26a36f8ad5a257037a Mon Sep 17 00:00:00 2001 From: Cedric Staub Date: Mon, 17 Oct 2016 22:36:35 -0700 Subject: [PATCH] Add support for HTML output --- output/formatter.go | 22 ++- output/template.go | 401 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 418 insertions(+), 5 deletions(-) create mode 100644 output/template.go diff --git a/output/formatter.go b/output/formatter.go index 24c32cd..c004050 100644 --- a/output/formatter.go +++ b/output/formatter.go @@ -17,9 +17,10 @@ package output import ( "encoding/csv" "encoding/json" + htmlTemplate "html/template" "io" "strconv" - "text/template" + plainTemplate "text/template" gas "github.com/HewlettPackard/gas/core" ) @@ -54,10 +55,12 @@ func CreateReport(w io.Writer, format string, data *gas.Analyzer) error { err = reportJSON(w, data) case "csv": err = reportCSV(w, data) + case "html": + err = reportFromHTMLTemplate(w, html, data) case "text": - err = reportFromTemplate(w, text, data) + err = reportFromPlaintextTemplate(w, text, data) default: - err = reportFromTemplate(w, text, data) + err = reportFromPlaintextTemplate(w, text, data) } return err } @@ -94,8 +97,17 @@ func reportCSV(w io.Writer, data *gas.Analyzer) error { return nil } -func reportFromTemplate(w io.Writer, reportTemplate string, data *gas.Analyzer) error { - t, e := template.New("gas").Parse(reportTemplate) +func reportFromPlaintextTemplate(w io.Writer, reportTemplate string, data *gas.Analyzer) error { + t, e := plainTemplate.New("gas").Parse(reportTemplate) + if e != nil { + return e + } + + return t.Execute(w, data) +} + +func reportFromHTMLTemplate(w io.Writer, reportTemplate string, data *gas.Analyzer) error { + t, e := htmlTemplate.New("gas").Parse(reportTemplate) if e != nil { return e } diff --git a/output/template.go b/output/template.go new file mode 100644 index 0000000..f7dd236 --- /dev/null +++ b/output/template.go @@ -0,0 +1,401 @@ +// (c) Copyright 2016 Hewlett Packard Enterprise Development LP +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package output + +const html = ` + + + + + Go AST Scanner + + + + + + + +
+
+
+
+
+ + + +`