squib 0.15.3 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +22 -0
  3. data/CHANGELOG.md +35 -1
  4. data/Dockerfile +18 -16
  5. data/Guardfile +8 -0
  6. data/README.md +3 -9
  7. data/RELEASE TODO.md +4 -2
  8. data/Rakefile +3 -0
  9. data/lib/squib.rb +5 -1
  10. data/lib/squib/args/arg_loader.rb +109 -106
  11. data/lib/squib/args/box.rb +52 -48
  12. data/lib/squib/args/card_range.rb +26 -24
  13. data/lib/squib/args/color_validator.rb +4 -9
  14. data/lib/squib/args/coords.rb +39 -25
  15. data/lib/squib/args/csv_opts.rb +13 -16
  16. data/lib/squib/args/dir_validator.rb +7 -12
  17. data/lib/squib/args/draw.rb +69 -68
  18. data/lib/squib/args/drop_shadow.rb +39 -0
  19. data/lib/squib/args/embed_adjust.rb +12 -15
  20. data/lib/squib/args/embed_key.rb +6 -11
  21. data/lib/squib/args/hand_special.rb +25 -25
  22. data/lib/squib/args/import.rb +54 -27
  23. data/lib/squib/args/input_file.rb +22 -26
  24. data/lib/squib/args/paint.rb +30 -31
  25. data/lib/squib/args/paragraph.rb +95 -93
  26. data/lib/squib/args/save_batch.rb +50 -48
  27. data/lib/squib/args/scale_box.rb +43 -39
  28. data/lib/squib/args/sheet.rb +142 -149
  29. data/lib/squib/args/showcase_special.rb +32 -32
  30. data/lib/squib/args/sprue_file.rb +30 -30
  31. data/lib/squib/args/svg_special.rb +26 -26
  32. data/lib/squib/args/transform.rb +48 -54
  33. data/lib/squib/args/typographer.rb +88 -92
  34. data/lib/squib/args/unit_conversion.rb +6 -8
  35. data/lib/squib/args/xywh_shorthands.rb +51 -0
  36. data/lib/squib/builtin/projects/advanced/config.yml +4 -3
  37. data/lib/squib/builtin/projects/basic/config.yml +4 -3
  38. data/lib/squib/conf.rb +5 -0
  39. data/lib/squib/deck.rb +34 -12
  40. data/lib/squib/dsl/background.rb +35 -0
  41. data/lib/squib/dsl/circle.rb +39 -0
  42. data/lib/squib/dsl/csv.rb +42 -0
  43. data/lib/squib/dsl/curve.rb +35 -0
  44. data/lib/squib/dsl/cut_zone.rb +47 -0
  45. data/lib/squib/dsl/ellipse.rb +37 -0
  46. data/lib/squib/dsl/grid.rb +35 -0
  47. data/lib/squib/{api → dsl}/groups.rb +0 -0
  48. data/lib/squib/dsl/hand.rb +42 -0
  49. data/lib/squib/dsl/line.rb +35 -0
  50. data/lib/squib/dsl/png.rb +56 -0
  51. data/lib/squib/dsl/polygon.rb +36 -0
  52. data/lib/squib/dsl/rect.rb +37 -0
  53. data/lib/squib/dsl/safe_zone.rb +48 -0
  54. data/lib/squib/dsl/save.rb +21 -0
  55. data/lib/squib/dsl/save_pdf.rb +50 -0
  56. data/lib/squib/dsl/save_png.rb +48 -0
  57. data/lib/squib/dsl/save_sheet.rb +53 -0
  58. data/lib/squib/dsl/showcase.rb +43 -0
  59. data/lib/squib/dsl/star.rb +37 -0
  60. data/lib/squib/dsl/svg.rb +62 -0
  61. data/lib/squib/dsl/text.rb +54 -0
  62. data/lib/squib/dsl/text_embed.rb +78 -0
  63. data/lib/squib/dsl/triangle.rb +35 -0
  64. data/lib/squib/{api → dsl}/units.rb +10 -0
  65. data/lib/squib/dsl/xlsx.rb +40 -0
  66. data/lib/squib/dsl/yaml.rb +40 -0
  67. data/lib/squib/errors_warnings/warn_unexpected_params.rb +14 -0
  68. data/lib/squib/graphics/cairo_context_wrapper.rb +8 -6
  69. data/lib/squib/graphics/save_images.rb +54 -15
  70. data/lib/squib/graphics/save_sprue.rb +14 -2
  71. data/lib/squib/graphics/text.rb +37 -9
  72. data/lib/squib/import/csv_importer.rb +45 -0
  73. data/lib/squib/import/quantity_exploder.rb +18 -0
  74. data/lib/squib/import/xlsx_importer.rb +28 -0
  75. data/lib/squib/import/yaml_importer.rb +30 -0
  76. data/lib/squib/layout_parser.rb +24 -7
  77. data/lib/squib/sprues/crop_line.rb +6 -6
  78. data/lib/squib/sprues/crop_line_dash.rb +6 -6
  79. data/lib/squib/sprues/sprue.rb +16 -14
  80. data/lib/squib/system_fonts.rb +17 -0
  81. data/lib/squib/version.rb +2 -1
  82. data/samples/autoscale_font/_autoscale_font.rb +77 -8
  83. data/samples/colors/_switch_color.rb +2 -2
  84. data/samples/data/_excel.rb +1 -1
  85. data/samples/ranges/_ranges.rb +1 -1
  86. data/samples/saves/_save_filenames.rb +4 -0
  87. data/samples/saves/_save_pdf.rb +1 -1
  88. data/samples/saves/_saves.rb +12 -1
  89. data/samples/shadows/_shadow.rb +72 -0
  90. data/samples/shapes/_draw_shapes.rb +2 -2
  91. data/samples/sprues/_builtin_sprues.rb +1 -0
  92. data/samples/sprues/_fold_sheet.rb +4 -1
  93. data/samples/system_font_debug/_list_fonts.rb +14 -0
  94. data/samples/text/_text.rb +6 -1
  95. data/samples/text/_text_options.rb +2 -1
  96. data/samples/units/_cells.rb +51 -0
  97. data/samples/units/_shorthands.rb +48 -0
  98. data/samples/units/_units.rb +7 -0
  99. data/squib.gemspec +14 -8
  100. metadata +134 -39
  101. data/.travis.yml +0 -17
  102. data/appveyor.yml +0 -25
  103. data/lib/squib/api/background.rb +0 -15
  104. data/lib/squib/api/data.rb +0 -137
  105. data/lib/squib/api/image.rb +0 -49
  106. data/lib/squib/api/save.rb +0 -83
  107. data/lib/squib/api/shapes.rb +0 -124
  108. data/lib/squib/api/text.rb +0 -25
  109. data/lib/squib/api/text_embed.rb +0 -71
@@ -1,55 +1,59 @@
1
1
  require_relative 'arg_loader'
2
+ require_relative 'xywh_shorthands'
2
3
 
3
- module Squib
4
- # @api private
5
- module Args
6
-
7
- class Box
8
- include ArgLoader
9
-
10
- def initialize(deck = nil, dsl_method_defaults = {})
11
- @deck = deck
12
- @dsl_method_defaults = dsl_method_defaults
13
- end
14
-
15
- def self.parameters
16
- { x: 0, y: 0,
17
- width: :deck, height: :deck,
18
- radius: nil, x_radius: 0, y_radius: 0
19
- }
20
- end
21
-
22
- def self.expanding_parameters
23
- parameters.keys # all of them
24
- end
25
-
26
- def self.params_with_units
27
- parameters.keys # all of them
28
- end
29
-
30
- def validate_width(arg, _i)
31
- return arg if @deck.nil?
32
- return @deck.width if arg == :deck
33
- arg
34
- end
35
-
36
- def validate_height(arg, _i)
37
- return arg if @deck.nil?
38
- return @deck.height if arg == :deck
39
- arg
40
- end
41
-
42
- def validate_x_radius(arg, i)
43
- return radius[i] unless radius[i].nil?
44
- arg
45
- end
46
-
47
- def validate_y_radius(arg, i)
48
- return radius[i] unless radius[i].nil?
49
- arg
50
- end
4
+ module Squib::Args
51
5
 
6
+ module_function def extract_box(opts, deck, dsl_method_defaults = {})
7
+ Box.new(deck, dsl_method_defaults).extract!(opts, deck)
8
+ end
9
+
10
+ class Box
11
+ include ArgLoader
12
+ include XYWHShorthands
13
+
14
+ def initialize(deck = nil, dsl_method_defaults = {})
15
+ @deck = deck
16
+ @dsl_method_defaults = dsl_method_defaults
17
+ end
18
+
19
+ def self.parameters
20
+ { x: 0, y: 0,
21
+ width: :deck, height: :deck,
22
+ radius: nil, x_radius: 0, y_radius: 0
23
+ }
24
+ end
25
+
26
+ def self.expanding_parameters
27
+ parameters.keys # all of them
28
+ end
29
+
30
+ def self.params_with_units
31
+ parameters.keys # all of them
52
32
  end
53
33
 
34
+ def validate_x(arg, i) apply_shorthands(arg, @deck, axis: :x) end
35
+ def validate_y(arg,_i) apply_shorthands(arg, @deck, axis: :y) end
36
+
37
+ def validate_width(arg, _i)
38
+ return arg if @deck.nil?
39
+ apply_shorthands(arg, @deck, axis: :x)
40
+ end
41
+
42
+ def validate_height(arg, _i)
43
+ return arg if @deck.nil?
44
+ apply_shorthands(arg, @deck, axis: :y)
45
+ end
46
+
47
+ def validate_x_radius(arg, i)
48
+ return radius[i] unless radius[i].nil?
49
+ arg
50
+ end
51
+
52
+ def validate_y_radius(arg, i)
53
+ return radius[i] unless radius[i].nil?
54
+ arg
55
+ end
56
+
54
57
  end
58
+
55
59
  end
@@ -1,32 +1,34 @@
1
- module Squib
2
- # @api private
3
- module Args
4
- class CardRange
5
- include Enumerable
1
+ module Squib::Args
6
2
 
7
- def initialize(input, deck_size: 1)
8
- @range = validate(input, deck_size)
9
- end
3
+ module_function def extract_range(opts, deck)
4
+ CardRange.new(opts[:range], deck_size: deck.size)
5
+ end
6
+
7
+ class CardRange
8
+ include Enumerable
10
9
 
11
- # Hook into enumerable by delegating to @range
12
- def each(&block)
13
- @range.each { |i| block.call(i) }
14
- end
10
+ def initialize(input, deck_size: 1)
11
+ @range = validate(input, deck_size)
12
+ end
15
13
 
16
- def size
17
- @range.size
18
- end
14
+ # Hook into enumerable by delegating to @range
15
+ def each(&block)
16
+ @range.each { |i| block.call(i) }
17
+ end
19
18
 
20
- private
21
- def validate(input, deck_size)
22
- input ||= :all # default
23
- input = 0..(deck_size - 1) if input == :all
24
- input = (input.to_i)..(input.to_i) if input.respond_to? :to_i
25
- raise ArgumentError.new("#{input} must be Enumerable (i.e. respond_to :each).") unless input.respond_to? :each
26
- raise ArgumentError.new("#{input} is outside of deck range of 0..#{deck_size - 1}") if (!input.max.nil?) && (input.max > (deck_size - 1))
27
- input
28
- end
19
+ def size
20
+ @range.size
21
+ end
29
22
 
23
+ private
24
+ def validate(input, deck_size)
25
+ input ||= :all # default
26
+ input = 0..(deck_size - 1) if input == :all
27
+ input = (input.to_i)..(input.to_i) if input.respond_to? :to_i
28
+ raise ArgumentError.new("#{input} must be Enumerable (i.e. respond_to :each).") unless input.respond_to? :each
29
+ raise ArgumentError.new("#{input} is outside of deck range of 0..#{deck_size - 1}") if (!input.max.nil?) && (input.max > (deck_size - 1))
30
+ input
30
31
  end
32
+
31
33
  end
32
34
  end
@@ -1,12 +1,7 @@
1
- module Squib
2
- # @api private
3
- module Args
4
- module ColorValidator
1
+ module Squib::Args::ColorValidator
5
2
 
6
- def colorify(color, custom_colors = {})
7
- custom_colors[color.to_s] || color.to_s
8
- end
9
-
10
- end
3
+ def colorify(color, custom_colors = {})
4
+ custom_colors[color.to_s] || color.to_s
11
5
  end
6
+
12
7
  end
@@ -1,35 +1,49 @@
1
1
  require_relative 'arg_loader'
2
+ require_relative 'xywh_shorthands'
2
3
 
3
- module Squib
4
- # @api private
5
- module Args
6
-
7
- class Coords
8
- include ArgLoader
4
+ module Squib::Args
5
+ module_function def extract_coords(opts, deck)
6
+ Coords.new.extract!(opts, deck)
7
+ end
9
8
 
10
- def self.parameters
11
- { x: 0, y: 0,
12
- x1: 100, y1: 100,
13
- x2: 150, y2: 150,
14
- x3: 100, y3: 150,
15
- cx1: 0 , cy1: 0,
16
- cx2: 0 , cy2: 0,
17
- inner_radius: 50, outer_radius: 100,
18
- radius: 100,
19
- n: 5,
20
- arc_start: 0, arc_end: 2 * Math::PI, arc_direction: :clockwise, arc_close: false,
21
- }
22
- end
9
+ class Coords
10
+ include ArgLoader
11
+ include XYWHShorthands
23
12
 
24
- def self.expanding_parameters
25
- parameters.keys # all of them
26
- end
13
+ def self.parameters
14
+ { x: 0, y: 0,
15
+ x1: 100, y1: 100,
16
+ x2: 150, y2: 150,
17
+ x3: 100, y3: 150,
18
+ cx1: 0 , cy1: 0,
19
+ cx2: 0 , cy2: 0,
20
+ inner_radius: 50, outer_radius: 100,
21
+ radius: 100,
22
+ n: 5,
23
+ arc_start: 0, arc_end: 2 * Math::PI, arc_direction: :clockwise, arc_close: false,
24
+ }
25
+ end
27
26
 
28
- def self.params_with_units
29
- parameters.keys # all of them
30
- end
27
+ def self.expanding_parameters
28
+ parameters.keys # all of them
29
+ end
31
30
 
31
+ def self.params_with_units
32
+ parameters.keys # all of them
32
33
  end
33
34
 
35
+ def validate_x(arg, i) apply_shorthands(arg, @deck, axis: :x) end
36
+ def validate_y(arg,_i) apply_shorthands(arg, @deck, axis: :y) end
37
+ def validate_x1(arg, i) apply_shorthands(arg, @deck, axis: :x) end
38
+ def validate_y1(arg,_i) apply_shorthands(arg, @deck, axis: :y) end
39
+ def validate_x2(arg, i) apply_shorthands(arg, @deck, axis: :x) end
40
+ def validate_y2(arg,_i) apply_shorthands(arg, @deck, axis: :y)end
41
+ def validate_x3(arg, i) apply_shorthands(arg, @deck, axis: :x) end
42
+ def validate_y3(arg,_i) apply_shorthands(arg, @deck, axis: :y) end
43
+ def validate_cx1(arg, i) apply_shorthands(arg, @deck, axis: :x) end
44
+ def validate_cy1(arg,_i) apply_shorthands(arg, @deck, axis: :y) end
45
+ def validate_cx2(arg, i) apply_shorthands(arg, @deck, axis: :x) end
46
+ def validate_cy2(arg,_i) apply_shorthands(arg, @deck, axis: :y) end
34
47
  end
48
+
35
49
  end
@@ -1,25 +1,22 @@
1
1
  require 'csv'
2
2
 
3
- module Squib
4
- # @api private
5
- module Args
6
- class CSV_Opts
3
+ module Squib::Args
4
+ class CSV_Opts
7
5
 
8
- def initialize(opts)
9
- opts = opts.keep_if { |k, _v| CSV::DEFAULT_OPTIONS.key? k}
10
- @hash = CSV::DEFAULT_OPTIONS.merge(opts).merge(required)
11
- end
12
-
13
- def to_hash
14
- @hash
15
- end
6
+ def initialize(opts)
7
+ opts = opts.keep_if { |k, _v| CSV::DEFAULT_OPTIONS.key? k}
8
+ @hash = CSV::DEFAULT_OPTIONS.merge(opts).merge(required)
9
+ end
16
10
 
17
- private
11
+ def to_hash
12
+ @hash
13
+ end
18
14
 
19
- def required
20
- { headers: true, converters: :numeric }
21
- end
15
+ private
22
16
 
17
+ def required
18
+ { headers: true, converters: :numeric }
23
19
  end
20
+
24
21
  end
25
22
  end
@@ -1,16 +1,11 @@
1
- module Squib
2
- # @api private
3
- module Args
4
- module DirValidator
5
-
6
- def ensure_dir_created(dir)
7
- unless Dir.exists?(dir)
8
- Squib.logger.warn "Dir '#{dir}' does not exist, creating it."
9
- FileUtils.mkdir_p dir
10
- end
11
- return dir
12
- end
1
+ module Squib::Args::DirValidator
13
2
 
3
+ def ensure_dir_created(dir)
4
+ unless Dir.exists?(dir)
5
+ Squib.logger.warn "Dir '#{dir}' does not exist, creating it."
6
+ FileUtils.mkdir_p dir
14
7
  end
8
+ return dir
15
9
  end
10
+
16
11
  end
@@ -2,91 +2,92 @@ require 'cairo'
2
2
  require_relative 'arg_loader'
3
3
  require_relative 'color_validator'
4
4
 
5
- module Squib
6
- # @api private
7
- module Args
5
+ module Squib::Args
8
6
 
9
- class Draw
10
- include ArgLoader
11
- include ColorValidator
7
+ module_function def extract_draw(opts, deck, dsl_method_defaults = {})
8
+ Draw.new(deck.custom_colors, dsl_method_defaults).extract!(opts, deck)
9
+ end
12
10
 
13
- def initialize(custom_colors, dsl_method_defaults = {})
14
- @custom_colors = custom_colors
15
- @dsl_method_defaults = dsl_method_defaults
16
- end
11
+ class Draw
12
+ include ArgLoader
13
+ include ColorValidator
17
14
 
18
- def self.parameters
19
- { color: :black,
20
- fill_color: '#0000',
21
- stroke_color: :black,
22
- stroke_width: 2.0,
23
- stroke_strategy: :fill_first,
24
- join: :miter,
25
- cap: 'butt',
26
- dash: ''
27
- }
28
- end
15
+ def initialize(custom_colors, dsl_method_defaults = {})
16
+ @custom_colors = custom_colors
17
+ @dsl_method_defaults = dsl_method_defaults
18
+ end
29
19
 
30
- def self.expanding_parameters
31
- parameters.keys # all of them are expandable
32
- end
20
+ def self.parameters
21
+ { color: :black,
22
+ fill_color: '#0000',
23
+ stroke_color: :black,
24
+ stroke_width: 2.0,
25
+ stroke_strategy: :fill_first,
26
+ join: :miter,
27
+ cap: 'butt',
28
+ dash: ''
29
+ }
30
+ end
33
31
 
34
- def self.params_with_units
35
- [:stroke_width]
36
- end
32
+ def self.expanding_parameters
33
+ parameters.keys # all of them are expandable
34
+ end
37
35
 
38
- def validate_join(arg, _i)
39
- case arg.to_s.strip.downcase
40
- when 'miter'
41
- Cairo::LINE_JOIN_MITER
42
- when 'round'
43
- Cairo::LINE_JOIN_ROUND
44
- when 'bevel'
45
- Cairo::LINE_JOIN_BEVEL
46
- end
47
- end
36
+ def self.params_with_units
37
+ [:stroke_width]
38
+ end
48
39
 
49
- def validate_cap(arg, _i)
50
- case arg.to_s.strip.downcase
51
- when 'butt'
52
- Cairo::LINE_CAP_BUTT
53
- when 'round'
54
- Cairo::LINE_CAP_ROUND
55
- when 'square'
56
- Cairo::LINE_CAP_SQUARE
57
- end
40
+ def validate_join(arg, _i)
41
+ case arg.to_s.strip.downcase
42
+ when 'miter'
43
+ Cairo::LINE_JOIN_MITER
44
+ when 'round'
45
+ Cairo::LINE_JOIN_ROUND
46
+ when 'bevel'
47
+ Cairo::LINE_JOIN_BEVEL
58
48
  end
49
+ end
59
50
 
60
- def validate_dash(arg, _i)
61
- arg.to_s.split.collect do |x|
62
- UnitConversion.parse(x, @dpi).to_f
63
- end
51
+ def validate_cap(arg, _i)
52
+ case arg.to_s.strip.downcase
53
+ when 'butt'
54
+ Cairo::LINE_CAP_BUTT
55
+ when 'round'
56
+ Cairo::LINE_CAP_ROUND
57
+ when 'square'
58
+ Cairo::LINE_CAP_SQUARE
64
59
  end
60
+ end
65
61
 
66
- def validate_fill_color(arg, _i)
67
- colorify(arg, @custom_colors)
62
+ def validate_dash(arg, _i)
63
+ arg.to_s.split.collect do |x|
64
+ UnitConversion.parse(x, @dpi, @cell_px).to_f
68
65
  end
66
+ end
69
67
 
70
- def validate_stroke_color(arg, _i)
71
- colorify(arg, @custom_colors)
72
- end
68
+ def validate_fill_color(arg, _i)
69
+ colorify(arg, @custom_colors)
70
+ end
73
71
 
74
- def validate_color(arg, _i)
75
- colorify(arg, @custom_colors)
76
- end
72
+ def validate_stroke_color(arg, _i)
73
+ colorify(arg, @custom_colors)
74
+ end
77
75
 
78
- def validate_stroke_strategy(arg, _i)
79
- case arg.to_s.downcase.strip
80
- when 'fill_first'
81
- :fill_first
82
- when 'stroke_first'
83
- :stroke_first
84
- else
85
- raise "Only 'stroke_first' or 'fill_first' allowed"
86
- end
87
- end
76
+ def validate_color(arg, _i)
77
+ colorify(arg, @custom_colors)
78
+ end
88
79
 
80
+ def validate_stroke_strategy(arg, _i)
81
+ case arg.to_s.downcase.strip
82
+ when 'fill_first'
83
+ :fill_first
84
+ when 'stroke_first'
85
+ :stroke_first
86
+ else
87
+ raise "Only 'stroke_first' or 'fill_first' allowed"
88
+ end
89
89
  end
90
90
 
91
91
  end
92
+
92
93
  end