Martin J. DÜRST
Aoyama Gakuin University
http://www.sw.it.aoyama.ac.jp/SVuGy/RubyKaigi2008Presentation.html
© 2008 Martin J. Dürst, Aoyama Gakuin University
[see Collophon for how to view best]
Ruby DSL for SVG
SVG + Ruby = SVuGy
Pronounced SVeeGee ( スゥィージー)
<rect x='100' y='200' width='50' height='30'/>
Practical: Create simple diagrams for lectures
Research: Study procedural → declarative transition (see SVGopen2007 paper)
Side-effect:
Ruby metaprogramming and DSL experience
Source for student projects
Graphics editors available, e.g. Inkscape, Adobe Illustrator,...
But:
A rectangle in SVG:
<rect x='100' y='200' width='50' height='30'/>
Wouldn't you sometimes want to write this like:
rect 100, 200, 50, 30
With SVuGy, you can!
rect 100, 200, 30, 50 circle 300, 300, 50 ellipse 400, 500, 20, 60 polygon 100, 100, 20, 100, 20, 20, 100, 20 text 'Hello SVuGy!', 50, 40
And so on...
Grouping:
g { # group content }
Anchors:
a 'IRI' { # link content }
rect
is a factory method, creates Rect
object
and adds it to parentLooking for every way to make coding shorter and easier!
Syntax variants:
rect(0, 0, 200, 200).
style(:fill => :red)
rect(0, 0, 200, 200) {
style { fill :red } }
rect(0, 0, 200, 200).
fill(:red)
rect(0, 0, 200,
200) { fill :red }
(miss?)using method_missing
#aabbcc
⇒ Haabbcc
)Example before: style(:fill => :red)
(or style(fill: :red)
for 1.9)
Example after: fill red
Before:
r = rect 100, 200, 30, 50
line r.tl, r.br
After:
rect :r 100, 200, 30, 50 line r.tl, r.br
Symbol is SVG id; scope is SVG document!
rect 100, 200, 30, 50 rect 30, 50 rect :id 100, 200, 30, 50 rect point, 30, 50 ...
Semi-manually coded, function based on class
High-end automatic solution half complete
Return value and block use depending on chaining
my_style = style(fill: :red,
stroke: :green) { }
my_group = g.style(...) { }
Ideal solution:
if method_chained? ...
(one variant)
if block_given? if @chained then @chained = false instance_eval(&block) @chained = true else warn "Block on style, ignored" end end
Composite objects introduced on a by-need base
text('sample text', 150, 250).
rotate -90, 150, 250
text('sample text',
p1=pt(150, 250)).rotate -90, p1
rotated_text 'sample text',
150, 250, -90
(one class, one method, three lines of actual code)
Please try out SVuGy and send feedback!
[if time permits]
SVuGy Home Page (http://www.sw.it.aoyama.ac.jp/SVuGy)
SVuGy - Exploring the Space between Procedural and Declarative Graphics, Martin J. Dürst, Makoto Fujimori, Takeshi Maemura, Tohru Koga, Kazunari Ito, Proc. SVG Open 2007, Tokyo, Japan, Sept. 2007. [presentation]
or how these slides were produced,
and how they are best viewed