squib 0.15.3 → 0.16.0.pre.preview1

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.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +22 -0
  3. data/CHANGELOG.md +22 -0
  4. data/Dockerfile +18 -16
  5. data/Guardfile +8 -0
  6. data/README.md +3 -9
  7. data/RELEASE TODO.md +1 -0
  8. data/Rakefile +3 -0
  9. data/lib/squib.rb +3 -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/embed_adjust.rb +12 -15
  19. data/lib/squib/args/embed_key.rb +6 -11
  20. data/lib/squib/args/hand_special.rb +25 -25
  21. data/lib/squib/args/import.rb +54 -27
  22. data/lib/squib/args/input_file.rb +22 -26
  23. data/lib/squib/args/paint.rb +30 -31
  24. data/lib/squib/args/paragraph.rb +95 -93
  25. data/lib/squib/args/save_batch.rb +50 -48
  26. data/lib/squib/args/scale_box.rb +43 -39
  27. data/lib/squib/args/sheet.rb +147 -149
  28. data/lib/squib/args/showcase_special.rb +32 -32
  29. data/lib/squib/args/sprue_file.rb +30 -30
  30. data/lib/squib/args/svg_special.rb +26 -26
  31. data/lib/squib/args/transform.rb +48 -54
  32. data/lib/squib/args/typographer.rb +88 -92
  33. data/lib/squib/args/unit_conversion.rb +6 -8
  34. data/lib/squib/args/xywh_shorthands.rb +56 -0
  35. data/lib/squib/builtin/projects/advanced/config.yml +4 -3
  36. data/lib/squib/builtin/projects/basic/config.yml +4 -3
  37. data/lib/squib/conf.rb +5 -0
  38. data/lib/squib/deck.rb +34 -12
  39. data/lib/squib/dsl/background.rb +35 -0
  40. data/lib/squib/dsl/circle.rb +39 -0
  41. data/lib/squib/dsl/csv.rb +42 -0
  42. data/lib/squib/dsl/curve.rb +35 -0
  43. data/lib/squib/dsl/cut_zone.rb +47 -0
  44. data/lib/squib/dsl/ellipse.rb +37 -0
  45. data/lib/squib/dsl/grid.rb +35 -0
  46. data/lib/squib/{api → dsl}/groups.rb +0 -0
  47. data/lib/squib/dsl/hand.rb +42 -0
  48. data/lib/squib/dsl/line.rb +35 -0
  49. data/lib/squib/dsl/png.rb +56 -0
  50. data/lib/squib/dsl/polygon.rb +36 -0
  51. data/lib/squib/dsl/rect.rb +37 -0
  52. data/lib/squib/dsl/safe_zone.rb +48 -0
  53. data/lib/squib/dsl/save.rb +21 -0
  54. data/lib/squib/dsl/save_pdf.rb +50 -0
  55. data/lib/squib/dsl/save_png.rb +47 -0
  56. data/lib/squib/dsl/save_sheet.rb +53 -0
  57. data/lib/squib/dsl/showcase.rb +43 -0
  58. data/lib/squib/dsl/star.rb +37 -0
  59. data/lib/squib/dsl/svg.rb +62 -0
  60. data/lib/squib/dsl/text.rb +54 -0
  61. data/lib/squib/dsl/text_embed.rb +78 -0
  62. data/lib/squib/dsl/triangle.rb +35 -0
  63. data/lib/squib/{api → dsl}/units.rb +10 -0
  64. data/lib/squib/dsl/xlsx.rb +40 -0
  65. data/lib/squib/dsl/yaml.rb +40 -0
  66. data/lib/squib/errors_warnings/warn_unexpected_params.rb +14 -0
  67. data/lib/squib/graphics/save_images.rb +3 -3
  68. data/lib/squib/graphics/save_sprue.rb +14 -2
  69. data/lib/squib/graphics/text.rb +37 -9
  70. data/lib/squib/import/csv_importer.rb +45 -0
  71. data/lib/squib/import/quantity_exploder.rb +18 -0
  72. data/lib/squib/import/xlsx_importer.rb +28 -0
  73. data/lib/squib/import/yaml_importer.rb +30 -0
  74. data/lib/squib/layout_parser.rb +24 -7
  75. data/lib/squib/sprues/crop_line.rb +6 -6
  76. data/lib/squib/sprues/crop_line_dash.rb +6 -6
  77. data/lib/squib/sprues/sprue.rb +16 -14
  78. data/lib/squib/version.rb +1 -1
  79. data/samples/autoscale_font/_autoscale_font.rb +77 -8
  80. data/samples/colors/_switch_color.rb +2 -2
  81. data/samples/data/_excel.rb +1 -1
  82. data/samples/ranges/_ranges.rb +1 -1
  83. data/samples/saves/_save_filenames.rb +4 -0
  84. data/samples/saves/_save_pdf.rb +1 -1
  85. data/samples/saves/_saves.rb +2 -1
  86. data/samples/shapes/_draw_shapes.rb +2 -2
  87. data/samples/sprues/_builtin_sprues.rb +1 -0
  88. data/samples/sprues/_fold_sheet.rb +4 -1
  89. data/samples/text/_text.rb +6 -1
  90. data/samples/text/_text_options.rb +2 -1
  91. data/samples/units/_cells.rb +51 -0
  92. data/samples/units/_shorthands.rb +49 -0
  93. data/samples/units/_units.rb +7 -0
  94. data/squib.gemspec +11 -5
  95. metadata +120 -33
  96. data/.travis.yml +0 -17
  97. data/appveyor.yml +0 -25
  98. data/lib/squib/api/background.rb +0 -15
  99. data/lib/squib/api/data.rb +0 -137
  100. data/lib/squib/api/image.rb +0 -49
  101. data/lib/squib/api/save.rb +0 -83
  102. data/lib/squib/api/shapes.rb +0 -124
  103. data/lib/squib/api/text.rb +0 -25
  104. data/lib/squib/api/text_embed.rb +0 -71
@@ -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
@@ -1,25 +1,22 @@
1
1
  require_relative 'arg_loader'
2
2
 
3
- module Squib
4
- # @api private
5
- module Args
3
+ module Squib::Args
6
4
 
7
- class EmbedAdjust
8
- include ArgLoader
5
+ class EmbedAdjust
6
+ include ArgLoader
9
7
 
10
- def self.parameters
11
- { dx: 0, dy: 0 }
12
- end
13
-
14
- def self.expanding_parameters
15
- parameters.keys # all of them
16
- end
8
+ def self.parameters
9
+ { dx: 0, dy: 0 }
10
+ end
17
11
 
18
- def self.params_with_units
19
- parameters.keys # all of them
20
- end
12
+ def self.expanding_parameters
13
+ parameters.keys # all of them
14
+ end
21
15
 
16
+ def self.params_with_units
17
+ parameters.keys # all of them
22
18
  end
23
19
 
24
20
  end
21
+
25
22
  end
@@ -1,17 +1,12 @@
1
1
  require_relative 'arg_loader'
2
2
 
3
- module Squib
4
- # @api private
5
- module Args
6
-
7
- class EmbedKey
8
-
9
- # Validate the embed lookup key
10
- def validate_key(str)
11
- str.to_s
12
- end
3
+ module Squib::Args
4
+ class EmbedKey
13
5
 
6
+ # Validate the embed lookup key
7
+ def validate_key(str)
8
+ str.to_s
14
9
  end
15
-
10
+
16
11
  end
17
12
  end
@@ -1,37 +1,37 @@
1
1
  require 'cairo'
2
2
 
3
- module Squib
4
- # @api private
5
- module Args
6
-
7
- class HandSpecial
8
- include ArgLoader
3
+ module Squib::Args
4
+ module_function def extract_hand_special(opts, deck)
5
+ HandSpecial.new(deck.height).extract! opts, deck
6
+ end
9
7
 
10
- def initialize(card_height)
11
- @card_height = card_height
12
- end
8
+ class HandSpecial
9
+ include ArgLoader
13
10
 
14
- def self.parameters
15
- {
16
- angle_range: (Math::PI / -4.0)..(Math::PI / 4),
17
- radius: :auto
18
- }
19
- end
11
+ def initialize(card_height)
12
+ @card_height = card_height
13
+ end
20
14
 
21
- def self.expanding_parameters
22
- [] # none of them
23
- end
15
+ def self.parameters
16
+ {
17
+ angle_range: (Math::PI / -4.0)..(Math::PI / 4),
18
+ radius: :auto
19
+ }
20
+ end
24
21
 
25
- def self.params_with_units
26
- [ :radius ]
27
- end
22
+ def self.expanding_parameters
23
+ [] # none of them
24
+ end
28
25
 
29
- def validate_radius(arg)
30
- return 0.3 * @card_height if arg.to_s.downcase.strip == 'auto'
31
- arg
32
- end
26
+ def self.params_with_units
27
+ [ :radius ]
28
+ end
33
29
 
30
+ def validate_radius(arg)
31
+ return 0.3 * @card_height if arg.to_s.downcase.strip == 'auto'
32
+ arg
34
33
  end
35
34
 
36
35
  end
36
+
37
37
  end