Replies: 1 comment
-
Well - here also, I would consider inverting the perspective and using inheritance/composition: # Your code in a separate, testable module
module SVGUtils
def text_at_angle str, angle, r, _opts={}
# ...
end
def deg_to_rad d
# ...
end
end
# Your extended class
class SVG < Victor::SVG
include SVGUtils
end
# Or, if you prefer to create a monkey patch extension:
class Victor::SVG
include SVGUtils
end In general, I would recommend avoiding redefining Also - you cannot use both a text argument and a block to Here is a working example, achieving the basis of what you want. require 'victor'
class SVG < Victor::SVG
def blue_text(&block)
text fill_color: :blue, &block
end
end
svg = SVG.new
# Option 1: Using build
svg.build do
blue_text do
_ "hello"
tspan "cruel"
_ "world"
end
end
# Option 2: No build
svg.blue_text do
svg._ "hello"
svg.tspan "cruel"
svg._ "world"
end
puts svg.to_s output: <text fill-color="blue">
hello
<tspan>
cruel
</tspan>
world
</text> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using some custom SVG helper methods that work well, but am having trouble getting a nested tspan. Here is a simplified test example:
output is missing the tspan. Can you please tell me what am I doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions