Add ability to set custom stylesheets for SVG renderer (#105)
* Add ability to set custom stylesheets for SVG renderer This allow to set custom inline CSS and a optional CSP nonce. This solves the problem mentioned in #103 and is best used with it, as seen in the added examples. Without this one would have to write a custom renderer. * Add note with link to the custom_stylesheets example
This commit is contained in:
parent
96acfc6a9f
commit
3cb33d48d3
5 changed files with 168 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package chart
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
|
@ -89,3 +90,30 @@ func TestCanvasClassSVG(t *testing.T) {
|
|||
|
||||
as.Equal("class=\"test-class\"", canvas.styleAsSVG(set))
|
||||
}
|
||||
|
||||
func TestCanvasCustomInlineStylesheet(t *testing.T) {
|
||||
b := strings.Builder{}
|
||||
|
||||
canvas := &canvas{
|
||||
w: &b,
|
||||
css: ".background { fill: red }",
|
||||
}
|
||||
|
||||
canvas.Start(200, 200)
|
||||
|
||||
assert.New(t).Contains(b.String(), fmt.Sprintf(`<style type="text/css"><![CDATA[%s]]></style>`, canvas.css))
|
||||
}
|
||||
|
||||
func TestCanvasCustomInlineStylesheetWithNonce(t *testing.T) {
|
||||
b := strings.Builder{}
|
||||
|
||||
canvas := &canvas{
|
||||
w: &b,
|
||||
css: ".background { fill: red }",
|
||||
nonce: "RAND0MSTRING",
|
||||
}
|
||||
|
||||
canvas.Start(200, 200)
|
||||
|
||||
assert.New(t).Contains(b.String(), fmt.Sprintf(`<style type="text/css" nonce="%s"><![CDATA[%s]]></style>`, canvas.nonce, canvas.css))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue