github.com/vlifesystems/rulehunter@v0.0.0-20180501090014-673078aa4a83/html/report.go (about) 1 // Copyright (C) 2016-2017 vLife Systems Ltd <http://vlifesystems.com> 2 // Licensed under an MIT licence. Please see LICENSE.md for details. 3 4 package html 5 6 import ( 7 "html/template" 8 "path/filepath" 9 "time" 10 11 "github.com/vlifesystems/rhkit/assessment" 12 "github.com/vlifesystems/rhkit/description" 13 "github.com/vlifesystems/rulehunter/config" 14 "github.com/vlifesystems/rulehunter/report" 15 ) 16 17 func generateReport(r *report.Report, config *config.Config) (string, error) { 18 type TplData struct { 19 Mode string 20 Title string 21 Tags map[string]string 22 Category string 23 CategoryURL string 24 DateTime string 25 ExperimentFilename string 26 NumRecords int64 27 Description *description.Description 28 SortOrder []assessment.SortOrder 29 Aggregators []report.AggregatorDesc 30 Assessments []*report.Assessment 31 Html map[string]template.HTML 32 } 33 34 tplData := TplData{ 35 Mode: r.Mode.String(), 36 Title: r.Title, 37 Tags: makeTagLinks(r.Tags), 38 Category: r.Category, 39 CategoryURL: makeCategoryLink(r.Category), 40 DateTime: r.Stamp.Format(time.RFC822), 41 ExperimentFilename: r.ExperimentFilename, 42 NumRecords: r.NumRecords, 43 Description: r.Description, 44 SortOrder: r.SortOrder, 45 Aggregators: r.Aggregators, 46 Assessments: r.Assessments, 47 Html: makeHtml(config, "reports"), 48 } 49 50 reportURLDir := genReportURLDir(r.Mode, r.Category, r.Title) 51 reportFilename := genReportFilename(r.Mode, r.Category, r.Title) 52 err := writeTemplate(config, reportFilename, reportTpl, tplData) 53 return reportURLDir, err 54 } 55 56 func genReportFilename( 57 mode report.ModeKind, 58 category string, 59 title string, 60 ) string { 61 escapedTitle := escapeString(title) 62 escapedCategory := escapeString(category) 63 if category != "" { 64 return filepath.Join( 65 "reports", 66 "category", 67 escapedCategory, 68 escapedTitle, 69 mode.String(), 70 "index.html", 71 ) 72 } 73 return filepath.Join( 74 "reports", 75 "nocategory", 76 escapedTitle, 77 mode.String(), 78 "index.html", 79 ) 80 }