savage 1.1.8 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ A little gem for extracting and manipulating SVG vector path data, Savage will m
4
4
 
5
5
  == Latest Update
6
6
 
7
- Version 1.1.0 adds support for Rails 3 and Ruby 1.9.2. Enjoy!
7
+ Version 1.2.0 includes a new array abstraction (see below) and optimized implementation of Direction#to_command, courtesy of {bdon}[https://github.com/bdon]!
8
8
 
9
9
  == Usage
10
10
 
@@ -68,6 +68,12 @@ Did you mess up before and need to change a directions coordinates after you dre
68
68
 
69
69
  As you may have guessed, Savage::Path#subpaths and Savage::SubPath#directions are both just good old-fashioned arrays, so you can fiddle with them using all your favorite Enumerable tricks as always.
70
70
 
71
+ <b>Abstracting it to an array (new in v1.2.0!)</b>
72
+
73
+ Bang!:
74
+
75
+ path.to_a # => ["M", 100, 200, ...]
76
+
71
77
  <b>Turning it back into a path data string</b>
72
78
 
73
79
  Bang!:
@@ -90,10 +96,10 @@ I have no doubt that will be some problems with this thing, as well as features
90
96
 
91
97
  == Contributors
92
98
 
93
- * Jeremy Holland (jeremy@jeremypholland.com, github:awebneck) -- author
94
- * Christoffer Klang (toffeklang@yahoo.se, github:christoffer) -- regexp improvements
95
- * MatmaRex (github:MatmaRex) -- parser improvements, scientific notation support, bug fixes
96
- * Brandon Liu (github:bdon) -- spec improvements
99
+ * Jeremy Holland (jeremy@jeremypholland.com, github:{awebneck}[https://github.com/awebneck]) -- author
100
+ * Christoffer Klang (toffeklang@yahoo.se, github:{christoffer}[https://github.com/christoffer]) -- regexp improvements
101
+ * Bartosz Dz (github:{MatmaRex}[https://github.com/matmarex]) -- parser improvements, scientific notation support, bug fixes
102
+ * Brandon Liu (github:{bdon}[https://github.com/bdon]) -- spec improvements, array abstraction
97
103
 
98
104
  == Copyright
99
105
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.8
1
+ 1.2.0
@@ -2,18 +2,23 @@ module Savage
2
2
  module Directions
3
3
  Point = Struct.new :x, :y
4
4
  end
5
-
5
+
6
6
  class Direction
7
-
7
+
8
8
  include Utils
9
-
9
+
10
10
  def initialize(absolute)
11
11
  @absolute = absolute
12
12
  end
13
-
13
+
14
14
  def absolute?
15
15
  @absolute
16
16
  end
17
+
18
+ def to_command
19
+ arr = to_a
20
+ arr[0] + arr[1..-1].join(' ').gsub(/ -/,'-')
21
+ end
17
22
  end
18
23
  end
19
24
 
@@ -2,7 +2,7 @@ module Savage
2
2
  module Directions
3
3
  class ArcTo < PointTarget
4
4
  attr_accessor :radius, :rotation, :large_arc, :sweep
5
-
5
+
6
6
  def initialize(radius_x, radius_y, rotation, large_arc, sweep, target_x, target_y, absolute=true)
7
7
  super(target_x, target_y, absolute)
8
8
  @radius = Point.new(radius_x, radius_y)
@@ -10,11 +10,11 @@ module Savage
10
10
  @large_arc = large_arc.is_a?(Numeric) ? large_arc > 0 : large_arc
11
11
  @sweep = sweep.is_a?(Numeric) ? sweep > 0 : sweep
12
12
  end
13
-
14
- def to_command
15
- command_code << "#{@radius.x} #{@radius.y} #{@rotation} #{bool_to_int(@large_arc)} #{bool_to_int(@sweep)} #{target.x} #{target.y}".gsub(/ -/,'-')
13
+
14
+ def to_a
15
+ [command_code, @radius.x, @radius.y, @rotation, bool_to_int(@large_arc), bool_to_int(@sweep), target.x, target.y]
16
16
  end
17
-
17
+
18
18
  def command_code
19
19
  (absolute?) ? 'A' : 'a'
20
20
  end
@@ -1,15 +1,15 @@
1
1
  module Savage
2
2
  module Directions
3
3
  class ClosePath < Direction
4
-
4
+
5
5
  def initialize(absolute=true)
6
6
  super(absolute)
7
7
  end
8
-
9
- def to_command
10
- command_code
8
+
9
+ def to_a
10
+ [command_code]
11
11
  end
12
-
12
+
13
13
  def command_code
14
14
  (absolute?) ? 'Z' : 'z'
15
15
  end
@@ -1,16 +1,16 @@
1
1
  module Savage
2
2
  module Directions
3
3
  class CoordinateTarget < Direction
4
-
4
+
5
5
  attr_accessor :target
6
-
6
+
7
7
  def initialize(target, absolute=true)
8
8
  @target = target
9
9
  super(absolute)
10
10
  end
11
-
12
- def to_command
13
- command_code << @target.to_s
11
+
12
+ def to_a
13
+ [command_code, @target.to_s]
14
14
  end
15
15
  end
16
16
  end
@@ -2,7 +2,7 @@ module Savage
2
2
  module Directions
3
3
  class CubicCurveTo < QuadraticCurveTo
4
4
  attr_accessor :control_1
5
-
5
+
6
6
  def initialize(*args)
7
7
  raise ArgumentError if args.length < 4
8
8
  case args.length
@@ -19,14 +19,18 @@ module Savage
19
19
  super(args[2],args[3],args[4],args[5],args[6])
20
20
  end
21
21
  end
22
-
23
- def to_command
24
- command_code << ((@control_1) ? "#{@control_1.x} #{@control_1.y} #{@control.x} #{@control.y} #{@target.x} #{@target.y}".gsub(/ -/,'-') : super().gsub(/[A-Za-z]/,''))
22
+
23
+ def to_a
24
+ if @control_1
25
+ [command_code, @control_1.x, @control_1.y, @control.x, @control.y, @target.x, @target.y]
26
+ else
27
+ [command_code, @control.x, @control.y, @target.x, @target.y]
28
+ end
25
29
  end
26
-
30
+
27
31
  def control_2; @control; end
28
32
  def control_2=(value); @control = value; end
29
-
33
+
30
34
  def command_code
31
35
  return (absolute?) ? 'C' : 'c' if @control_1
32
36
  (absolute?) ? 'S' : 's'
@@ -1,16 +1,16 @@
1
1
  module Savage
2
2
  module Directions
3
3
  class PointTarget < Direction
4
-
4
+
5
5
  attr_accessor :target
6
-
6
+
7
7
  def initialize(x, y, absolute=true)
8
8
  @target = Point.new(x,y)
9
9
  super(absolute)
10
10
  end
11
-
12
- def to_command
13
- command_code << "#{@target.x.to_s} #{@target.y.to_s}".gsub(/ -/,'-')
11
+
12
+ def to_a
13
+ [command_code, @target.x, @target.y]
14
14
  end
15
15
  end
16
16
  end
@@ -2,7 +2,7 @@ module Savage
2
2
  module Directions
3
3
  class QuadraticCurveTo < PointTarget
4
4
  attr_accessor :control
5
-
5
+
6
6
  def initialize(*args)
7
7
  raise ArgumentError if args.length < 2
8
8
  case args.length
@@ -19,9 +19,13 @@ module Savage
19
19
  super(args[2],args[3],args[4])
20
20
  end
21
21
  end
22
-
23
- def to_command
24
- command_code << ((@control) ? "#{@control.x} #{@control.y} #{@target.x} #{@target.y}".gsub(/ -/,'-') : super().gsub(/[A-Za-z]/,''))
22
+
23
+ def to_a
24
+ if @control
25
+ [command_code, @control.x, @control.y, @target.x, @target.y]
26
+ else
27
+ [command_code, @target.x, @target.y]
28
+ end
25
29
  end
26
30
 
27
31
  def command_code
@@ -2,30 +2,30 @@ module Savage
2
2
  class Path
3
3
  require File.dirname(__FILE__) + "/direction_proxy"
4
4
  require File.dirname(__FILE__) + "/sub_path"
5
-
5
+
6
6
  include Utils
7
7
  include DirectionProxy
8
-
8
+
9
9
  attr_accessor :subpaths
10
-
10
+
11
11
  define_proxies do |sym,const|
12
12
  define_method(sym) do |*args|
13
13
  @subpaths.last.send(sym,*args)
14
- end
14
+ end
15
15
  end
16
-
16
+
17
17
  def initialize(*args)
18
18
  @subpaths = [SubPath.new]
19
19
  @subpaths.last.move_to(*args) if (2..3).include?(*args.length)
20
20
  yield self if block_given?
21
21
  end
22
-
22
+
23
23
  def directions
24
24
  directions = []
25
25
  @subpaths.each { |subpath| directions.concat(subpath.directions) }
26
26
  directions
27
27
  end
28
-
28
+
29
29
  def move_to(*args)
30
30
  unless (@subpaths.last.directions.empty?)
31
31
  (@subpaths << SubPath.new(*args)).last
@@ -33,11 +33,11 @@ module Savage
33
33
  @subpaths.last.move_to(*args)
34
34
  end
35
35
  end
36
-
36
+
37
37
  def closed?
38
38
  @subpaths.last.closed?
39
39
  end
40
-
40
+
41
41
  def to_command
42
42
  @subpaths.collect { |subpath| subpath.to_command }.join
43
43
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "savage"
8
- s.version = "1.1.8"
8
+ s.version = "1.2.0"
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 = "2013-01-03"
12
+ s.date = "2013-01-10"
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 = [
@@ -22,7 +22,7 @@ describe Path do
22
22
  path.subpaths.last.directions[1].class.should == Directions::LineTo
23
23
  path.subpaths.last.directions[2].class.should == Directions::CubicCurveTo
24
24
  path.subpaths.last.directions[3].class.should == Directions::ArcTo
25
-
25
+
26
26
  path2 = Path.new do |p|
27
27
  p.line_to 300, 400
28
28
  p.cubic_curve_to 500,600,700,800,900,1000
@@ -102,4 +102,4 @@ describe Path do
102
102
  path.to_command.should == concatenated
103
103
  end
104
104
  end
105
- end
105
+ 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.8
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-03 00:00:00.000000000 Z
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec