squib 0.14.3.pre1 → 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 +58 -2
- data/Dockerfile +27 -0
- data/Guardfile +8 -0
- data/README.md +24 -6
- 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 -29
- 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 +3 -6
- data/lib/squib/builtin/projects/basic/config.yml +3 -6
- data/lib/squib/commands/make_sprue.rb +2 -0
- data/lib/squib/conf.rb +5 -5
- 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/cairo_context_wrapper.rb +2 -2
- data/lib/squib/graphics/image.rb +0 -6
- data/lib/squib/graphics/save_images.rb +3 -3
- data/lib/squib/graphics/save_sprue.rb +39 -12
- data/lib/squib/graphics/showcase.rb +1 -1
- 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 +19 -14
- data/lib/squib/sprues/sprue_schema.rb +4 -2
- data/lib/squib/version.rb +1 -1
- data/samples/autoscale_font/_autoscale_font.rb +77 -8
- data/samples/colors/_colors.rb +11 -5
- data/samples/colors/_switch_color.rb +33 -0
- data/samples/data/_excel.rb +1 -1
- data/samples/images/_more_load_images.rb +1 -1
- data/samples/ranges/_ranges.rb +1 -1
- data/samples/saves/_save_filenames.rb +28 -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/_advanced_sprues.rb +4 -3
- 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 +19 -13
- metadata +151 -61
- data/.travis.yml +0 -19
- data/appveyor.yml +0 -24
- 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
- data/samples/bug256/_bug256.rb +0 -13
@@ -3,21 +3,21 @@ module Squib
|
|
3
3
|
class CropLine
|
4
4
|
attr_reader :x1, :y1, :x2, :y2
|
5
5
|
|
6
|
-
def initialize(type, position, sheet_width, sheet_height, dpi)
|
6
|
+
def initialize(type, position, sheet_width, sheet_height, dpi, cell_px)
|
7
7
|
method = "parse_#{type}"
|
8
|
-
send method, position, sheet_width, sheet_height, dpi
|
8
|
+
send method, position, sheet_width, sheet_height, dpi, cell_px
|
9
9
|
end
|
10
10
|
|
11
|
-
def parse_horizontal(position, sheet_width, _, dpi)
|
12
|
-
position = Args::UnitConversion.parse(position, dpi)
|
11
|
+
def parse_horizontal(position, sheet_width, _, dpi, cell_px)
|
12
|
+
position = Args::UnitConversion.parse(position, dpi, cell_px)
|
13
13
|
@x1 = 0
|
14
14
|
@y1 = position
|
15
15
|
@x2 = sheet_width
|
16
16
|
@y2 = position
|
17
17
|
end
|
18
18
|
|
19
|
-
def parse_vertical(position, _, sheet_height, dpi)
|
20
|
-
position = Args::UnitConversion.parse(position, dpi)
|
19
|
+
def parse_vertical(position, _, sheet_height, dpi, cell_px)
|
20
|
+
position = Args::UnitConversion.parse(position, dpi, cell_px)
|
21
21
|
@x1 = position
|
22
22
|
@y1 = 0
|
23
23
|
@x2 = position
|
@@ -9,22 +9,22 @@ module Squib
|
|
9
9
|
|
10
10
|
attr_reader :pattern
|
11
11
|
|
12
|
-
def initialize(value, dpi)
|
12
|
+
def initialize(value, dpi, cell_px)
|
13
13
|
if value == :solid
|
14
14
|
@pattern = nil
|
15
15
|
elsif value == :dotted
|
16
16
|
@pattern = [
|
17
|
-
Args::UnitConversion.parse('0.2mm', dpi),
|
18
|
-
Args::UnitConversion.parse('0.5mm', dpi)
|
17
|
+
Args::UnitConversion.parse('0.2mm', dpi, cell_px),
|
18
|
+
Args::UnitConversion.parse('0.5mm', dpi, cell_px)
|
19
19
|
]
|
20
20
|
elsif value == :dashed
|
21
21
|
@pattern = [
|
22
|
-
Args::UnitConversion.parse('2mm', dpi),
|
23
|
-
Args::UnitConversion.parse('2mm', dpi)
|
22
|
+
Args::UnitConversion.parse('2mm', dpi, cell_px),
|
23
|
+
Args::UnitConversion.parse('2mm', dpi, cell_px)
|
24
24
|
]
|
25
25
|
elsif value.is_a? String
|
26
26
|
@pattern = value.split(' ').map do |val|
|
27
|
-
Args::UnitConversion.parse val, dpi
|
27
|
+
Args::UnitConversion.parse val, dpi, cell_px
|
28
28
|
end
|
29
29
|
else
|
30
30
|
raise ArgumentError, 'Unsupported dash style'
|
data/lib/squib/sprues/sprue.rb
CHANGED
@@ -18,6 +18,7 @@ module Squib
|
|
18
18
|
'card_width' => nil,
|
19
19
|
'card_height' => nil,
|
20
20
|
'dpi' => 300,
|
21
|
+
'cell_px' => 37.5,
|
21
22
|
'position_reference' => :topleft,
|
22
23
|
'rotate' => 0.0,
|
23
24
|
'crop_line' => {
|
@@ -32,16 +33,17 @@ module Squib
|
|
32
33
|
|
33
34
|
attr_reader :dpi
|
34
35
|
|
35
|
-
def initialize(template_hash, dpi)
|
36
|
+
def initialize(template_hash, dpi, cell_px)
|
36
37
|
@template_hash = template_hash
|
37
38
|
@dpi = dpi
|
39
|
+
@cell_px = cell_px
|
38
40
|
@crop_line_default = @template_hash['crop_line'].select do |k, _|
|
39
41
|
%w[style width color].include? k
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
43
45
|
# Load the template definition file
|
44
|
-
def self.load(file, dpi)
|
46
|
+
def self.load(file, dpi, cell_px)
|
45
47
|
yaml = {}
|
46
48
|
thefile = file if File.exist?(file) # use custom first
|
47
49
|
thefile = builtin(file) if File.exist?(builtin(file)) # then builtin
|
@@ -62,23 +64,23 @@ module Squib
|
|
62
64
|
rescue ClassyHash::SchemaViolationError => e
|
63
65
|
raise Sprues::InvalidSprueDefinition.new(thefile, e)
|
64
66
|
end
|
65
|
-
Sprue.new new_hash, dpi
|
67
|
+
Sprue.new new_hash, dpi, cell_px
|
66
68
|
end
|
67
69
|
|
68
70
|
def sheet_width
|
69
|
-
Args::UnitConversion.parse @template_hash['sheet_width'], @dpi
|
71
|
+
Args::UnitConversion.parse @template_hash['sheet_width'], @dpi, @cell_px
|
70
72
|
end
|
71
73
|
|
72
74
|
def sheet_height
|
73
|
-
Args::UnitConversion.parse @template_hash['sheet_height'], @dpi
|
75
|
+
Args::UnitConversion.parse @template_hash['sheet_height'], @dpi, @cell_px
|
74
76
|
end
|
75
77
|
|
76
78
|
def card_width
|
77
|
-
Args::UnitConversion.parse @template_hash['card_width'], @dpi
|
79
|
+
Args::UnitConversion.parse @template_hash['card_width'], @dpi, @cell_px
|
78
80
|
end
|
79
81
|
|
80
82
|
def card_height
|
81
|
-
Args::UnitConversion.parse @template_hash['card_height'], @dpi
|
83
|
+
Args::UnitConversion.parse @template_hash['card_height'], @dpi, @cell_px
|
82
84
|
end
|
83
85
|
|
84
86
|
def card_default_rotation
|
@@ -113,8 +115,8 @@ module Squib
|
|
113
115
|
# NOTE: There's a baseline of 0.25mm that we can 100% make sure that we
|
114
116
|
# can overlap really thin lines on the PDF
|
115
117
|
crop_line_width = [
|
116
|
-
Args::UnitConversion.parse(@template_hash['crop_line']['width'], @dpi),
|
117
|
-
Args::UnitConversion.parse('0.25mm', @dpi)
|
118
|
+
Args::UnitConversion.parse(@template_hash['crop_line']['width'], @dpi, @cell_px),
|
119
|
+
Args::UnitConversion.parse('0.25mm', @dpi, @cell_px)
|
118
120
|
].max
|
119
121
|
|
120
122
|
parsed_cards = cards
|
@@ -149,12 +151,12 @@ module Squib
|
|
149
151
|
# Parse crop line definitions from template.
|
150
152
|
def parse_crop_line(line)
|
151
153
|
new_line = @crop_line_default.merge line
|
152
|
-
new_line['width'] = Args::UnitConversion.parse(new_line['width'], @dpi)
|
154
|
+
new_line['width'] = Args::UnitConversion.parse(new_line['width'], @dpi, @cell_px)
|
153
155
|
new_line['color'] = colorify new_line['color']
|
154
156
|
new_line['style_desc'] = new_line['style']
|
155
|
-
new_line['style'] = Sprues::CropLineDash.new(new_line['style'], @dpi)
|
157
|
+
new_line['style'] = Sprues::CropLineDash.new(new_line['style'], @dpi, @cell_px)
|
156
158
|
new_line['line'] = Sprues::CropLine.new(
|
157
|
-
new_line['type'], new_line['position'], sheet_width, sheet_height, @dpi
|
159
|
+
new_line['type'], new_line['position'], sheet_width, sheet_height, @dpi, @cell_px
|
158
160
|
)
|
159
161
|
new_line
|
160
162
|
end
|
@@ -163,8 +165,8 @@ module Squib
|
|
163
165
|
def parse_card(card)
|
164
166
|
new_card = card.clone
|
165
167
|
|
166
|
-
x = Args::UnitConversion.parse(card['x'], @dpi)
|
167
|
-
y = Args::UnitConversion.parse(card['y'], @dpi)
|
168
|
+
x = Args::UnitConversion.parse(card['x'], @dpi, @cell_px)
|
169
|
+
y = Args::UnitConversion.parse(card['y'], @dpi, @cell_px)
|
168
170
|
if @template_hash['position_reference'] == :center
|
169
171
|
# Normalize it to a top-left positional reference
|
170
172
|
x -= card_width / 2
|
@@ -175,6 +177,8 @@ module Squib
|
|
175
177
|
new_card['y'] = y
|
176
178
|
new_card['rotate'] = parse_rotate_param(
|
177
179
|
card['rotate'] ? card['rotate'] : @template_hash['rotate'])
|
180
|
+
new_card['flip_vertical'] = card['flip_vertical'] == true
|
181
|
+
new_card['flip_horizontal'] = card['flip_horizontal'] == true
|
178
182
|
new_card
|
179
183
|
end
|
180
184
|
|
@@ -199,5 +203,6 @@ module Squib
|
|
199
203
|
val.to_f
|
200
204
|
end
|
201
205
|
end
|
206
|
+
|
202
207
|
end
|
203
208
|
end
|
@@ -41,8 +41,10 @@ module Squib
|
|
41
41
|
:optional, Numeric,
|
42
42
|
ClassyHash::G.enum(:clockwise, :counterclockwise, :turnaround),
|
43
43
|
ROTATE_REGEX
|
44
|
-
]
|
45
|
-
|
44
|
+
],
|
45
|
+
'flip_vertical' => [ :optional, FalseClass ],
|
46
|
+
'flip_horizontal' => [ :optional, FalseClass ],
|
47
|
+
}]]
|
46
48
|
}.freeze
|
47
49
|
end
|
48
50
|
end
|
data/lib/squib/version.rb
CHANGED
@@ -1,13 +1,79 @@
|
|
1
1
|
require 'squib'
|
2
2
|
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
3
|
+
# Autoscaling font is handy for a bunch of things:
|
4
|
+
# * Picture-perfect text fitting for one-off
|
5
|
+
# * Rapid prototyping where you don't have to think about sizes
|
6
|
+
#
|
7
|
+
# We've got three options...
|
8
|
+
# Option 1. Use your data <--- good for picture-perfect
|
9
|
+
# Option 2. Use ellipsize: :autoscale <--- good for rapid prototyping
|
10
|
+
# Option 3. Use map ranges in your code <--- good for picture-perfect
|
11
|
+
# or other weird cases
|
12
|
+
|
13
|
+
###########################
|
14
|
+
# Option 1: Use your data #
|
15
|
+
###########################
|
16
|
+
# If you want to tweak the font size per-card, you can always make font_size
|
17
|
+
# a column and map it from there. This is tedious but leads to perfectly
|
18
|
+
# customized results
|
19
|
+
my_data = Squib.csv data: <<~CSV
|
20
|
+
"Title","Font Size"
|
21
|
+
"Short & Big",10
|
22
|
+
"Medium Length & Size", 5
|
23
|
+
"Super duper long string here, therefore a smaller font.", 4
|
24
|
+
CSV
|
25
|
+
|
26
|
+
Squib::Deck.new(width: 300, height: 75, cards: 3) do
|
27
|
+
background color: :white
|
28
|
+
rect stroke_color: :black
|
29
|
+
|
30
|
+
text str: my_data.title, font: 'Arial',
|
31
|
+
font_size: my_data.font_size, # <-- key part
|
32
|
+
x: 10, y:10, align: :center,
|
33
|
+
width: 280, # <-- note how height does NOT need to be set
|
34
|
+
ellipsize: false,
|
35
|
+
hint: :red
|
36
|
+
save_sheet columns: 3, prefix: 'autoscale_w_data_'
|
37
|
+
end
|
38
|
+
|
39
|
+
#######################################
|
40
|
+
# Option 2: Use ellipsize: :autoscale #
|
41
|
+
#######################################
|
42
|
+
# If set the height, you can set "autoscale" and it will incrementally
|
43
|
+
# downgrade the font size until the text does not ellipsize
|
44
|
+
#
|
45
|
+
# Great for rapid prototyping, set-it-and-forget-it
|
46
|
+
#
|
47
|
+
# NOTE: You MUST set the height for this to work. Otherwise, the text will
|
48
|
+
# never ellipsize and Squib doesn't know when to start autoscaling
|
49
|
+
Squib::Deck.new(width: 300, height: 75, cards: 3) do
|
50
|
+
background color: :white
|
51
|
+
rect stroke_color: :black
|
52
|
+
title = ['Short & Big',
|
53
|
+
'Medium Length & Size',
|
54
|
+
'Super duper long string here, therefore a smaller font.']
|
55
|
+
|
56
|
+
# Automatically scale the text down from the specified font_size to the largest size that fits
|
57
|
+
text str: title, font: 'Arial',
|
58
|
+
font_size: 15, # <-- this is the MAX font size. Scale down from here
|
59
|
+
ellipsize: :autoscale, # <-- key part
|
60
|
+
height: 50, # <-- need this to be set to something
|
61
|
+
width: 280, x: 10, y: 10, align: :center, valign: :middle, hint: :red
|
62
|
+
|
63
|
+
save_sheet columns: 3, prefix: 'autoscale_w_ellipsize_'
|
64
|
+
end
|
65
|
+
|
66
|
+
############################################
|
67
|
+
# Option 3: Mapping to ranges in your code #
|
68
|
+
############################################
|
69
|
+
# Here's an in-between option that allows you to programmatically apply font
|
70
|
+
# sizes. This allows you a ton of flexibility.Probably more flexibility than
|
71
|
+
# you need, frankly. But one advantage is that you don't have to set the height
|
6
72
|
def autoscale(str_array)
|
7
73
|
str_array.map do | str |
|
8
74
|
case str.length
|
9
75
|
when 0..15
|
10
|
-
|
76
|
+
9
|
11
77
|
when 16..20
|
12
78
|
6
|
13
79
|
else
|
@@ -16,14 +82,17 @@ def autoscale(str_array)
|
|
16
82
|
end
|
17
83
|
end
|
18
84
|
|
19
|
-
Squib::Deck.new(width: 300, height:
|
85
|
+
Squib::Deck.new(width: 300, height: 75, cards: 3) do
|
20
86
|
background color: :white
|
21
|
-
rect
|
87
|
+
rect stroke_color: :black
|
22
88
|
title = ['Short & Big',
|
23
89
|
'Medium Length & Size',
|
24
90
|
'Super duper long string here, therefore a smaller font.']
|
25
|
-
|
91
|
+
|
92
|
+
# Scale text based on the string length
|
93
|
+
text str: title, font: 'Arial',
|
94
|
+
font_size: autoscale(title), # <-- key part
|
26
95
|
x: 10, y:10, align: :center, width: 280, ellipsize: false, hint: :red
|
27
96
|
|
28
|
-
|
97
|
+
save_sheet columns: 3, prefix: 'autoscale_w_range_'
|
29
98
|
end
|
data/samples/colors/_colors.rb
CHANGED
@@ -19,17 +19,23 @@ Squib::Deck.new(width: 825, height: 1125, cards: 1) do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
# This script generates a table of the built-in constants
|
22
|
-
|
22
|
+
colors = (Cairo::Color.constants - %i(HEX_RE Base RGB CMYK HSV X11))
|
23
|
+
colors.sort_by! do |c|
|
24
|
+
hsv = Cairo::Color.parse(c).to_hsv
|
25
|
+
[(hsv.hue / 16.0).to_i, hsv.value, hsv.saturation]
|
26
|
+
end
|
27
|
+
w, h = 300, 50
|
28
|
+
deck_height = 4000
|
29
|
+
deck_width = (colors.size / ((deck_height / h) + 1)) * w
|
30
|
+
Squib::Deck.new(width: deck_width, height: deck_height) do
|
23
31
|
background color: :white
|
24
|
-
|
25
|
-
colors.sort_by! {|c| Cairo::Color.parse(c).to_s}
|
26
|
-
x, y, w, h = 0, 0, 300, 50
|
32
|
+
x, y = 0, 0
|
27
33
|
colors.each_with_index do |color, i|
|
28
34
|
rect x: x, y: y, width: w, height: h, fill_color: color
|
29
35
|
text str: color.to_s, x: x + 5, y: y + 13, font: 'Sans Bold 5',
|
30
36
|
color: (Cairo::Color.parse(color).to_hsv.v > 0.9) ? '#000' : '#fff'
|
31
37
|
y += h
|
32
|
-
if y >
|
38
|
+
if y > deck_height
|
33
39
|
x += w
|
34
40
|
y = 0
|
35
41
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative '../../lib/squib'
|
2
|
+
|
3
|
+
# Choose between black and white color theme for type snake
|
4
|
+
# * Allow using white snake cards with black text or
|
5
|
+
# black snake cards with white text
|
6
|
+
color = 'white'
|
7
|
+
|
8
|
+
cards = Squib.csv file: '_switch_color_data.csv'
|
9
|
+
|
10
|
+
Squib::Deck.new cards: cards['Type'].size do
|
11
|
+
|
12
|
+
background_color = cards['Type'].map do |t|
|
13
|
+
if color == 'black' && t == "Snake" then
|
14
|
+
"black"
|
15
|
+
else
|
16
|
+
"white"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
background color: background_color
|
20
|
+
|
21
|
+
text_color = cards['Type'].map do |t|
|
22
|
+
if color == 'black' && t == "Snake" then
|
23
|
+
"white"
|
24
|
+
else
|
25
|
+
"black"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
text str: cards['Text'], color: text_color
|
30
|
+
|
31
|
+
save_png prefix: '_switch_color_sample_'
|
32
|
+
|
33
|
+
end
|
data/samples/data/_excel.rb
CHANGED
@@ -37,7 +37,7 @@ end
|
|
37
37
|
# from each value. This is the default behavior in Squib, but the options
|
38
38
|
# are here just to make sure.
|
39
39
|
|
40
|
-
resource_data = Squib.xlsx(file: 'sample.xlsx', sheet: 2, strip: true) do |header, value|
|
40
|
+
resource_data = Squib.xlsx(file: 'sample.xlsx', explode: 'Qty', sheet: 2, strip: true) do |header, value|
|
41
41
|
case header
|
42
42
|
when 'Cost'
|
43
43
|
"$#{value}k" # e.g. "3" becomes "$3k"
|
@@ -93,7 +93,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 1, config: 'load_images_config.
|
|
93
93
|
# but sometimes want to use none.
|
94
94
|
# e.g. id: [:attack, :defend, nil]
|
95
95
|
svg file: 'spanner.svg', width: :deck, height: :deck,
|
96
|
-
force_id: true, id:
|
96
|
+
force_id: true, id: nil # <-- the important part
|
97
97
|
|
98
98
|
# Squib can handle incorrectly formatted svg files
|
99
99
|
svg file: 'bad-svg.svg'
|
data/samples/ranges/_ranges.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'squib'
|
2
|
+
|
3
|
+
# This demonstrates the many ways you can save file to save_png and the like
|
4
|
+
Squib::Deck.new(width: 50, height: 50, cards: 2) do
|
5
|
+
background color: :white
|
6
|
+
text str: (0..16).to_a, font: 'Arial Bold 12'
|
7
|
+
|
8
|
+
# three digits, e.g. save_three_digits_000.png
|
9
|
+
save_png prefix: 'save_three_digits_', count_format: '%03d'
|
10
|
+
|
11
|
+
# foo_0.png
|
12
|
+
# bar_1.png
|
13
|
+
save_png prefix: ['foo_', 'bar_'], count_format: '%01d'
|
14
|
+
|
15
|
+
# foo.png
|
16
|
+
# bar.png
|
17
|
+
save_png prefix: ['foo', 'bar'], count_format: ''
|
18
|
+
|
19
|
+
# foo_00_bar.png
|
20
|
+
# foo_01_bar.png
|
21
|
+
save_png prefix: 'foo_', suffix: '_bar'
|
22
|
+
|
23
|
+
# thief.png
|
24
|
+
# thug.png
|
25
|
+
data = csv data: "filename\nthief\nthug"
|
26
|
+
save_png prefix: data.filename, count_format: ''
|
27
|
+
|
28
|
+
end
|
data/samples/saves/_save_pdf.rb
CHANGED
@@ -3,7 +3,7 @@ require 'squib'
|
|
3
3
|
Squib::Deck.new(cards: 8) do
|
4
4
|
background color: :gray
|
5
5
|
rect x: 37.5, y: 37.5, width: 750, height: 1050,
|
6
|
-
x_radius: 37.5, y_radius: 37.5,
|
6
|
+
x_radius: 37.5, y_radius: 37.5, stroke_width: 2.0, dash: '4 4'
|
7
7
|
|
8
8
|
# Tests for crop marks
|
9
9
|
save_pdf file: 'crops-default.pdf', crop_marks: true
|
data/samples/saves/_saves.rb
CHANGED
@@ -5,7 +5,7 @@ require 'squib'
|
|
5
5
|
Squib::Deck.new(width: 825, height: 1125, cards: 16) do
|
6
6
|
background color: :gray
|
7
7
|
rect x: 38, y: 38, width: 750, height: 1050,
|
8
|
-
x_radius: 38, y_radius: 38,
|
8
|
+
x_radius: 38, y_radius: 38, stroke_width: 2.0, dash: '4 4'
|
9
9
|
|
10
10
|
text str: (1..16).to_a, x: 220, y: 78, font: 'Arial 18'
|
11
11
|
|
@@ -45,6 +45,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 16) do
|
|
45
45
|
|
46
46
|
# Sheets can arrange left-to-right and right-to-left
|
47
47
|
save_sheet prefix: 'save_sheet_rtl_',
|
48
|
+
suffix: '_with_suffix',
|
48
49
|
range: 0..1, rtl: true,
|
49
50
|
columns: 2, rows: 1,
|
50
51
|
margin: 75, gap: 5, trim: 37
|
@@ -3,8 +3,8 @@ require 'squib'
|
|
3
3
|
Squib::Deck.new do
|
4
4
|
background color: :white
|
5
5
|
|
6
|
-
grid x: 10, y: 10, width: 50, height: 50, stroke_color: '#0066FF', stroke_width: 1.5
|
7
|
-
grid x: 10, y: 10, width: 200, height: 200, stroke_color: '#0066FF', stroke_width: 3
|
6
|
+
grid x: 10, y: 10, width: 50, height: 50, stroke_color: '#0066FF', stroke_width: 1.5
|
7
|
+
grid x: 10, y: 10, width: 200, height: 200, stroke_color: '#0066FF', stroke_width: 3
|
8
8
|
|
9
9
|
rect x: 305, y: 105, width: 200, height: 50, dash: '4 2'
|
10
10
|
|