Skip to content

Commit a360e45

Browse files
author
Jonathan Slate
committed
adding transforms to groups, getting specs to run
1 parent 764ef82 commit a360e45

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

Gemfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ source "http://rubygems.org"
66
# Add dependencies to develop your gem here.
77
# Include everything needed to run rake, tests, features, etc.
88
group :development do
9-
gem "rspec", "~> 2.3.0"
10-
gem "bundler", "~> 1.0.0"
11-
gem "jeweler", "~> 1.5.2"
12-
gem "rcov", ">= 0"
9+
gem "rspec", "~> 2.10.0"
10+
gem "jeweler", "~> 1.8.2"
11+
gem "simplecov", "~> 0.6.4"
1312
end

lib/rasem/svg_image.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ def with_style(style={}, &proc)
118118
@default_styles.pop
119119
end
120120

121-
def group(style={}, &proc)
121+
def group(style={}, transforms={}, &proc)
122122
# Open the group
123123
@output << "<g"
124124
write_style(style)
125+
write_transforms(transforms)
125126
@output << ">"
126127
# Call the block
127128
self.instance_exec(&proc)
@@ -224,5 +225,17 @@ def write_style(style)
224225
end
225226
@output << '"'
226227
end
228+
229+
def write_transforms(transforms)
230+
return if transforms.empty?
231+
@output << ' transform="'
232+
transforms.each_pair do |attribute, value|
233+
value = [value] unless value.is_a?(Array)
234+
@output << "#{attribute}(#{value.join(',')})"
235+
end
236+
@output << '"'
237+
end
238+
239+
227240
end
228241

spec/rasem_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,16 @@
259259
str = img.output
260260
str.should =~ %r{<g .*circle.*circle.*</g>}
261261
end
262+
263+
it "should apply transforms to a group" do
264+
img = Rasem::SVGImage.new(100, 100) do
265+
group({}, {:scale => 5, :translate => [15,20]}) do
266+
circle(0, 0, 10)
267+
end
268+
end
269+
str = img.output
270+
str.should =~ %r{scale\(5\)translate\(15,20\)}
271+
end
262272

263273
it "should update width and height after init" do
264274
img = Rasem::SVGImage.new(100, 100) do

0 commit comments

Comments
 (0)