8000 Add support for themes (#25) · matm/gocov-html@863e1bb · GitHub
[go: up one dir, main page]

Skip to content

Commit 863e1bb

Browse files
author
Mathias M
authored
Add support for themes (#25)
* Defines theming structure * Working default theme * Working fine also with multiple packages * Do not use testify lib anymore * Add -lt and -t flags Fixes #24
1 parent 99435c6 commit 863e1bb

File tree

13 files changed

+632
-435
lines changed

13 files changed

+632
-435
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
v 1.2
2+
- Add support for themes. #24
23
- Re-enable support for older Go compilers (1.11+). #29
34
- New -d flag to output CSS content used in default theme. #22
45
- Embbed custom stylesheet into final HTML document. #22

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ build:
1111
@go build -ldflags "all=$(GO_LDFLAGS)" ${MAIN_CMD}
1212

1313
test:
14-
@go test -v ./...
14+
@go test ./...
1515

1616
clean:
1717
@rm -rf ${BIN}

README.md

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Here is a screenshot:
88

99
## Installation
1010

11+
Requires Go 1.11+.
12+
1113
Just type the following to install the program and its dependencies:
1214
```
1315
$ go install github.com/axw/gocov/gocov@latest
@@ -16,21 +18,27 @@ $ go install github.com/matm/gocov-html/cmd/gocov-html@latest
1618

1719
## Features Matrix
1820

19-
Feature|Version
20-
:---|---:
21-
Use custom CSS file|`1.0`
22-
Show program version|`1.1.1`
23-
Write CSS of default theme to stdout|`1.2`
24-
Embbed custom CSS into final HTML document|`1.2`
21+
Feature|CLI Flag|Version
22+
:---|:---|---:
23+
Use custom CSS file|`-s <filename>`|`1.0`
24+
Show program version|`-v`|`1.1.1`
25+
Write CSS of default theme to stdout|`-d`|`1.2`
26+
Embbed custom CSS into final HTML document|-|`1.2`
27+
List available themes|`-lt`|`1.2`
28+
Render with a specific theme|`-t <theme>`|`1.2`
2529

2630
## Usage
2731

2832
```bash
2933
$ gocov-html -h
3034
Usage of ./gocov-html:
3135
-d output CSS of default theme
36+
-lt
37+
list available themes
3238
-s string
3339
path to custom CSS file
40+
-t string
41+
theme to use for rendering (default "golang")
3442
-v show program version
3543
```
3644

@@ -40,16 +48,36 @@ $ gocov test strings | gocov-html > strings.html
4048
ok strings 0.700s coverage: 98.1% of statements
4149
```
4250

51+
Several packages can be tested at once and added to a single report. Let's test the `fmt`, `math` and `io` packages:
52+
```
53+
$ gocov test fmt math io | gocov-html > report.html
54+
ok fmt 0.045s coverage: 95.2% of statements
55+
ok math 0.006s coverage: 83.6% of statements
56+
ok io 0.024s coverage: 88.2% of statements
57+
```
58+
59+
In this case, the generated report will have an *overview* section with stats per package along with the global coverage percentage. This section may be rendered depending on the theme used. The `golang` (default) theme displays it.
60+
4361
The generated HTML content comes along with a default embedded CSS. However a custom stylesheet can be used with the `-s` flag:
4462
```
4563
$ gocov test net/http | gocov-html -s mystyle.css > http.html
4664
```
4765

48-
As of version 1.2:
66+
As of version 1.2,
4967
- A `-d` flag is available to write the defaut stylesheet to the standard output. This is provided for convenience and easy editing:
5068
```
5169
$ gocov-html -d > newstyle.css
5270
... edit newstyle.css ...
5371
$ gocov test strings | gocov-html -s newstyle.css > http.html
5472
```
5573
- The content of the stylesheet given to `-s` is embedded into the final HTML document
74+
- Theming capabilities are available (to go further than just using a CSS file) through the use of Go templates.
75+
- Use the `-lt` flag to list available themes:
76+
```
77+
$ gocov-html -lt
78+
golang -- original golang theme (default)
79+
```
80+
- Generate a report using a specific theme with `-t`:
81+
```
82+
$ gocov test io | gocov-html -t golang > io.html
83+
```

cmd/gocov-html/main.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
"github.com/matm/gocov-html/pkg/config"
3232
"github.com/matm/gocov-html/pkg/cov"
33+
"github.com/matm/gocov-html/pkg/themes"
3334
)
3435

3536
func main() {
@@ -39,6 +40,9 @@ func main() {
3940
css := flag.String("s", "", "path to custom CSS file")
4041
showVersion := flag.Bool("v", false, "show program version")
4142
showDefaultCSS := flag.Bool("d", false, "output CSS of default theme")
43+
listThemes := flag.Bool("lt", false, "list available themes")
44+
theme := flag.String("t", "golang", "theme to use for rendering")
45+
4246
flag.Parse()
4347

4448
if *showVersion {
@@ -51,8 +55,20 @@ func main() {
5155
return
5256
}
5357

58+
if *listThemes {
59+
for _, th := range themes.List() {
60+
fmt.Printf("%-10s -- %s\n", th.Name(), th.Description())
61+
}
62+
return
63+
}
64+
65+
err := themes.Use(*theme)
66+
if err != nil {
67+
log.Fatalf("theme selection: %v", err)
68+
}
69+
5470
if *showDefaultCSS {
55-
fmt.Println(cov.DefaultCSS)
71+
fmt.Println(themes.Current().Data().CSS)
5672
return
5773
}
5874

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ go 1.11
44

55
require (
66
github.com/axw/gocov v1.1.0
7-
github.com/rotisserie/eris v0.5.4 // indirect
7+
github.com/rotisserie/eris v0.5.4
88
)

pkg/cov/annotate.go

Lines changed: 0 additions & 116 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0