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.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +22 -0
- data/CHANGELOG.md +22 -0
- data/Dockerfile +18 -16
- data/Guardfile +8 -0
- data/README.md +3 -9
- data/RELEASE TODO.md +1 -0
- data/Rakefile +3 -0
- data/lib/squib.rb +3 -1
- data/lib/squib/args/arg_loader.rb +109 -106
- data/lib/squib/args/box.rb +52 -48
- data/lib/squib/args/card_range.rb +26 -24
- data/lib/squib/args/color_validator.rb +4 -9
- data/lib/squib/args/coords.rb +39 -25
- data/lib/squib/args/csv_opts.rb +13 -16
- data/lib/squib/args/dir_validator.rb +7 -12
- data/lib/squib/args/draw.rb +69 -68
- data/lib/squib/args/embed_adjust.rb +12 -15
- data/lib/squib/args/embed_key.rb +6 -11
- data/lib/squib/args/hand_special.rb +25 -25
- data/lib/squib/args/import.rb +54 -27
- data/lib/squib/args/input_file.rb +22 -26
- data/lib/squib/args/paint.rb +30 -31
- data/lib/squib/args/paragraph.rb +95 -93
- data/lib/squib/args/save_batch.rb +50 -48
- data/lib/squib/args/scale_box.rb +43 -39
- data/lib/squib/args/sheet.rb +147 -149
- data/lib/squib/args/showcase_special.rb +32 -32
- data/lib/squib/args/sprue_file.rb +30 -30
- data/lib/squib/args/svg_special.rb +26 -26
- data/lib/squib/args/transform.rb +48 -54
- data/lib/squib/args/typographer.rb +88 -92
- data/lib/squib/args/unit_conversion.rb +6 -8
- data/lib/squib/args/xywh_shorthands.rb +56 -0
- data/lib/squib/builtin/projects/advanced/config.yml +4 -3
- data/lib/squib/builtin/projects/basic/config.yml +4 -3
- data/lib/squib/conf.rb +5 -0
- data/lib/squib/deck.rb +34 -12
- data/lib/squib/dsl/background.rb +35 -0
- data/lib/squib/dsl/circle.rb +39 -0
- data/lib/squib/dsl/csv.rb +42 -0
- data/lib/squib/dsl/curve.rb +35 -0
- data/lib/squib/dsl/cut_zone.rb +47 -0
- data/lib/squib/dsl/ellipse.rb +37 -0
- data/lib/squib/dsl/grid.rb +35 -0
- data/lib/squib/{api → dsl}/groups.rb +0 -0
- data/lib/squib/dsl/hand.rb +42 -0
- data/lib/squib/dsl/line.rb +35 -0
- data/lib/squib/dsl/png.rb +56 -0
- data/lib/squib/dsl/polygon.rb +36 -0
- data/lib/squib/dsl/rect.rb +37 -0
- data/lib/squib/dsl/safe_zone.rb +48 -0
- data/lib/squib/dsl/save.rb +21 -0
- data/lib/squib/dsl/save_pdf.rb +50 -0
- data/lib/squib/dsl/save_png.rb +47 -0
- data/lib/squib/dsl/save_sheet.rb +53 -0
- data/lib/squib/dsl/showcase.rb +43 -0
- data/lib/squib/dsl/star.rb +37 -0
- data/lib/squib/dsl/svg.rb +62 -0
- data/lib/squib/dsl/text.rb +54 -0
- data/lib/squib/dsl/text_embed.rb +78 -0
- data/lib/squib/dsl/triangle.rb +35 -0
- data/lib/squib/{api → dsl}/units.rb +10 -0
- data/lib/squib/dsl/xlsx.rb +40 -0
- data/lib/squib/dsl/yaml.rb +40 -0
- data/lib/squib/errors_warnings/warn_unexpected_params.rb +14 -0
- data/lib/squib/graphics/save_images.rb +3 -3
- data/lib/squib/graphics/save_sprue.rb +14 -2
- data/lib/squib/graphics/text.rb +37 -9
- data/lib/squib/import/csv_importer.rb +45 -0
- data/lib/squib/import/quantity_exploder.rb +18 -0
- data/lib/squib/import/xlsx_importer.rb +28 -0
- data/lib/squib/import/yaml_importer.rb +30 -0
- data/lib/squib/layout_parser.rb +24 -7
- data/lib/squib/sprues/crop_line.rb +6 -6
- data/lib/squib/sprues/crop_line_dash.rb +6 -6
- data/lib/squib/sprues/sprue.rb +16 -14
- data/lib/squib/version.rb +1 -1
- data/samples/autoscale_font/_autoscale_font.rb +77 -8
- data/samples/colors/_switch_color.rb +2 -2
- data/samples/data/_excel.rb +1 -1
- data/samples/ranges/_ranges.rb +1 -1
- data/samples/saves/_save_filenames.rb +4 -0
- data/samples/saves/_save_pdf.rb +1 -1
- data/samples/saves/_saves.rb +2 -1
- data/samples/shapes/_draw_shapes.rb +2 -2
- data/samples/sprues/_builtin_sprues.rb +1 -0
- data/samples/sprues/_fold_sheet.rb +4 -1
- data/samples/text/_text.rb +6 -1
- data/samples/text/_text_options.rb +2 -1
- data/samples/units/_cells.rb +51 -0
- data/samples/units/_shorthands.rb +49 -0
- data/samples/units/_units.rb +7 -0
- data/squib.gemspec +11 -5
- metadata +120 -33
- data/.travis.yml +0 -17
- data/appveyor.yml +0 -25
- data/lib/squib/api/background.rb +0 -15
- data/lib/squib/api/data.rb +0 -137
- data/lib/squib/api/image.rb +0 -49
- data/lib/squib/api/save.rb +0 -83
- data/lib/squib/api/shapes.rb +0 -124
- data/lib/squib/api/text.rb +0 -25
- 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
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
10
|
+
def initialize(input, deck_size: 1)
|
11
|
+
@range = validate(input, deck_size)
|
12
|
+
end
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
# Hook into enumerable by delegating to @range
|
15
|
+
def each(&block)
|
16
|
+
@range.each { |i| block.call(i) }
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
7
|
-
|
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
|
data/lib/squib/args/coords.rb
CHANGED
@@ -1,35 +1,49 @@
|
|
1
1
|
require_relative 'arg_loader'
|
2
|
+
require_relative 'xywh_shorthands'
|
2
3
|
|
3
|
-
module Squib
|
4
|
-
|
5
|
-
|
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
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
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
|
data/lib/squib/args/csv_opts.rb
CHANGED
@@ -1,25 +1,22 @@
|
|
1
1
|
require 'csv'
|
2
2
|
|
3
|
-
module Squib
|
4
|
-
|
5
|
-
module Args
|
6
|
-
class CSV_Opts
|
3
|
+
module Squib::Args
|
4
|
+
class CSV_Opts
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
11
|
+
def to_hash
|
12
|
+
@hash
|
13
|
+
end
|
18
14
|
|
19
|
-
|
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
|
data/lib/squib/args/draw.rb
CHANGED
@@ -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
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
11
|
+
class Draw
|
12
|
+
include ArgLoader
|
13
|
+
include ColorValidator
|
17
14
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
32
|
+
def self.expanding_parameters
|
33
|
+
parameters.keys # all of them are expandable
|
34
|
+
end
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
67
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
68
|
+
def validate_fill_color(arg, _i)
|
69
|
+
colorify(arg, @custom_colors)
|
70
|
+
end
|
73
71
|
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
def validate_stroke_color(arg, _i)
|
73
|
+
colorify(arg, @custom_colors)
|
74
|
+
end
|
77
75
|
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
-
|
8
|
-
|
5
|
+
class EmbedAdjust
|
6
|
+
include ArgLoader
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
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
|
data/lib/squib/args/embed_key.rb
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
require_relative 'arg_loader'
|
2
2
|
|
3
|
-
module Squib
|
4
|
-
|
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
|
-
|
5
|
-
|
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
|
-
|
11
|
-
|
12
|
-
end
|
8
|
+
class HandSpecial
|
9
|
+
include ArgLoader
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
radius: :auto
|
18
|
-
}
|
19
|
-
end
|
11
|
+
def initialize(card_height)
|
12
|
+
@card_height = card_height
|
13
|
+
end
|
20
14
|
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
def self.parameters
|
16
|
+
{
|
17
|
+
angle_range: (Math::PI / -4.0)..(Math::PI / 4),
|
18
|
+
radius: :auto
|
19
|
+
}
|
20
|
+
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
def self.expanding_parameters
|
23
|
+
[] # none of them
|
24
|
+
end
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|