Skip to content

Commit

Permalink
adding transforms to groups, getting specs to run
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Slate committed May 30, 2012
1 parent 764ef82 commit a360e45
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
7 changes: 3 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ source "http://rubygems.org"
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "rspec", "~> 2.3.0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.2"
gem "rcov", ">= 0"
gem "rspec", "~> 2.10.0"
gem "jeweler", "~> 1.8.2"
gem "simplecov", "~> 0.6.4"
end
15 changes: 14 additions & 1 deletion lib/rasem/svg_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ def with_style(style={}, &proc)
@default_styles.pop
end

def group(style={}, &proc)
def group(style={}, transforms={}, &proc)
# Open the group
@output << "<g"
write_style(style)
write_transforms(transforms)
@output << ">"
# Call the block
self.instance_exec(&proc)
Expand Down Expand Up @@ -224,5 +225,17 @@ def write_style(style)
end
@output << '"'
end

def write_transforms(transforms)
return if transforms.empty?
@output << ' transform="'
transforms.each_pair do |attribute, value|
value = [value] unless value.is_a?(Array)
@output << "#{attribute}(#{value.join(',')})"
end
@output << '"'
end


end

10 changes: 10 additions & 0 deletions spec/rasem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@
str = img.output
str.should =~ %r{<g .*circle.*circle.*</g>}
end

it "should apply transforms to a group" do
img = Rasem::SVGImage.new(100, 100) do
group({}, {:scale => 5, :translate => [15,20]}) do
circle(0, 0, 10)
end
end
str = img.output
str.should =~ %r{scale\(5\)translate\(15,20\)}
end

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

0 comments on commit a360e45

Please sign in to comment.