vector_salad 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aaccdb7ab3d09bd163ec4868a518c0a93ed2be68
4
- data.tar.gz: 6cca51fd3cde40a4003785ef789b8586c4dc2b20
3
+ metadata.gz: bc23021a759973f72595a9b083f0c14557a81ee1
4
+ data.tar.gz: de57bf043d59f32f38f9c85a4ec54d4b1347c4b2
5
5
  SHA512:
6
- metadata.gz: 4327f2033ea5c7a2525987c755401cf6eb7ca47eadbca43bfcdff85ce45db3667466b8c05b30874c03362deea47b461dc6ebee2e995db06e7fc71415c1588606
7
- data.tar.gz: fac9847a5c5f658b3568f1dd30b677c902d18106c99c81cc9858aed256aedc672d3df9405f58ffb4af3832d8f03b1ffc79b5eae2c209825dab3248fc81e9481c
6
+ metadata.gz: e9b18624730aab10da1463714ae2b6da737ffdcf168a205205fe48f668cdfacebe9c9f6d60cae3220472f19267857a6d5650cf1a1162536c3ab167c83afbd429
7
+ data.tar.gz: 78df56043bb2ad3d9f5ad54bbd8413705c8d2432315477a5af4b449c0febeb954973f89b9a35b00546469cb9d150985417f2e2f3d878c56e0c30e25d3d0c2de8
data/bin/vector_salad CHANGED
@@ -2,74 +2,11 @@
2
2
 
3
3
  require "optparse"
4
4
  require "ostruct"
5
- require_relative "../lib/vector_salad/version"
5
+ require "vector_salad/version"
6
+ require "vector_salad/optparse"
6
7
 
7
- class OptparseVectorSalad
8
- #
9
- # Return a structure describing the options.
10
- #
11
- def self.parse(args)
12
- # The options specified on the command line will be collected in *options*.
13
- # We set default values here.
14
- options = OpenStruct.new
15
- options.file = nil
16
- options.magic = true
17
- options.verbose = false
18
- options.width = nil
19
- options.height = nil
8
+ ARGV << "--help" if ARGV.empty?
9
+ options = VectorSalad::Optparse.parse(ARGV)
20
10
 
21
- opt_parser = OptionParser.new do |opts|
22
- opts.banner = "Usage: vrs [options]"
23
-
24
- opts.separator ""
25
- opts.separator "Specific options:"
26
-
27
- opts.on("--crop CROP",
28
- "Set manual crop, WIDTHxHEIGHT, e.g: 400x600") do |crop|
29
- options.width, options.height = crop.split('x').map(&:to_i)
30
- end
31
-
32
- # Mandatory argument.
33
- opts.on("-f", "--file FILE",
34
- "Run VectorSalad on the FILE") do |file|
35
- options.file = file
36
- end
37
-
38
- opts.on("--[no-]magic",
39
- "Add some helpful magic to your design") do |m|
40
- puts "So this happened: #{m}"
41
- options.magic = m
42
- end
43
-
44
- # Boolean switch.
45
- # opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
46
- # options.verbose = v
47
- # end
48
-
49
- opts.separator ""
50
- opts.separator "Common options:"
51
-
52
- # No argument, shows at tail. This will print an options summary.
53
- # Try it and see!
54
- opts.on_tail("-h", "--help", "Show this message") do
55
- puts opts
56
- exit
57
- end
58
-
59
- # Another typical switch to print the version.
60
- opts.on_tail("--version", "Show version") do
61
- puts VectorSalad::VERSION
62
- exit
63
- end
64
- end
65
-
66
- opt_parser.parse!(args)
67
- options
68
- end
69
- end
70
-
71
- ARGV << "-h" if ARGV.empty?
72
- options = OptparseVectorSalad.parse(ARGV)
73
-
74
- require_relative "../lib/vector_salad/export_with_magic"
11
+ require "vector_salad/export_with_magic"
75
12
  puts VectorSalad::ExportWithMagic.new(options).export
@@ -0,0 +1,34 @@
1
+ # @api private
2
+ module Contracts
3
+ module Builtin
4
+ class Coords
5
+ def self.valid?(val)
6
+ Contracts::Maybe[[Contracts::Num, Contracts::Num]].valid? val
7
+ end
8
+
9
+ def self.to_s
10
+ "[Num, Num] an x,y coordinate array"
11
+ end
12
+ end
13
+
14
+ class Coord
15
+ def self.valid?(val)
16
+ Contracts::Num.valid? val
17
+ end
18
+
19
+ def self.to_s
20
+ "Num; a coordinate"
21
+ end
22
+ end
23
+
24
+ class PolySides
25
+ def self.valid?(val)
26
+ val && val.is_a?(Integer) && val >= 3
27
+ end
28
+
29
+ def self.to_s
30
+ "Int; sides of the polygon, minimum of 3"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -8,7 +8,7 @@ module VectorSalad
8
8
  # @api private
9
9
  module Magic
10
10
  def canvas
11
- @vs_canvas ||= VectorSalad::Canvas.new
11
+ @canvas ||= VectorSalad::Canvas.new
12
12
  end
13
13
  end
14
14
  end
@@ -0,0 +1,65 @@
1
+ module VectorSalad
2
+ # @api private
3
+ class Optparse
4
+ def self.defaults
5
+ @defaults ||= {
6
+ file: nil,
7
+ magic: true,
8
+ verbose: false,
9
+ width: nil,
10
+ height: nil
11
+ }
12
+ end
13
+
14
+ def self.options
15
+ @options ||= OpenStruct.new(defaults)
16
+ end
17
+
18
+ def self.tool_name=(name)
19
+ @tool_name = name
20
+ end
21
+ self.tool_name = "vector_salad"
22
+
23
+ def self.optparse
24
+ @optparse ||= OptionParser.new do |o|
25
+ o.banner = <<-EOF.gsub(/^.*# ?/, "")
26
+ # Usage:
27
+ # #{@tool_name} -f path/to/file.rb [options]
28
+ #
29
+ # Options:
30
+ EOF
31
+
32
+ o.on_head("-c", "--crop CROP", "Set manual crop, WIDTHxHEIGHT, e.g: 400x600") do |crop|
33
+ options.width, options.height = crop.split("x").map(&:to_i)
34
+ end
35
+
36
+ o.on_head("-f", "--file FILE", "Run VectorSalad on the FILE") do |file|
37
+ options.file = file
38
+ end
39
+
40
+ # o.on_head("--[no-]magic", "Add some helpful magic to your design") do |m|
41
+ # options.magic = m
42
+ # end
43
+
44
+ o.separator ""
45
+ o.separator "General options:"
46
+
47
+ o.on_tail("-h", "--help", "Show this message") do
48
+ puts o
49
+ exit
50
+ end
51
+
52
+ o.on_tail("--version", "Show version") do
53
+ puts VectorSalad::VERSION
54
+ exit
55
+ end
56
+ end
57
+ end
58
+
59
+ # Return a structure describing the options.
60
+ def self.parse(args)
61
+ optparse.parse!(args)
62
+ options
63
+ end
64
+ end
65
+ end
@@ -1,6 +1,6 @@
1
1
  require "forwardable"
2
2
  require "contracts"
3
- require "contracts_contracts"
3
+ require "contracts_builtin"
4
4
 
5
5
  module VectorSalad
6
6
  module StandardShapes
@@ -13,7 +13,8 @@ module VectorSalad
13
13
  # You can't use BasicShape directly.
14
14
  class BasicShape
15
15
  extend Forwardable
16
- include Contracts
16
+ include Contracts::Core
17
+ include Contracts::Builtin
17
18
 
18
19
  attr_accessor :options
19
20
 
@@ -2,6 +2,7 @@ require "clipper"
2
2
 
3
3
  require "vector_salad/dsl"
4
4
  require "vector_salad/canvas"
5
+ require "vector_salad/standard_shapes/basic_shape"
5
6
  require "vector_salad/standard_shapes/multi_path"
6
7
 
7
8
  module VectorSalad
@@ -1,7 +1,6 @@
1
- require "vector_salad/standard_shapes/path"
2
- require "vector_salad/standard_shapes/n"
3
1
  require "vector_salad/dsl"
4
2
  require "vector_salad/canvas"
3
+ require "vector_salad/standard_shapes/basic_shape"
5
4
 
6
5
  module VectorSalad
7
6
  module StandardShapes
@@ -1,5 +1,4 @@
1
1
  require "vector_salad/standard_shapes/clip"
2
- require "vector_salad/standard_shapes/multi_path"
3
2
 
4
3
  module VectorSalad
5
4
  module StandardShapes
@@ -1,5 +1,4 @@
1
1
  require "vector_salad/standard_shapes/clip"
2
- require "vector_salad/standard_shapes/multi_path"
3
2
 
4
3
  module VectorSalad
5
4
  module StandardShapes
@@ -1,4 +1,5 @@
1
1
  require "vector_salad/standard_shapes/transform"
2
+ require "vector_salad/canvas"
2
3
 
3
4
  module VectorSalad
4
5
  module StandardShapes
@@ -1,4 +1,6 @@
1
+ require "vector_salad/standard_shapes/basic_shape"
1
2
  require "vector_salad/standard_shapes/polygon"
3
+ require "vector_salad/standard_shapes/union"
2
4
 
3
5
  module VectorSalad
4
6
  module StandardShapes
@@ -1,5 +1,4 @@
1
1
  require "vector_salad/standard_shapes/clip"
2
- require "vector_salad/standard_shapes/multi_path"
3
2
 
4
3
  module VectorSalad
5
4
  module StandardShapes
@@ -1,3 +1,4 @@
1
+ require "vector_salad/standard_shapes/basic_shape"
1
2
  require "vector_salad/standard_shapes/path"
2
3
  require "vector_salad/standard_shapes/n"
3
4
  require "vector_salad/mixins/at"
@@ -1,3 +1,4 @@
1
+ require "vector_salad/canvas"
1
2
  require "vector_salad/standard_shapes/transform"
2
3
 
3
4
  module VectorSalad
@@ -1,4 +1,5 @@
1
1
  require "vector_salad/standard_shapes/transform"
2
+ require "vector_salad/canvas"
2
3
 
3
4
  module VectorSalad
4
5
  module StandardShapes
@@ -1,3 +1,4 @@
1
+ require "vector_salad/standard_shapes/basic_shape"
1
2
  require "vector_salad/standard_shapes/path"
2
3
  require "vector_salad/standard_shapes/n"
3
4
  require "vector_salad/mixins/at"
@@ -1,4 +1,5 @@
1
- require "contracts_contracts"
1
+ require "contracts_builtin"
2
+ require "vector_salad/standard_shapes/basic_shape"
2
3
  require "vector_salad/standard_shapes/path"
3
4
  require "vector_salad/mixins/at"
4
5
 
@@ -1,3 +1,4 @@
1
+ require "vector_salad/standard_shapes/basic_shape"
1
2
  require "vector_salad/standard_shapes/path"
2
3
  require "vector_salad/standard_shapes/n"
3
4
  require "vector_salad/mixins/at"
@@ -1,4 +1,5 @@
1
1
  require "vector_salad/standard_shapes/transform"
2
+ require "vector_salad/canvas"
2
3
 
3
4
  module VectorSalad
4
5
  module StandardShapes
@@ -1,9 +1,7 @@
1
1
  require "contracts"
2
- require "contracts_contracts"
3
-
2
+ require "contracts_builtin"
4
3
  require "vector_salad/dsl"
5
4
  require "vector_salad/canvas"
6
- require "vector_salad/standard_shapes/path"
7
5
 
8
6
  module VectorSalad
9
7
  module StandardShapes
@@ -11,7 +9,8 @@ module VectorSalad
11
9
  class Transform
12
10
  include VectorSalad::DSL
13
11
  include VectorSalad::StandardShapes
14
- include Contracts
12
+ include Contracts::Core
13
+ include Contracts::Builtin
15
14
 
16
15
  def canvas
17
16
  @canvas ||= VectorSalad::Canvas.new
@@ -1,5 +1,4 @@
1
1
  require "vector_salad/standard_shapes/clip"
2
- require "vector_salad/standard_shapes/multi_path"
3
2
 
4
3
  module VectorSalad
5
4
  module StandardShapes
@@ -1,3 +1,3 @@
1
1
  module VectorSalad
2
- VERSION = "0.1.3" # Version of VectorSalad
2
+ VERSION = "0.2.0" # Version of VectorSalad
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vector_salad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon George
@@ -209,7 +209,7 @@ files:
209
209
  - examples/triangles.png
210
210
  - examples/triangles.rb
211
211
  - examples/triangles.svg
212
- - lib/contracts_contracts.rb
212
+ - lib/contracts_builtin.rb
213
213
  - lib/vector_salad.rb
214
214
  - lib/vector_salad/canvas.rb
215
215
  - lib/vector_salad/dsl.rb
@@ -221,6 +221,7 @@ files:
221
221
  - lib/vector_salad/mixins/at.rb
222
222
  - lib/vector_salad/mixins/mixins.rb
223
223
  - lib/vector_salad/monkeypatches.rb
224
+ - lib/vector_salad/optparse.rb
224
225
  - lib/vector_salad/shape_proxy.rb
225
226
  - lib/vector_salad/standard_shapes/basic_shape.rb
226
227
  - lib/vector_salad/standard_shapes/circle.rb
@@ -1,32 +0,0 @@
1
- # @api private
2
- module Contracts
3
- class Coords
4
- def self.valid?(val)
5
- Contracts::Maybe[[Contracts::Num, Contracts::Num]].valid? val
6
- end
7
-
8
- def self.to_s
9
- "[Num, Num] an x,y coordinate array"
10
- end
11
- end
12
-
13
- class Coord
14
- def self.valid?(val)
15
- Contracts::Num.valid? val
16
- end
17
-
18
- def self.to_s
19
- "Num; a coordinate"
20
- end
21
- end
22
-
23
- class PolySides
24
- def self.valid?(val)
25
- val && val.is_a?(Integer) && val >= 3
26
- end
27
-
28
- def self.to_s
29
- "Int; sides of the polygon, minimum of 3"
30
- end
31
- end
32
- end