squib 0.9.0 → 0.10.0
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/.gitignore +2 -1
- data/.gitmodules +22 -0
- data/.travis.yml +4 -5
- data/CHANGELOG.md +23 -0
- data/CONTRIBUTING.md +40 -0
- data/README.md +25 -553
- data/RELEASE TODO.md +2 -2
- data/Rakefile +6 -64
- data/appveyor.yml +0 -4
- data/benchmarks/antialias_best.rb +2 -2
- data/benchmarks/antialias_fast.rb +2 -2
- data/benchmarks/{backend-memory.rb → backend_memory.rb} +2 -2
- data/benchmarks/{backend-svg.rb → backend_svg.rb} +2 -2
- data/benchmarks/tons_of_png.rb +1 -1
- data/benchmarks/tons_of_svg.rb +1 -1
- data/benchmarks/tons_of_text.rb +1 -1
- data/docs/Makefile +216 -0
- data/docs/_static/css/squibdocs.css +18 -0
- data/docs/args/draw.rst +36 -0
- data/docs/args/expansion.rst +3 -0
- data/docs/args/layout.rst +6 -0
- data/docs/args/output_dir.rst +6 -0
- data/docs/args/range.rst +6 -0
- data/docs/args/transform.rst +51 -0
- data/docs/args/trim.rst +11 -0
- data/docs/args/wh.rst +12 -0
- data/docs/args/xy.rst +12 -0
- data/docs/arrays.rst +77 -0
- data/docs/backends.rst +20 -0
- data/docs/bleed.rst +13 -0
- data/docs/build_groups.rst +47 -0
- data/docs/colors.rst +64 -0
- data/docs/conf.py +287 -0
- data/docs/config.rst +117 -0
- data/docs/data.rst +22 -0
- data/docs/dsl/background.rst +20 -0
- data/docs/dsl/build.rst +32 -0
- data/docs/dsl/build_groups.rst +23 -0
- data/docs/dsl/circle.rst +27 -0
- data/docs/dsl/cm.rst +19 -0
- data/docs/dsl/csv.rst +62 -0
- data/docs/dsl/curve.rst +63 -0
- data/docs/dsl/deck.rst +45 -0
- data/docs/dsl/disable_build.rst +28 -0
- data/docs/dsl/ellipse.rst +17 -0
- data/docs/dsl/enable_build.rst +25 -0
- data/docs/dsl/grid.rst +31 -0
- data/docs/dsl/hand.rst +40 -0
- data/docs/dsl/hint.rst +15 -0
- data/docs/dsl/inches.rst +19 -0
- data/docs/dsl/index.rst +9 -0
- data/docs/dsl/line.rst +52 -0
- data/docs/dsl/png.rst +49 -0
- data/docs/dsl/polygon.rst +28 -0
- data/docs/dsl/rect.rst +18 -0
- data/docs/dsl/save.rst +23 -0
- data/docs/dsl/save_pdf.rst +48 -0
- data/docs/dsl/save_png.rst +46 -0
- data/docs/dsl/save_sheet.rst +55 -0
- data/docs/dsl/showcase.rst +65 -0
- data/docs/dsl/star.rst +35 -0
- data/docs/dsl/svg.rst +119 -0
- data/docs/dsl/text.rst +294 -0
- data/docs/dsl/triangle.rst +38 -0
- data/docs/dsl/use_layout.rst +16 -0
- data/docs/dsl/xlsx.rst +50 -0
- data/docs/guides/game_icons.rst +2 -0
- data/docs/guides/getting-started/index.rst +5 -0
- data/docs/guides/getting-started/part_0_learning_ruby.rst +145 -0
- data/docs/guides/getting-started/part_1_zero_to_game.rst +216 -0
- data/docs/guides/getting-started/part_2_iconography.rst +152 -0
- data/docs/guides/getting-started/part_3_workflows.rst +4 -0
- data/docs/guides/git.rst +13 -0
- data/docs/guides/hello_world.rst +6 -0
- data/docs/help.rst +157 -0
- data/docs/index.rst +35 -0
- data/docs/install.rst +66 -0
- data/docs/layouts.rst +235 -0
- data/docs/learning.rst +10 -0
- data/docs/make.bat +263 -0
- data/docs/parameters.rst +26 -0
- data/docs/server.bat +1 -0
- data/docs/text_feature.rst +86 -0
- data/docs/units.rst +6 -0
- data/lib/squib.rb +4 -4
- data/lib/squib/api/background.rb +5 -10
- data/lib/squib/api/data.rb +30 -54
- data/lib/squib/api/groups.rb +47 -0
- data/lib/squib/api/image.rb +8 -67
- data/lib/squib/api/save.rb +15 -105
- data/lib/squib/api/settings.rb +8 -22
- data/lib/squib/api/shapes.rb +15 -185
- data/lib/squib/api/text.rb +9 -49
- data/lib/squib/api/text_embed.rb +12 -12
- data/lib/squib/api/units.rb +3 -17
- data/lib/squib/args/arg_loader.rb +6 -6
- data/lib/squib/args/box.rb +2 -2
- data/lib/squib/args/card_range.rb +1 -1
- data/lib/squib/args/color_validator.rb +2 -2
- data/lib/squib/args/coords.rb +2 -2
- data/lib/squib/args/csv_opts.rb +25 -0
- data/lib/squib/args/dir_validator.rb +1 -1
- data/lib/squib/args/draw.rb +2 -2
- data/lib/squib/args/embed_adjust.rb +1 -1
- data/lib/squib/args/embed_key.rb +1 -1
- data/lib/squib/args/hand_special.rb +37 -37
- data/lib/squib/args/import.rb +2 -2
- data/lib/squib/args/input_file.rb +1 -1
- data/lib/squib/args/paint.rb +3 -3
- data/lib/squib/args/paragraph.rb +2 -2
- data/lib/squib/args/save_batch.rb +2 -2
- data/lib/squib/args/scale_box.rb +1 -1
- data/lib/squib/args/sheet.rb +3 -3
- data/lib/squib/args/showcase_special.rb +2 -2
- data/lib/squib/args/svg_special.rb +1 -1
- data/lib/squib/args/transform.rb +2 -2
- data/lib/squib/args/typographer.rb +5 -4
- data/lib/squib/args/unit_conversion.rb +4 -4
- data/lib/squib/card.rb +8 -8
- data/lib/squib/conf.rb +5 -5
- data/lib/squib/deck.rb +20 -18
- data/lib/squib/graphics/cairo_context_wrapper.rb +3 -3
- data/lib/squib/graphics/gradient_regex.rb +1 -1
- data/lib/squib/graphics/hand.rb +2 -2
- data/lib/squib/graphics/save_doc.rb +9 -8
- data/lib/squib/graphics/save_images.rb +24 -11
- data/lib/squib/graphics/shapes.rb +16 -17
- data/lib/squib/graphics/showcase.rb +9 -9
- data/lib/squib/graphics/text.rb +21 -21
- data/lib/squib/layout_parser.rb +9 -9
- data/lib/squib/layouts/economy.yml +85 -85
- data/lib/squib/layouts/fantasy.yml +101 -101
- data/lib/squib/layouts/hand.yml +62 -62
- data/lib/squib/layouts/playing-card.yml +35 -35
- data/lib/squib/layouts/tuck_box.yml +45 -45
- data/lib/squib/sample_helpers.rb +1 -1
- data/lib/squib/version.rb +1 -1
- data/samples/{backend.rb → backend/_backend.rb} +2 -2
- data/samples/basic.rb +3 -3
- data/samples/bug134.rb +14 -0
- data/samples/build_groups/build_groups.rb +36 -0
- data/samples/cairo_access.rb +12 -1
- data/samples/{colors.rb → colors/_colors.rb} +12 -12
- data/samples/{gradients.rb → colors/_gradients.rb} +1 -1
- data/samples/config_text_markup.rb +2 -2
- data/samples/custom-config.yml +5 -5
- data/samples/custom_config.rb +18 -18
- data/samples/{csv_import.rb → data/_csv.rb} +8 -1
- data/samples/{excel.rb → data/_excel.rb} +3 -3
- data/samples/embed_text.rb +21 -0
- data/samples/hello_world.rb +1 -1
- data/samples/{load_images.rb → images/_more_load_images.rb} +2 -2
- data/samples/layouts.rb +11 -1
- data/samples/layouts_builtin.rb +51 -51
- data/samples/offset.svg +71 -71
- data/samples/ranges.rb +7 -7
- data/samples/{hand.rb → saves/_hand.rb} +1 -2
- data/samples/{portrait-landscape.rb → saves/_portrait_landscape.rb} +4 -4
- data/samples/{saves.rb → saves/_saves.rb} +0 -0
- data/samples/{showcase.rb → saves/_showcase.rb} +2 -2
- data/samples/{draw_shapes.rb → shapes/_draw_shapes.rb} +1 -1
- data/samples/text/_text.rb +4 -3
- data/samples/text_options.rb +6 -6
- data/samples/unicode.rb +1 -1
- data/spec/api/api_data_spec.rb +59 -4
- data/spec/api/api_settings_spec.rb +1 -1
- data/spec/args/box_spec.rb +7 -7
- data/spec/args/draw_spec.rb +19 -19
- data/spec/args/embed_key_spec.rb +13 -13
- data/spec/args/input_file_spec.rb +2 -2
- data/spec/args/paint_spec.rb +5 -5
- data/spec/args/paragraph_spec.rb +28 -28
- data/spec/args/range_spec.rb +1 -1
- data/spec/args/save_batch_spec.rb +10 -10
- data/spec/args/scale_box_spec.rb +9 -9
- data/spec/args/sheet_spec.rb +8 -8
- data/spec/args/showcase_special_spec.rb +15 -15
- data/spec/args/transform_spec.rb +4 -4
- data/spec/args/typographer_spec.rb +11 -11
- data/spec/args/unit_conversion_spec.rb +2 -2
- data/spec/card_spec.rb +1 -1
- data/spec/commands/new_spec.rb +1 -1
- data/spec/data/csv/custom_opts.csv +2 -0
- data/spec/data/csv/newline.csv +3 -0
- data/spec/data/csv/qty.csv +2 -2
- data/spec/data/csv/qty_named.csv +2 -2
- data/spec/data/csv/with_spaces.csv +2 -2
- data/spec/data/csv/yield.csv +3 -0
- data/spec/data/samples/{autoscale_font.rb.txt → autoscale_font/_autoscale_font.rb.txt} +55 -18
- data/spec/data/samples/cairo_access.rb.txt +24 -0
- data/spec/data/samples/{gradients.rb.txt → colors/_gradients.rb.txt} +0 -0
- data/spec/data/samples/config_text_markup.rb.txt +72 -72
- data/spec/data/samples/custom_config.rb.txt +1 -0
- data/spec/data/samples/{csv_import.rb.txt → data/_csv.rb.txt} +0 -0
- data/spec/data/samples/{excel.rb.txt → data/_excel.rb.txt} +0 -0
- data/spec/data/samples/embed_text.rb.txt +79 -0
- data/spec/data/samples/hello_world.rb.txt +36 -36
- data/spec/data/samples/{load_images.rb.txt → images/_more_load_images.rb.txt} +4 -4
- data/spec/data/samples/{hand.rb.txt → saves/_hand.rb.txt} +0 -0
- data/spec/data/samples/{portrait-landscape.rb.txt → saves/_portrait_landscape.rb.txt} +11 -7
- data/spec/data/samples/{save_pdf.rb.txt → saves/_save_pdf.rb.txt} +0 -0
- data/spec/data/samples/{saves.rb.txt → saves/_saves.rb.txt} +3 -4
- data/spec/data/samples/{showcase.rb.txt → saves/_showcase.rb.txt} +0 -0
- data/spec/data/samples/{draw_shapes.rb.txt → shapes/_draw_shapes.rb.txt} +0 -0
- data/spec/data/samples/text_options.rb.txt +1125 -1125
- data/spec/graphics/cairo_context_wrapper_spec.rb +10 -10
- data/spec/graphics/graphics_save_doc_spec.rb +11 -5
- data/spec/layout_parser_spec.rb +21 -9
- data/spec/logger_spec.rb +2 -2
- data/spec/samples/run_samples_spec.rb +1 -1
- data/spec/samples/samples_regression_spec.rb +16 -18
- data/spec/samples/sanity.rb +9 -9
- data/spec/sanity/.gitignore +1 -0
- data/spec/sanity/sanity.html.erb +42 -0
- data/spec/sanity/sanity_test.rb +42 -0
- data/spec/sanity/tests.yml +12 -0
- data/spec/spec_helper.rb +22 -20
- data/squib.gemspec +3 -4
- metadata +143 -81
- data/.rspec +0 -1
- data/.yardopts +0 -10
- data/samples/autoscale_font.rb +0 -27
- data/samples/backend-config.yml +0 -5
- data/samples/color_shortcuts.rb +0 -6
- data/samples/explode_quantities.xlsx +0 -0
- data/samples/quantity_explosion.csv +0 -3
- data/samples/sample.csv +0 -3
- data/samples/sample.xlsx +0 -0
- data/squib.sublime-project +0 -42
|
@@ -7,7 +7,7 @@ Squib::Deck.new(cards: 8, layout: 'playing-card.yml') do
|
|
|
7
7
|
text str: ('A'..'Z').to_a, layout: :bonus_ul, font: 'Sans bold 100'
|
|
8
8
|
|
|
9
9
|
# Defaults are sensible
|
|
10
|
-
hand #saves to _output/hand.png
|
|
10
|
+
hand # saves to _output/hand.png
|
|
11
11
|
|
|
12
12
|
# Here's a prettier version:
|
|
13
13
|
# - Each card is trimmed with rounded corners
|
|
@@ -21,4 +21,3 @@ Squib::Deck.new(cards: 8, layout: 'playing-card.yml') do
|
|
|
21
21
|
# Tip: you can have the top card be on the left by reversing the range
|
|
22
22
|
# angle_range: (Math::PI / 4)..(Math::PI / -4)
|
|
23
23
|
end
|
|
24
|
-
|
|
@@ -8,16 +8,16 @@ require 'squib'
|
|
|
8
8
|
Squib::Deck.new(width: 825, height: 1125) do
|
|
9
9
|
background color: '#aaa'
|
|
10
10
|
|
|
11
|
-
text str: 'This is portrait'
|
|
11
|
+
text str: 'This is portrait and trimmed'
|
|
12
12
|
|
|
13
|
-
save_png prefix: 'portrait_'
|
|
13
|
+
save_png prefix: 'portrait_', trim: 10, trim_radius: 15
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
# Money cards are landscape
|
|
17
17
|
Squib::Deck.new(width: 1125, height: 825) do
|
|
18
18
|
background color: '#aaa'
|
|
19
19
|
|
|
20
|
-
text str: 'This is landscape'
|
|
20
|
+
text str: 'This is landscape and trimmed', x: 15, y: 10
|
|
21
21
|
|
|
22
|
-
save_png prefix: 'landscape_', rotate:
|
|
22
|
+
save_png prefix: 'landscape_', rotate: :clockwise, trim: 25, trim_radius: 15
|
|
23
23
|
end
|
|
File without changes
|
|
@@ -9,7 +9,7 @@ Squib::Deck.new(cards: 4) do
|
|
|
9
9
|
text str: %w(Grifter Thief Thug Kingpin),
|
|
10
10
|
font: 'Helvetica,Sans weight=800 120',
|
|
11
11
|
x: 78, y: 78, width: '2.25in', align: :center
|
|
12
|
-
svg file: 'spanner.svg', x: (825-500)/2, y: 500, width: 500, height: 500
|
|
12
|
+
svg file: 'spanner.svg', x: (825 - 500) / 2, y: 500, width: 500, height: 500
|
|
13
13
|
|
|
14
14
|
# Defaults are pretty sensible.
|
|
15
15
|
showcase file: 'showcase.png'
|
|
@@ -22,4 +22,4 @@ Squib::Deck.new(cards: 4) do
|
|
|
22
22
|
file: 'showcase2.png'
|
|
23
23
|
|
|
24
24
|
save_png prefix: 'showcase_individual_' # to show that they're not trimmed
|
|
25
|
-
end
|
|
25
|
+
end
|
|
@@ -36,7 +36,7 @@ Squib::Deck.new do
|
|
|
36
36
|
star x: 300, y: 1000, n: 5, inner_radius: 15, outer_radius: 40,
|
|
37
37
|
fill_color: :cyan, stroke_color: :burgundy, stroke_width: 5
|
|
38
38
|
|
|
39
|
-
#default draw is fill-then-stroke. Can be changed to stroke-then-fill
|
|
39
|
+
# default draw is fill-then-stroke. Can be changed to stroke-then-fill
|
|
40
40
|
star x: 375, y: 1000, n: 5, inner_radius: 15, outer_radius: 40,
|
|
41
41
|
fill_color: :cyan, stroke_color: :burgundy,
|
|
42
42
|
stroke_width: 5, stroke_strategy: :stroke_first
|
data/samples/text/_text.rb
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
require 'squib'
|
|
2
2
|
require 'squib/sample_helpers'
|
|
3
3
|
|
|
4
|
-
Squib::Deck.new(width: 1000, height:
|
|
4
|
+
Squib::Deck.new(width: 1000, height: 1250) do
|
|
5
5
|
draw_graph_paper width, height
|
|
6
6
|
|
|
7
|
-
sample 'Font strings are quite expressive. Specify family, modifiers, then size. Font names with spaces in them should
|
|
7
|
+
sample 'Font strings are quite expressive. Specify family, modifiers, then size. Font names with spaces in them should end with a comma to help with parsing.' do |x, y|
|
|
8
8
|
text font: 'Arial bold italic 32', str: 'Bold and italic!', x: x, y: y - 50
|
|
9
9
|
text font: 'Arial weight=300 32', str: 'Light bold!', x: x, y: y
|
|
10
|
-
text font: 'Times New Roman,
|
|
10
|
+
text font: 'Times New Roman, 32', str: 'Times New Roman', x: x, y: y + 50
|
|
11
|
+
text font: 'NoSuchFont,Arial 32', str: 'Arial Backup', x: x, y: y + 100
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
sample 'Specify width and height to see a text box. Also: set "hint" to see the extents of your text box' do |x, y|
|
data/samples/text_options.rb
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# encoding: UTF-8
|
|
2
2
|
require 'squib'
|
|
3
3
|
|
|
4
|
-
data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
|
|
5
|
-
'level' => [1,2,3]}
|
|
4
|
+
data = { 'name' => ['Thief', 'Grifter', 'Mastermind'],
|
|
5
|
+
'level' => [1, 2, 3] }
|
|
6
6
|
longtext = "This is left-justified text, with newlines.\nWhat do you know about tweetle beetles? well... When tweetle beetles fight, it's called a tweetle beetle battle. And when they battle in a puddle, it's a tweetle beetle puddle battle. AND when tweetle beetles battle with paddles in a puddle, they call it a tweetle beetle puddle paddle battle. AND... When beetles battle beetles in a puddle paddle battle and the beetle battle puddle is a puddle in a bottle... ..they call this a tweetle beetle bottle puddle paddle battle muddle."
|
|
7
7
|
|
|
8
8
|
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
|
@@ -37,7 +37,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
|
|
37
37
|
# Extents come back as an array of hashes, which can get split out like this
|
|
38
38
|
ws = extents.inject([]) { |arr, ext| arr << ext[:width] + 10; arr }
|
|
39
39
|
hs = extents.inject([]) { |arr, ext| arr << ext[:height] + 10; arr }
|
|
40
|
-
rect x: 65 - margin/2, y: 550 - margin/2,
|
|
40
|
+
rect x: 65 - margin / 2, y: 550 - margin / 2,
|
|
41
41
|
width: ws, height: hs,
|
|
42
42
|
radius: 10, stroke_color: :black
|
|
43
43
|
|
|
@@ -79,15 +79,15 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
|
|
79
79
|
embed.svg key: ':health:', width: 28, height: 28, file: 'glass-heart.svg'
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
-
text str:
|
|
82
|
+
text str: 'Fill n <span fgcolor="#ff0000">stroke</span>',
|
|
83
83
|
color: :green, stroke_width: 2.0, stroke_color: :blue,
|
|
84
84
|
x: '1.8in', y: '2.9in', width: '0.85in', font: 'Sans Bold 26', markup: true
|
|
85
85
|
|
|
86
|
-
text str:
|
|
86
|
+
text str: 'Stroke n <span fgcolor="#ff0000">fill</span>',
|
|
87
87
|
color: :green, stroke_width: 2.0, stroke_color: :blue, stroke_strategy: :stroke_first,
|
|
88
88
|
x: '1.8in', y: '3.0in', width: '0.85in', font: 'Sans Bold 26', markup: true
|
|
89
89
|
|
|
90
|
-
text str:
|
|
90
|
+
text str: 'Dotted',
|
|
91
91
|
color: :white, stroke_width: 2.0, dash: '4 2', stroke_color: :black,
|
|
92
92
|
x: '1.8in', y: '3.1in', width: '0.85in', font: 'Sans Bold 26', markup: true
|
|
93
93
|
#
|
data/samples/unicode.rb
CHANGED
|
@@ -14,7 +14,7 @@ Squib::Deck.new(height: (game_chars.size / cols + 1) * cell_height,
|
|
|
14
14
|
text str: 'Game-related UTF8 icons. Generated by Squib, https://github.com/andymeneely/squib'
|
|
15
15
|
game_chars.each_with_index do |c, i|
|
|
16
16
|
rect fill_color: %w(#eeee #ffff)[i % 2],
|
|
17
|
-
width: cell_width, height: cell_height,
|
|
17
|
+
width: cell_width, height: cell_height, x: x, y: y
|
|
18
18
|
text str: c.inspect, font: 'Sans 42', x: x, y: y
|
|
19
19
|
text str: c, font: 'Sans,Segoe UI Symbol 42', x: x + 300, y: y
|
|
20
20
|
x += cell_width
|
data/spec/api/api_data_spec.rb
CHANGED
|
@@ -38,26 +38,81 @@ describe Squib::Deck do
|
|
|
38
38
|
|
|
39
39
|
it 'explodes quantities' do
|
|
40
40
|
expect(Squib.csv(file: csv_file('qty.csv'))).to eq({
|
|
41
|
-
'Name'
|
|
41
|
+
'Name' => %w(Ha Ha Ha Ho),
|
|
42
42
|
'Qty' => [3, 3, 3, 1],
|
|
43
43
|
})
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
it 'explodes quantities on specified header' do
|
|
47
47
|
expect(Squib.csv(explode: 'Quantity', file: csv_file('qty_named.csv'))).to eq({
|
|
48
|
-
'Name'
|
|
48
|
+
'Name' => %w(Ha Ha Ha Ho),
|
|
49
49
|
'Quantity' => [3, 3, 3, 1],
|
|
50
50
|
})
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
it 'loads inline data' do
|
|
54
|
+
hash = Squib.csv(data: "h1,h2\n1,2\n3,4")
|
|
55
|
+
expect(hash).to eq({
|
|
56
|
+
'h1' => [1, 3],
|
|
57
|
+
'h2' => [2, 4]
|
|
58
|
+
})
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'loads csv with newlines' do
|
|
62
|
+
hash = Squib.csv(file: csv_file('newline.csv'))
|
|
63
|
+
expect(hash).to eq({
|
|
64
|
+
'title' => ['Foo'],
|
|
65
|
+
'level' => [1],
|
|
66
|
+
'notes' => ["a\nb"]
|
|
67
|
+
})
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'loads custom CSV options' do
|
|
71
|
+
hash = Squib.csv(file: csv_file('custom_opts.csv'),
|
|
72
|
+
col_sep: '-', quote_char: '|')
|
|
73
|
+
expect(hash).to eq({
|
|
74
|
+
'x' => ['p'],
|
|
75
|
+
'y' => ['q-r']
|
|
76
|
+
})
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'yields to block when given' do
|
|
80
|
+
data = Squib.csv(file: csv_file('basic.csv')) do |header, value|
|
|
81
|
+
case header
|
|
82
|
+
when 'h1'
|
|
83
|
+
value * 2
|
|
84
|
+
else
|
|
85
|
+
'ha'
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
expect(data).to eq({
|
|
89
|
+
'h1' => [2, 6],
|
|
90
|
+
'h2' => %w(ha ha),
|
|
91
|
+
})
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it 'replaces newlines whenever its a string' do
|
|
95
|
+
data = Squib.csv(file: csv_file('yield.csv')) do |header, value|
|
|
96
|
+
if value.respond_to? :gsub
|
|
97
|
+
value.gsub '%n', "\n"
|
|
98
|
+
else
|
|
99
|
+
value
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
expect(data).to eq({
|
|
103
|
+
'a' => ["foo\nbar", 1],
|
|
104
|
+
'b' => [1, "blah\n"],
|
|
105
|
+
})
|
|
106
|
+
end
|
|
107
|
+
|
|
53
108
|
end
|
|
54
109
|
|
|
55
110
|
context '#xlsx' do
|
|
56
111
|
it 'loads basic xlsx data' do
|
|
57
112
|
expect(Squib.xlsx(file: xlsx_file('basic.xlsx'))).to eq({
|
|
58
113
|
'Name' => %w(Larry Curly Mo),
|
|
59
|
-
'General Number' => %w(1 2 3), #general types always get loaded as strings with no conversion
|
|
60
|
-
'Actual Number'
|
|
114
|
+
'General Number' => %w(1 2 3), # general types always get loaded as strings with no conversion
|
|
115
|
+
'Actual Number' => [4.0, 5.0, 6.0], # numbers get auto-converted to integers
|
|
61
116
|
})
|
|
62
117
|
end
|
|
63
118
|
|
data/spec/args/box_spec.rb
CHANGED
|
@@ -3,7 +3,7 @@ require 'squib/args/box'
|
|
|
3
3
|
|
|
4
4
|
describe Squib::Args::Box do
|
|
5
5
|
subject(:box) { Squib::Args::Box.new }
|
|
6
|
-
let(:expected_defaults) { {x: [0], y: [0], width: [:deck], height: [:deck] } }
|
|
6
|
+
let(:expected_defaults) { { x: [0], y: [0], width: [:deck], height: [:deck] } }
|
|
7
7
|
|
|
8
8
|
it 'intitially has no params set' do
|
|
9
9
|
expect(box).not_to respond_to(:x, :y, :width, :height)
|
|
@@ -20,13 +20,13 @@ describe Squib::Args::Box do
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it 'extracts the defaults from Box on an empty hash' do
|
|
23
|
-
box.load!({foo: :bar})
|
|
23
|
+
box.load!({ foo: :bar })
|
|
24
24
|
expect(box).to have_attributes(expected_defaults)
|
|
25
25
|
expect(box).not_to respond_to(:foo)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
context 'single expansion' do
|
|
29
|
-
let(:args) { {x: [1, 2], y: 3} }
|
|
29
|
+
let(:args) { { x: [1, 2], y: 3 } }
|
|
30
30
|
before(:each) { box.load!(args, expand_by: 2) }
|
|
31
31
|
it 'expands box' do
|
|
32
32
|
expect(box).to have_attributes({
|
|
@@ -81,7 +81,7 @@ describe Squib::Args::Box do
|
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
it 'warns on non-existent layouts' do
|
|
84
|
-
args = { layout: :heal}
|
|
84
|
+
args = { layout: :heal }
|
|
85
85
|
expect(Squib.logger).to receive(:warn).with('Layout "heal" does not exist in layout file - using default instead').at_least(:once)
|
|
86
86
|
box.load!(args, expand_by: 2, layout: layout)
|
|
87
87
|
expect(box).to have_attributes(
|
|
@@ -94,7 +94,7 @@ describe Squib::Args::Box do
|
|
|
94
94
|
context 'unit conversion' do
|
|
95
95
|
|
|
96
96
|
it 'converts units on all args' do
|
|
97
|
-
args = {x: ['1in', '2in'], y: 300, width: '1in', height: '1in'}
|
|
97
|
+
args = { x: ['1in', '2in'], y: 300, width: '1in', height: '1in' }
|
|
98
98
|
box.load!(args, expand_by: 2)
|
|
99
99
|
expect(box).to have_attributes(
|
|
100
100
|
x: [300, 600],
|
|
@@ -108,7 +108,7 @@ describe Squib::Args::Box do
|
|
|
108
108
|
|
|
109
109
|
context 'validation' do
|
|
110
110
|
it 'replaces with deck width and height' do
|
|
111
|
-
args = {width: :deck, height: :deck}
|
|
111
|
+
args = { width: :deck, height: :deck }
|
|
112
112
|
deck = OpenStruct.new(width: 123, height: 456)
|
|
113
113
|
box = Squib::Args::Box.new(deck)
|
|
114
114
|
box.load!(args, expand_by: 1)
|
|
@@ -116,7 +116,7 @@ describe Squib::Args::Box do
|
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
it 'has radius override x_radius and y_radius' do
|
|
119
|
-
args = {x_radius: 1, y_radius: 2, radius: 3}
|
|
119
|
+
args = { x_radius: 1, y_radius: 2, radius: 3 }
|
|
120
120
|
box.load!(args, expand_by: 2)
|
|
121
121
|
expect(box).to have_attributes(x_radius: [3, 3], y_radius: [3, 3])
|
|
122
122
|
end
|
data/spec/args/draw_spec.rb
CHANGED
|
@@ -2,13 +2,13 @@ require 'spec_helper'
|
|
|
2
2
|
require 'squib/args/draw'
|
|
3
3
|
|
|
4
4
|
describe Squib::Args::Draw do
|
|
5
|
-
let(:custom_colors) { {'foo' => 'abc'} }
|
|
5
|
+
let(:custom_colors) { { 'foo' => 'abc' } }
|
|
6
6
|
subject(:draw) {Squib::Args::Draw.new(custom_colors)}
|
|
7
7
|
|
|
8
8
|
context 'unit conversion' do
|
|
9
9
|
|
|
10
10
|
it 'converts units on stroke width' do
|
|
11
|
-
args = {stroke_width: '2in'}
|
|
11
|
+
args = { stroke_width: '2in' }
|
|
12
12
|
draw.load!(args, expand_by: 2)
|
|
13
13
|
expect(draw).to have_attributes(stroke_width: [600, 600])
|
|
14
14
|
end
|
|
@@ -16,11 +16,11 @@ describe Squib::Args::Draw do
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
context 'dsl overrides' do
|
|
19
|
-
subject(:draw)
|
|
19
|
+
subject(:draw) {Squib::Args::Draw.new(custom_colors, { stroke_width: 0.0 })}
|
|
20
20
|
|
|
21
21
|
it 'works when specified' do
|
|
22
22
|
draw.load!({}) # go right to defaults
|
|
23
|
-
expect(draw.stroke_width).to eq(
|
|
23
|
+
expect(draw.stroke_width).to eq([0.0]) # ordinarily a non-zero according
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
end
|
|
@@ -28,7 +28,7 @@ describe Squib::Args::Draw do
|
|
|
28
28
|
context 'validation' do
|
|
29
29
|
|
|
30
30
|
it 'converts to Cairo options' do
|
|
31
|
-
args = {join: 'bevel', cap: 'round'}
|
|
31
|
+
args = { join: 'bevel', cap: 'round' }
|
|
32
32
|
draw.load!(args)
|
|
33
33
|
expect(draw).to have_attributes(
|
|
34
34
|
join: [Cairo::LINE_JOIN_BEVEL],
|
|
@@ -37,62 +37,62 @@ describe Squib::Args::Draw do
|
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
it 'parses dash options' do
|
|
40
|
-
args = {dash: '3 4 5'}
|
|
40
|
+
args = { dash: '3 4 5' }
|
|
41
41
|
draw.load!(args)
|
|
42
42
|
expect(draw).to have_attributes(dash: [[3, 4, 5]])
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
it 'parses more complex dash options' do
|
|
46
|
-
args = {dash: '30.5, 90, 5'}
|
|
46
|
+
args = { dash: '30.5, 90, 5' }
|
|
47
47
|
draw.load!(args)
|
|
48
48
|
expect(draw).to have_attributes(dash: [[30.5, 90, 5]])
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
it 'does unit conversion on dash options' do
|
|
52
|
-
args = {dash: '3in 4in 5in'}
|
|
52
|
+
args = { dash: '3in 4in 5in' }
|
|
53
53
|
draw.load!(args)
|
|
54
54
|
expect(draw).to have_attributes(dash: [[900, 1200, 1500]])
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
it 'converts line caps to Cairo constants' do
|
|
58
|
-
args = {cap: :SQUARE}
|
|
58
|
+
args = { cap: :SQUARE }
|
|
59
59
|
draw.load! args
|
|
60
|
-
expect(draw).to have_attributes(
|
|
60
|
+
expect(draw).to have_attributes(cap: [Cairo::LINE_CAP_SQUARE])
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
it 'converts line join' do
|
|
64
|
-
args = {join: 'round'}
|
|
64
|
+
args = { join: 'round' }
|
|
65
65
|
draw.load! args
|
|
66
|
-
expect(draw).to have_attributes(
|
|
66
|
+
expect(draw).to have_attributes(join: [Cairo::LINE_JOIN_ROUND])
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
it 'allows fill_first stroke_strategy' do
|
|
70
|
-
args = {stroke_strategy: :FILL_first}
|
|
70
|
+
args = { stroke_strategy: :FILL_first }
|
|
71
71
|
draw.load! args
|
|
72
|
-
expect(draw).to have_attributes(
|
|
72
|
+
expect(draw).to have_attributes(stroke_strategy: [:fill_first])
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
it 'allows stroke_first stroke_strategy' do
|
|
76
|
-
args = {stroke_strategy: ' stroke_FIRST '}
|
|
76
|
+
args = { stroke_strategy: ' stroke_FIRST ' }
|
|
77
77
|
draw.load! args
|
|
78
|
-
expect(draw).to have_attributes(
|
|
78
|
+
expect(draw).to have_attributes(stroke_strategy: [:stroke_first])
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
it 'disallows anything not stroke_first and fill_first' do
|
|
82
|
-
args = {stroke_strategy: 'foo'}
|
|
82
|
+
args = { stroke_strategy: 'foo' }
|
|
83
83
|
expect { draw.load! args }.to raise_error("Only 'stroke_first' or 'fill_first' allowed")
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
context 'custom colors' do
|
|
87
87
|
|
|
88
88
|
it 'looks up custom colors in the config' do
|
|
89
|
-
draw.load!({color: 'foo'})
|
|
89
|
+
draw.load!({ color: 'foo' })
|
|
90
90
|
expect(draw.color).to eq ['abc']
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
it 'passes on through for non-custom color' do
|
|
94
94
|
draw = Squib::Args::Draw.new(custom_colors)
|
|
95
|
-
draw.load!({color: 'bar'})
|
|
95
|
+
draw.load!({ color: 'bar' })
|
|
96
96
|
expect(draw.color).to eq ['bar']
|
|
97
97
|
end
|
|
98
98
|
|
data/spec/args/embed_key_spec.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'squib/args/embed_key'
|
|
3
|
-
|
|
4
|
-
describe Squib::Args::EmbedKey do
|
|
5
|
-
|
|
6
|
-
context '#validate_key' do
|
|
7
|
-
|
|
8
|
-
it 'converts to string' do
|
|
9
|
-
expect(subject.validate_key(2.5)).to eq ('2.5')
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
end
|
|
13
|
-
end
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'squib/args/embed_key'
|
|
3
|
+
|
|
4
|
+
describe Squib::Args::EmbedKey do
|
|
5
|
+
|
|
6
|
+
context '#validate_key' do
|
|
7
|
+
|
|
8
|
+
it 'converts to string' do
|
|
9
|
+
expect(subject.validate_key(2.5)).to eq ('2.5')
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -7,13 +7,13 @@ describe Squib::Args::InputFile do
|
|
|
7
7
|
context 'validate_file' do
|
|
8
8
|
|
|
9
9
|
it 'allows a file if it exists' do
|
|
10
|
-
args = {file: __FILE__} # I code therefore I am.
|
|
10
|
+
args = { file: __FILE__ } # I code therefore I am.
|
|
11
11
|
ifile.load!(args, expand_by: 1)
|
|
12
12
|
expect(ifile).to have_attributes(file: [File.expand_path(__FILE__)])
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it 'raises on non-existent file' do
|
|
16
|
-
args = {file: 'foo.rb'}
|
|
16
|
+
args = { file: 'foo.rb' }
|
|
17
17
|
expect { ifile.load!(args, expand_by: 1) }.to raise_error("File #{File.expand_path('foo.rb')} does not exist!")
|
|
18
18
|
end
|
|
19
19
|
|
data/spec/args/paint_spec.rb
CHANGED
|
@@ -2,21 +2,21 @@ require 'spec_helper'
|
|
|
2
2
|
require 'squib/args/paint'
|
|
3
3
|
|
|
4
4
|
describe Squib::Args::Draw do
|
|
5
|
-
let(:custom_colors) { {'foo' => 'abc'} }
|
|
6
|
-
subject(:paint)
|
|
5
|
+
let(:custom_colors) { { 'foo' => 'abc' } }
|
|
6
|
+
subject(:paint) {Squib::Args::Paint.new(custom_colors)}
|
|
7
7
|
|
|
8
8
|
context 'alpha' do
|
|
9
9
|
|
|
10
10
|
it 'can be a float' do
|
|
11
|
-
args = {alpha: 0.6}
|
|
11
|
+
args = { alpha: 0.6 }
|
|
12
12
|
paint.load!(args)
|
|
13
13
|
expect(paint.alpha).to eq [0.6]
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it 'raises exception when not a float' do
|
|
17
|
-
args = {alpha: /6/}
|
|
17
|
+
args = { alpha: /6/ }
|
|
18
18
|
expect { paint.load!(args) }.to raise_error('alpha must respond to to_f')
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
end
|
|
22
|
-
end
|
|
22
|
+
end
|