Closed ghost closed 7 years ago
Interesting. Can you show a use of the function?
Sure. I use it in code to embed CSS in the SVG being output:
c := svg.New(os.Stdout)
c.Start(640, 480)
c.Def()
c.Style(css) // <--------- Right here
c.DefEnd()
c.End()
where css
is some block of CSS code, maybe from an asset.
The commit message was misleading, implying that Style applies to XML Elements; it's just a way of including arbitrary CSS in the CSS definition section, a-la
<svg width="640" height="480">
<defs>
<style>
svg rect {
fill: inherit;
}
.boxybox {
fill: blue;
stroke: black;
stroke-width: 2;
}
</style>
</defs>
<rect x="100" y="70" width="100" height="70" class="boxybox"/>
</svg>
I'm wondering if we want to have another API (see the Script function):
c.Style("text/css", "/path/to/asset.css")
or
c.Style("text/css", css)
Sure, that makes sense. So the payload is either a URL or a byte array of raw CSS? And Style
would have to figure out which?
Yes, the code in Script does this.
Updated pull request such that Style() and Script() use the same code. It may have to be inlined if you decide to add tag-specific attributes, but right now the only difference in the two elements were the tag names so I have them using a helper function.
Updated with revision 19107c6 and f4dea3d
Hi,
I needed a way to add styling to elements, so I added this function. I finally got tired of the mess having a patch on your repo makes of vendoring, so am asking you to merge it upstream.
Thanks,