Add ability to set CSS classes instead of inline styles (#103)
* Add ability to set CSS classes instead of inline styles This allows to set a `ClassName` field in `Style` structs. Setting this field to anything but "" will cause all other styles to be ignored. The element will then have a `class=` tag instead with the corresponding name. Possible reasons to use this: * Including multiple SVGs on the same webside, using the same styles * Desire to use strict CSP headers * Add warning that setting `ClassName` will drop all other inline styles
This commit is contained in:
parent
6735e8990a
commit
f97f94425f
6 changed files with 120 additions and 7 deletions
|
|
@ -71,7 +71,21 @@ func TestCanvasStyleSVG(t *testing.T) {
|
|||
|
||||
svgString := canvas.styleAsSVG(set)
|
||||
assert.NotEmpty(svgString)
|
||||
assert.True(strings.HasPrefix(svgString, "style=\""))
|
||||
assert.True(strings.Contains(svgString, "stroke:rgba(255,255,255,1.0)"))
|
||||
assert.True(strings.Contains(svgString, "stroke-width:5"))
|
||||
assert.True(strings.Contains(svgString, "fill:rgba(255,255,255,1.0)"))
|
||||
assert.True(strings.HasSuffix(svgString, "\""))
|
||||
}
|
||||
|
||||
func TestCanvasClassSVG(t *testing.T) {
|
||||
as := assert.New(t)
|
||||
|
||||
set := Style{
|
||||
ClassName: "test-class",
|
||||
}
|
||||
|
||||
canvas := &canvas{dpi: DefaultDPI}
|
||||
|
||||
as.Equal("class=\"test-class\"", canvas.styleAsSVG(set))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue