savage 1.1.6 → 1.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/savage/parser.rb +6 -4
- data/savage.gemspec +3 -3
- data/spec/savage/parser_spec.rb +28 -2
- metadata +10 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.7
|
data/lib/savage/parser.rb
CHANGED
@@ -18,7 +18,7 @@ module Savage
|
|
18
18
|
subpaths = []
|
19
19
|
if move_index = parsable.index(/[Mm]/)
|
20
20
|
subpaths << parsable[0...move_index] if move_index > 0
|
21
|
-
parsable.scan
|
21
|
+
parsable.scan(/[Mm](?:\d|[eE.,+-]|[LlHhVvQqCcTtSsAaZz]|\W)+/m) do |match_group|
|
22
22
|
subpaths << $&
|
23
23
|
end
|
24
24
|
else
|
@@ -36,7 +36,7 @@ module Savage
|
|
36
36
|
def extract_directions(parsable, force_absolute=false)
|
37
37
|
directions = []
|
38
38
|
i = 0
|
39
|
-
parsable.scan
|
39
|
+
parsable.scan(/[MmLlHhVvQqCcTtSsAaZz](?:\d|[eE.,+-]|\W)*/m) do |match_group|
|
40
40
|
direction = build_direction $&, force_absolute && i == 0
|
41
41
|
if direction.kind_of?(Array)
|
42
42
|
directions.concat direction
|
@@ -51,15 +51,16 @@ module Savage
|
|
51
51
|
def build_direction(parsable, force_absolute=false)
|
52
52
|
directions = []
|
53
53
|
coordinates = extract_coordinates parsable
|
54
|
-
absolute = (force_absolute || parsable[0,1] == parsable[0,1].upcase) ? true : false
|
55
54
|
recurse_code = parsable[0,1]
|
55
|
+
first_absolute = force_absolute
|
56
56
|
|
57
57
|
# we need to handle this separately, since ClosePath doesn't take any coordinates
|
58
58
|
if coordinates.empty? && recurse_code =~ /[Zz]/
|
59
|
-
directions << Directions::ClosePath.new(
|
59
|
+
directions << Directions::ClosePath.new(parsable[0,1] == parsable[0,1].upcase)
|
60
60
|
end
|
61
61
|
|
62
62
|
until coordinates.empty?
|
63
|
+
absolute = (first_absolute || parsable[0,1] == parsable[0,1].upcase)
|
63
64
|
case recurse_code
|
64
65
|
when /[Mm]/
|
65
66
|
x = coordinates.shift
|
@@ -122,6 +123,7 @@ module Savage
|
|
122
123
|
coordinates = []
|
123
124
|
raise TypeError
|
124
125
|
end
|
126
|
+
first_absolute = false
|
125
127
|
end
|
126
128
|
|
127
129
|
directions
|
data/savage.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "savage"
|
8
|
-
s.version = "1.1.
|
8
|
+
s.version = "1.1.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jeremy Holland"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-10-16"
|
13
13
|
s.description = "A little gem for extracting and manipulating SVG vector path data."
|
14
14
|
s.email = "jeremy@jeremypholland.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -62,7 +62,7 @@ Gem::Specification.new do |s|
|
|
62
62
|
]
|
63
63
|
s.homepage = "http://github.com/awebneck/savage"
|
64
64
|
s.require_paths = ["lib"]
|
65
|
-
s.rubygems_version = "1.8.
|
65
|
+
s.rubygems_version = "1.8.24"
|
66
66
|
s.summary = "A little library to manipulate SVG path data"
|
67
67
|
|
68
68
|
if s.respond_to? :specification_version then
|
data/spec/savage/parser_spec.rb
CHANGED
@@ -165,37 +165,63 @@ describe Parser do
|
|
165
165
|
path.subpaths.last.directions[1].target.y.should == 400
|
166
166
|
end
|
167
167
|
|
168
|
-
it 'should return a path object with one subpath containing
|
168
|
+
it 'should return a path object with one subpath containing an absolute move_to and two absolute line_to directions when the string is an absolute move_to command followed by more than one set of implicit coordinates' do
|
169
169
|
path = Parser.parse("M100 200 300 400 500 600 ")
|
170
170
|
path.class.should == Path
|
171
171
|
path.subpaths.length.should == 1
|
172
172
|
path.subpaths.last.directions.length.should == 3
|
173
173
|
path.subpaths.last.directions[0].class.should == Directions::MoveTo
|
174
|
+
path.subpaths.last.directions[0].should be_absolute
|
174
175
|
path.subpaths.last.directions[0].target.x.should == 100
|
175
176
|
path.subpaths.last.directions[0].target.y.should == 200
|
176
177
|
path.subpaths.last.directions[1].class.should == Directions::LineTo
|
178
|
+
path.subpaths.last.directions[1].should be_absolute
|
177
179
|
path.subpaths.last.directions[1].target.x.should == 300
|
178
180
|
path.subpaths.last.directions[1].target.y.should == 400
|
179
181
|
path.subpaths.last.directions[2].class.should == Directions::LineTo
|
182
|
+
path.subpaths.last.directions[2].should be_absolute
|
183
|
+
path.subpaths.last.directions[2].target.x.should == 500
|
184
|
+
path.subpaths.last.directions[2].target.y.should == 600
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should return a path object with one subpath containing an absolute move_to and two relative line_to directions when the string is a relative move_to command followed by more than one set of implicit coordinates' do
|
188
|
+
path = Parser.parse("m100 200 300 400 500 600 ")
|
189
|
+
path.class.should == Path
|
190
|
+
path.subpaths.length.should == 1
|
191
|
+
path.subpaths.last.directions.length.should == 3
|
192
|
+
path.subpaths.last.directions[0].class.should == Directions::MoveTo
|
193
|
+
path.subpaths.last.directions[0].should be_absolute
|
194
|
+
path.subpaths.last.directions[0].target.x.should == 100
|
195
|
+
path.subpaths.last.directions[0].target.y.should == 200
|
196
|
+
path.subpaths.last.directions[1].class.should == Directions::LineTo
|
197
|
+
path.subpaths.last.directions[1].should_not be_absolute
|
198
|
+
path.subpaths.last.directions[1].target.x.should == 300
|
199
|
+
path.subpaths.last.directions[1].target.y.should == 400
|
200
|
+
path.subpaths.last.directions[2].class.should == Directions::LineTo
|
201
|
+
path.subpaths.last.directions[2].should_not be_absolute
|
180
202
|
path.subpaths.last.directions[2].target.x.should == 500
|
181
203
|
path.subpaths.last.directions[2].target.y.should == 600
|
182
204
|
end
|
183
205
|
|
184
206
|
it 'should return a path object with two subpaths containing one line_to directions each when the string is two move_to commands each followed by a line_to command' do
|
185
|
-
path = Parser.parse("M100 200 332 -12.
|
207
|
+
path = Parser.parse("M100 200 332 -12.3m594 230-423 11.1")
|
186
208
|
path.class.should == Path
|
187
209
|
path.subpaths.length.should == 2
|
188
210
|
path.subpaths[0].directions.length.should == 2
|
189
211
|
path.subpaths[0].directions[0].class.should == Directions::MoveTo
|
212
|
+
path.subpaths[0].directions[0].should be_absolute
|
190
213
|
path.subpaths[0].directions[0].target.x.should == 100
|
191
214
|
path.subpaths[0].directions[0].target.y.should == 200
|
192
215
|
path.subpaths[0].directions[1].class.should == Directions::LineTo
|
216
|
+
path.subpaths[0].directions[1].should be_absolute
|
193
217
|
path.subpaths[0].directions[1].target.x.should == 332
|
194
218
|
path.subpaths[0].directions[1].target.y.should == -12.3
|
195
219
|
path.subpaths[1].directions[0].class.should == Directions::MoveTo
|
220
|
+
path.subpaths[1].directions[0].should_not be_absolute
|
196
221
|
path.subpaths[1].directions[0].target.x.should == 594
|
197
222
|
path.subpaths[1].directions[0].target.y.should == 230
|
198
223
|
path.subpaths[1].directions[1].class.should == Directions::LineTo
|
224
|
+
path.subpaths[1].directions[1].should_not be_absolute
|
199
225
|
path.subpaths[1].directions[1].target.x.should == -423
|
200
226
|
path.subpaths[1].directions[1].target.y.should == 11.1
|
201
227
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: savage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,12 @@ dependencies:
|
|
21
21
|
version: 2.3.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.3.0
|
25
30
|
description: A little gem for extracting and manipulating SVG vector path data.
|
26
31
|
email: jeremy@jeremypholland.com
|
27
32
|
executables: []
|
@@ -92,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
97
|
version: '0'
|
93
98
|
requirements: []
|
94
99
|
rubyforge_project:
|
95
|
-
rubygems_version: 1.8.
|
100
|
+
rubygems_version: 1.8.24
|
96
101
|
signing_key:
|
97
102
|
specification_version: 3
|
98
103
|
summary: A little library to manipulate SVG path data
|