forked from matm/gocov-html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
theme.go
92 lines (81 loc) · 2.46 KB
/
theme.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package themes
import (
"text/template"
"github.com/rotisserie/eris"
)
// Beautifier defines a theme used for rendering the HTML coverage stats.
type Beautifier interface {
// Name is the name of the theme.
Name() string
// Description is a single line comment about the theme.
Description() string
Assets() StaticAssets
// Template is the structure of the page that will be rendered.
// This code is generated by pkg/theme/generator.go.
Template() *template.Template
// PackageTemplate is the structure of the page that will be rendered.
// This code is generated by pkg/theme/generator.go.
PackageTemplate() *template.Template
// Data is the content used by the template.
// This code is generated by pkg/theme/generator.go.
Data() *templateData
}
// templateData has all the fields needed by the the HTML template for rendering.
type templateData struct {
// Command is the shell Command used to generate the HTML report.
Command string
// Style is the stylesheet content that will be embedded in the HTML page.
Style string
// Script is the javascript content that will be embedded in the HTML page.
Script string
// When is the date time of report generation.
When string
// Overview holds data used for an additional header in case of multiple Go packages
// have been analysed. Can be used for a high level summary. Is nil if the report has
// only one package.
Overview *reportPackage
// Packages is the list of all Go Packages analysed.
Packages reportPackageList
// ProjectURL is the project's site on GitHub.
ProjectURL string
}
// StaticAssets sets all assets required for a theme.
type StaticAssets struct {
Stylesheets []string
Scripts []string
Index string
}
var availableThemes = []Beautifier{
defaultTheme{},
kitTheme{},
separatePackageTheme{},
}
// Theme to use for rendering.
var curTheme Beautifier = defaultTheme{}
// List returns all available themes.
func List() []Beautifier {
return availableThemes
}
// Get a theme by name. Returns nil if none found.
func Get(name string) Beautifier {
for _, t := range availableThemes {
if t.Name() == name {
return t
}
}
return nil
}
// Use takes the name of the theme that will be used for rendering.
// Returns an error for an unknown theme.
func Use(name string) error {
p := Get(name)
if p == nil {
return eris.Errorf("unknown theme %q", name)
}
curTheme = p
return nil
}
// Current returns the theme to use for rendering HTML.
func Current() Beautifier {
return curTheme
}