squib 0.0.3 → 0.0.4
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 +29 -29
- data/.travis.yml +6 -6
- data/.yardopts +7 -7
- data/CHANGELOG.md +19 -0
- data/Gemfile +2 -2
- data/LICENSE.txt +22 -22
- data/README.md +256 -244
- data/Rakefile +11 -11
- data/bin/squib +18 -18
- data/lib/squib.rb +31 -31
- data/lib/squib/api/background.rb +18 -18
- data/lib/squib/api/data.rb +52 -52
- data/lib/squib/api/image.rb +66 -66
- data/lib/squib/api/save.rb +43 -43
- data/lib/squib/api/settings.rb +37 -38
- data/lib/squib/api/shapes.rb +116 -116
- data/lib/squib/api/text.rb +53 -50
- data/lib/squib/api/units.rb +16 -16
- data/lib/squib/card.rb +41 -41
- data/lib/squib/commands/new.rb +43 -43
- data/lib/squib/constants.rb +108 -104
- data/lib/squib/deck.rb +170 -116
- data/lib/squib/graphics/background.rb +13 -13
- data/lib/squib/graphics/image.rb +47 -47
- data/lib/squib/graphics/save_doc.rb +54 -54
- data/lib/squib/graphics/save_images.rb +32 -32
- data/lib/squib/graphics/shapes.rb +59 -59
- data/lib/squib/graphics/text.rb +116 -113
- data/lib/squib/input_helpers.rb +193 -193
- data/lib/squib/progress.rb +37 -37
- data/lib/squib/project_template/.gitignore +4 -4
- data/lib/squib/project_template/ABOUT.md +19 -19
- data/lib/squib/project_template/Gemfile +2 -2
- data/lib/squib/project_template/PNP NOTES.md +3 -3
- data/lib/squib/project_template/config.yml +19 -19
- data/lib/squib/project_template/deck.rb +5 -5
- data/lib/squib/version.rb +6 -6
- data/samples/autoscale_font.rb +27 -0
- data/samples/basic.rb +19 -19
- data/samples/colors.rb +15 -15
- data/samples/custom-config.yml +5 -5
- data/samples/custom-layout.yml +59 -39
- data/samples/custom_config.rb +18 -18
- data/samples/customconfig-imgdir/spanner2.svg +91 -91
- data/samples/draw_shapes.rb +18 -18
- data/samples/excel.rb +19 -19
- data/samples/hello_world.rb +6 -6
- data/samples/load_images.rb +29 -29
- data/samples/offset.svg +71 -71
- data/samples/portrait-landscape.rb +22 -22
- data/samples/ranges.rb +55 -55
- data/samples/save_pdf.rb +14 -14
- data/samples/spanner.svg +91 -91
- data/samples/text_options.rb +67 -60
- data/samples/tgc_proofs.rb +19 -19
- data/samples/units.rb +12 -12
- data/samples/use_layout.rb +33 -28
- data/spec/api/api_text_spec.rb +43 -43
- data/spec/commands/new_spec.rb +47 -47
- data/spec/data/easy-circular-extends.yml +6 -0
- data/spec/data/hard-circular-extends.yml +9 -0
- data/spec/data/multi-extends-single-entry.yml +14 -13
- data/spec/data/multi-level-extends.yml +9 -9
- data/spec/data/no-extends.yml +5 -5
- data/spec/data/pre-extends.yml +7 -0
- data/spec/data/self-circular-extends.yml +3 -0
- data/spec/data/single-extends.yml +7 -7
- data/spec/data/single-level-multi-extends.yml +11 -11
- data/spec/deck_spec.rb +188 -147
- data/spec/input_helpers_spec.rb +116 -116
- data/spec/samples_run_spec.rb +19 -19
- data/squib.gemspec +46 -46
- metadata +17 -7
data/samples/draw_shapes.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
require 'squib'
|
2
|
-
|
3
|
-
Squib::Deck.new do
|
4
|
-
rect x: 300, y: 300, width: 400, height: 400,
|
5
|
-
fill_color: :blue, stroke_color: :red, stroke_width: 50.0
|
6
|
-
|
7
|
-
circle x: 600, y: 600, radius: 75,
|
8
|
-
fill_color: :gray, stroke_color: :green, stroke_width: 8.0
|
9
|
-
|
10
|
-
triangle x1: 50, y1: 50,
|
11
|
-
x2: 150, y2: 150,
|
12
|
-
x3: 75, y3: 250
|
13
|
-
|
14
|
-
line x1: 50, y1: 550,
|
15
|
-
x2: 150, y2: 650,
|
16
|
-
stroke_width: 25.0
|
17
|
-
|
18
|
-
save_png prefix: 'shape_'
|
1
|
+
require 'squib'
|
2
|
+
|
3
|
+
Squib::Deck.new do
|
4
|
+
rect x: 300, y: 300, width: 400, height: 400,
|
5
|
+
fill_color: :blue, stroke_color: :red, stroke_width: 50.0
|
6
|
+
|
7
|
+
circle x: 600, y: 600, radius: 75,
|
8
|
+
fill_color: :gray, stroke_color: :green, stroke_width: 8.0
|
9
|
+
|
10
|
+
triangle x1: 50, y1: 50,
|
11
|
+
x2: 150, y2: 150,
|
12
|
+
x3: 75, y3: 250
|
13
|
+
|
14
|
+
line x1: 50, y1: 550,
|
15
|
+
x2: 150, y2: 650,
|
16
|
+
stroke_width: 25.0
|
17
|
+
|
18
|
+
save_png prefix: 'shape_'
|
19
19
|
end
|
data/samples/excel.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'squib'
|
3
|
-
|
4
|
-
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
5
|
-
background color: :white
|
6
|
-
|
7
|
-
# Takes the first sheet by default
|
8
|
-
# Outputs a hash of arrays with the header names as keys
|
9
|
-
data = xlsx file: 'sample.xlsx'
|
10
|
-
|
11
|
-
text str: data['Name'], x: 250, y: 55, font: 'Arial 54'
|
12
|
-
text str: data['Level'], x: 65, y: 65, font: 'Arial 72'
|
13
|
-
text str: data['Description'], x: 65, y: 600, font: 'Arial 36'
|
14
|
-
|
15
|
-
# You can also specify the sheet, starting at 0
|
16
|
-
data = xlsx file: 'sample.xlsx', sheet: 2
|
17
|
-
|
18
|
-
save format: :png, prefix: 'sample_excel_'
|
19
|
-
end
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'squib'
|
3
|
+
|
4
|
+
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
5
|
+
background color: :white
|
6
|
+
|
7
|
+
# Takes the first sheet by default
|
8
|
+
# Outputs a hash of arrays with the header names as keys
|
9
|
+
data = xlsx file: 'sample.xlsx'
|
10
|
+
|
11
|
+
text str: data['Name'], x: 250, y: 55, font: 'Arial 54'
|
12
|
+
text str: data['Level'], x: 65, y: 65, font: 'Arial 72'
|
13
|
+
text str: data['Description'], x: 65, y: 600, font: 'Arial 36'
|
14
|
+
|
15
|
+
# You can also specify the sheet, starting at 0
|
16
|
+
data = xlsx file: 'sample.xlsx', sheet: 2
|
17
|
+
|
18
|
+
save format: :png, prefix: 'sample_excel_'
|
19
|
+
end
|
data/samples/hello_world.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'squib'
|
3
|
-
|
4
|
-
Squib::Deck.new do
|
5
|
-
text str: 'Hello, World!'
|
6
|
-
save_png
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'squib'
|
3
|
+
|
4
|
+
Squib::Deck.new do
|
5
|
+
text str: 'Hello, World!'
|
6
|
+
save_png
|
7
7
|
end
|
data/samples/load_images.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
require 'squib'
|
2
|
-
|
3
|
-
Squib::Deck.new(width: 825, height: 1125, cards: 1) do
|
4
|
-
background color: '#0b7c8e'
|
5
|
-
rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38
|
6
|
-
|
7
|
-
png file: 'shiny-purse.png', x: 620, y: 75
|
8
|
-
svg file: 'spanner.svg', x: 620, y: 218
|
9
|
-
|
10
|
-
# SVGs can be scaled too
|
11
|
-
svg file: 'spanner.svg', x: 50, y: 50, width: 250, height: 250
|
12
|
-
|
13
|
-
# We can also limit our rendering to a single object, if the SVG ID is set
|
14
|
-
# Squib prepends a #-sign if one is not specified
|
15
|
-
svg file: 'spanner.svg', id: '#backdrop', x: 50, y: 350, width: 75, height: 75
|
16
|
-
svg file: 'spanner.svg', id: 'backdrop', x: 50, y: 450, width: 125, height: 125
|
17
|
-
|
18
|
-
# WARNING! If you choose to use the SVG ID, the x-y coordinates are still
|
19
|
-
# relative to the SVG page. See this example in an SVG editor
|
20
|
-
svg file: 'offset.svg', id: 'thing', x: 0, y: 0, width: 600, height: 600
|
21
|
-
|
22
|
-
# Over 15 different blending operators are supported.
|
23
|
-
# See http://cairographics.org/operators
|
24
|
-
# Alpha transparency too
|
25
|
-
png file: 'ball.png', x: 50, y: 700
|
26
|
-
png file: 'grit.png', x: 70, y: 750, blend: :color_burn, alpha: 0.75
|
27
|
-
|
28
|
-
save prefix: 'load_images_', format: :png
|
29
|
-
end
|
1
|
+
require 'squib'
|
2
|
+
|
3
|
+
Squib::Deck.new(width: 825, height: 1125, cards: 1) do
|
4
|
+
background color: '#0b7c8e'
|
5
|
+
rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38
|
6
|
+
|
7
|
+
png file: 'shiny-purse.png', x: 620, y: 75
|
8
|
+
svg file: 'spanner.svg', x: 620, y: 218
|
9
|
+
|
10
|
+
# SVGs can be scaled too
|
11
|
+
svg file: 'spanner.svg', x: 50, y: 50, width: 250, height: 250
|
12
|
+
|
13
|
+
# We can also limit our rendering to a single object, if the SVG ID is set
|
14
|
+
# Squib prepends a #-sign if one is not specified
|
15
|
+
svg file: 'spanner.svg', id: '#backdrop', x: 50, y: 350, width: 75, height: 75
|
16
|
+
svg file: 'spanner.svg', id: 'backdrop', x: 50, y: 450, width: 125, height: 125
|
17
|
+
|
18
|
+
# WARNING! If you choose to use the SVG ID, the x-y coordinates are still
|
19
|
+
# relative to the SVG page. See this example in an SVG editor
|
20
|
+
svg file: 'offset.svg', id: 'thing', x: 0, y: 0, width: 600, height: 600
|
21
|
+
|
22
|
+
# Over 15 different blending operators are supported.
|
23
|
+
# See http://cairographics.org/operators
|
24
|
+
# Alpha transparency too
|
25
|
+
png file: 'ball.png', x: 50, y: 700
|
26
|
+
png file: 'grit.png', x: 70, y: 750, blend: :color_burn, alpha: 0.75
|
27
|
+
|
28
|
+
save prefix: 'load_images_', format: :png
|
29
|
+
end
|
data/samples/offset.svg
CHANGED
@@ -1,71 +1,71 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2
|
-
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
3
|
-
|
4
|
-
<svg
|
5
|
-
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
6
|
-
xmlns:cc="http://creativecommons.org/ns#"
|
7
|
-
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
8
|
-
xmlns:svg="http://www.w3.org/2000/svg"
|
9
|
-
xmlns="http://www.w3.org/2000/svg"
|
10
|
-
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
11
|
-
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
12
|
-
width="747.59235"
|
13
|
-
height="747.39734"
|
14
|
-
id="svg2"
|
15
|
-
version="1.1"
|
16
|
-
inkscape:version="0.48.5 r10040"
|
17
|
-
sodipodi:docname="offset.svg">
|
18
|
-
<defs
|
19
|
-
id="defs4" />
|
20
|
-
<sodipodi:namedview
|
21
|
-
id="base"
|
22
|
-
pagecolor="#ffffff"
|
23
|
-
bordercolor="#666666"
|
24
|
-
borderopacity="1.0"
|
25
|
-
inkscape:pageopacity="0.0"
|
26
|
-
inkscape:pageshadow="2"
|
27
|
-
inkscape:zoom="0.76264655"
|
28
|
-
inkscape:cx="373.79617"
|
29
|
-
inkscape:cy="373.69867"
|
30
|
-
inkscape:document-units="px"
|
31
|
-
inkscape:current-layer="layer1"
|
32
|
-
showgrid="false"
|
33
|
-
inkscape:window-width="1440"
|
34
|
-
inkscape:window-height="776"
|
35
|
-
inkscape:window-x="0"
|
36
|
-
inkscape:window-y="0"
|
37
|
-
inkscape:window-maximized="1"
|
38
|
-
fit-margin-top="0"
|
39
|
-
fit-margin-left="0"
|
40
|
-
fit-margin-right="0"
|
41
|
-
fit-margin-bottom="0" />
|
42
|
-
<metadata
|
43
|
-
id="metadata7">
|
44
|
-
<rdf:RDF>
|
45
|
-
<cc:Work
|
46
|
-
rdf:about="">
|
47
|
-
<dc:format>image/svg+xml</dc:format>
|
48
|
-
<dc:type
|
49
|
-
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
50
|
-
<dc:title />
|
51
|
-
</cc:Work>
|
52
|
-
</rdf:RDF>
|
53
|
-
</metadata>
|
54
|
-
<g
|
55
|
-
inkscape:label="Layer 1"
|
56
|
-
inkscape:groupmode="layer"
|
57
|
-
id="layer1"
|
58
|
-
transform="translate(5.1573995,-302.70286)">
|
59
|
-
<path
|
60
|
-
sodipodi:type="arc"
|
61
|
-
style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
62
|
-
id="thing"
|
63
|
-
sodipodi:cx="159.99248"
|
64
|
-
sodipodi:cy="152.67546"
|
65
|
-
sodipodi:rx="59.401001"
|
66
|
-
sodipodi:ry="59.401001"
|
67
|
-
d="m 219.39348,152.67546 c 0,32.80627 -26.59474,59.401 -59.401,59.401 -32.80627,0 -59.401,-26.59473 -59.401,-59.401 0,-32.80627 26.59473,-59.401 59.401,-59.401 32.80626,0 59.401,26.59473 59.401,59.401 z"
|
68
|
-
transform="matrix(0.95784259,0,0,0.95784259,531.73189,844.72627)"
|
69
|
-
inkscape:label="thing" />
|
70
|
-
</g>
|
71
|
-
</svg>
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2
|
+
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
3
|
+
|
4
|
+
<svg
|
5
|
+
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
6
|
+
xmlns:cc="http://creativecommons.org/ns#"
|
7
|
+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
8
|
+
xmlns:svg="http://www.w3.org/2000/svg"
|
9
|
+
xmlns="http://www.w3.org/2000/svg"
|
10
|
+
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
11
|
+
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
12
|
+
width="747.59235"
|
13
|
+
height="747.39734"
|
14
|
+
id="svg2"
|
15
|
+
version="1.1"
|
16
|
+
inkscape:version="0.48.5 r10040"
|
17
|
+
sodipodi:docname="offset.svg">
|
18
|
+
<defs
|
19
|
+
id="defs4" />
|
20
|
+
<sodipodi:namedview
|
21
|
+
id="base"
|
22
|
+
pagecolor="#ffffff"
|
23
|
+
bordercolor="#666666"
|
24
|
+
borderopacity="1.0"
|
25
|
+
inkscape:pageopacity="0.0"
|
26
|
+
inkscape:pageshadow="2"
|
27
|
+
inkscape:zoom="0.76264655"
|
28
|
+
inkscape:cx="373.79617"
|
29
|
+
inkscape:cy="373.69867"
|
30
|
+
inkscape:document-units="px"
|
31
|
+
inkscape:current-layer="layer1"
|
32
|
+
showgrid="false"
|
33
|
+
inkscape:window-width="1440"
|
34
|
+
inkscape:window-height="776"
|
35
|
+
inkscape:window-x="0"
|
36
|
+
inkscape:window-y="0"
|
37
|
+
inkscape:window-maximized="1"
|
38
|
+
fit-margin-top="0"
|
39
|
+
fit-margin-left="0"
|
40
|
+
fit-margin-right="0"
|
41
|
+
fit-margin-bottom="0" />
|
42
|
+
<metadata
|
43
|
+
id="metadata7">
|
44
|
+
<rdf:RDF>
|
45
|
+
<cc:Work
|
46
|
+
rdf:about="">
|
47
|
+
<dc:format>image/svg+xml</dc:format>
|
48
|
+
<dc:type
|
49
|
+
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
50
|
+
<dc:title />
|
51
|
+
</cc:Work>
|
52
|
+
</rdf:RDF>
|
53
|
+
</metadata>
|
54
|
+
<g
|
55
|
+
inkscape:label="Layer 1"
|
56
|
+
inkscape:groupmode="layer"
|
57
|
+
id="layer1"
|
58
|
+
transform="translate(5.1573995,-302.70286)">
|
59
|
+
<path
|
60
|
+
sodipodi:type="arc"
|
61
|
+
style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
|
62
|
+
id="thing"
|
63
|
+
sodipodi:cx="159.99248"
|
64
|
+
sodipodi:cy="152.67546"
|
65
|
+
sodipodi:rx="59.401001"
|
66
|
+
sodipodi:ry="59.401001"
|
67
|
+
d="m 219.39348,152.67546 c 0,32.80627 -26.59474,59.401 -59.401,59.401 -32.80627,0 -59.401,-26.59473 -59.401,-59.401 0,-32.80627 26.59473,-59.401 59.401,-59.401 32.80626,0 59.401,26.59473 59.401,59.401 z"
|
68
|
+
transform="matrix(0.95784259,0,0,0.95784259,531.73189,844.72627)"
|
69
|
+
inkscape:label="thing" />
|
70
|
+
</g>
|
71
|
+
</svg>
|
@@ -1,23 +1,23 @@
|
|
1
|
-
require 'squib'
|
2
|
-
|
3
|
-
# For decks with both landscape and portrait orientations,
|
4
|
-
# we recommend using two separate decks.
|
5
|
-
# For print-on-demand, we can rotate all of the images in the final step.
|
6
|
-
|
7
|
-
# Normal cards
|
8
|
-
Squib::Deck.new(width: 825, height: 1125) do
|
9
|
-
background color: '#aaa'
|
10
|
-
|
11
|
-
text str: "This is portrait"
|
12
|
-
|
13
|
-
save_png prefix: "portrait_"
|
14
|
-
end
|
15
|
-
|
16
|
-
# Money cards are landscape
|
17
|
-
Squib::Deck.new(width: 1125, height: 825) do
|
18
|
-
background color: '#aaa'
|
19
|
-
|
20
|
-
text str: "This is landscape"
|
21
|
-
|
22
|
-
save_png prefix: "landscape_", rotate: true
|
1
|
+
require 'squib'
|
2
|
+
|
3
|
+
# For decks with both landscape and portrait orientations,
|
4
|
+
# we recommend using two separate decks.
|
5
|
+
# For print-on-demand, we can rotate all of the images in the final step.
|
6
|
+
|
7
|
+
# Normal cards
|
8
|
+
Squib::Deck.new(width: 825, height: 1125) do
|
9
|
+
background color: '#aaa'
|
10
|
+
|
11
|
+
text str: "This is portrait"
|
12
|
+
|
13
|
+
save_png prefix: "portrait_"
|
14
|
+
end
|
15
|
+
|
16
|
+
# Money cards are landscape
|
17
|
+
Squib::Deck.new(width: 1125, height: 825) do
|
18
|
+
background color: '#aaa'
|
19
|
+
|
20
|
+
text str: "This is landscape"
|
21
|
+
|
22
|
+
save_png prefix: "landscape_", rotate: true
|
23
23
|
end
|
data/samples/ranges.rb
CHANGED
@@ -1,55 +1,55 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'squib'
|
3
|
-
|
4
|
-
data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
|
5
|
-
'type' => ['Thug', 'Thinker', 'Thinker'],
|
6
|
-
'level' => [1,2,3]}
|
7
|
-
|
8
|
-
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
9
|
-
# Default range is :all
|
10
|
-
background color: :white
|
11
|
-
text str: data['name'], x: 250, y: 55, font: 'Arial 54'
|
12
|
-
text str: data['level'], x: 65, y: 40, font: 'Arial 72'
|
13
|
-
|
14
|
-
# Could be explicit about using :all, too
|
15
|
-
text range: :all,
|
16
|
-
str: data['type'], x: 40, y: 128, font: 'Arial 18',
|
17
|
-
width: 100, align: :center
|
18
|
-
|
19
|
-
# Ranges are inclusive, zero-based
|
20
|
-
text range: 0..1, str: "Thief and Grifter only!!", x: 25, y:200
|
21
|
-
|
22
|
-
# Integers are also allowed
|
23
|
-
text range: 0, str: "Thief only!", x: 25, y: 250
|
24
|
-
|
25
|
-
# Negatives go from the back of the deck
|
26
|
-
text range: -1, str: "Mastermind only!", x: 25, y: 250
|
27
|
-
text range: -2..-1, str: "Grifter and Mastermind only!", x: 25, y: 650
|
28
|
-
|
29
|
-
# We can use Arrays too!
|
30
|
-
text range: [0,2], str: "Thief and Mastermind only!!", x: 25, y:300
|
31
|
-
|
32
|
-
# Just about everything in Squib can be given an array that
|
33
|
-
# corresponds to the deck's cards. This allows for each card to be styled differently
|
34
|
-
# This renders three cards, with three strings that had three different colors at three different locations.
|
35
|
-
text str: %w(red green blue),
|
36
|
-
color: [:red, :green, :blue],
|
37
|
-
x: [40, 80, 120],
|
38
|
-
y: [700, 750, 800]
|
39
|
-
|
40
|
-
# Useful idiom: construct a hash from card names back to its index (ID),
|
41
|
-
# then use a range. No need to memorize IDs, and you can add cards easily
|
42
|
-
id = {} ; data['name'].each_with_index{ |name,i| id[name] = i}
|
43
|
-
text range: id['Thief']..id['Grifter'],
|
44
|
-
str: "Thief through Grifter with id lookup!!",
|
45
|
-
x:25, y: 400
|
46
|
-
|
47
|
-
# Useful idiom: generate arrays from a column called 'type'
|
48
|
-
type = {}; data['type'].each_with_index{ |t,i| (type[t] ||= []) << i}
|
49
|
-
text range: type['Thinker'],
|
50
|
-
str: "Only for Thinkers!",
|
51
|
-
x:25, y: 500
|
52
|
-
|
53
|
-
save prefix: 'ranges_', format: :png
|
54
|
-
end
|
55
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'squib'
|
3
|
+
|
4
|
+
data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
|
5
|
+
'type' => ['Thug', 'Thinker', 'Thinker'],
|
6
|
+
'level' => [1,2,3]}
|
7
|
+
|
8
|
+
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
9
|
+
# Default range is :all
|
10
|
+
background color: :white
|
11
|
+
text str: data['name'], x: 250, y: 55, font: 'Arial 54'
|
12
|
+
text str: data['level'], x: 65, y: 40, font: 'Arial 72'
|
13
|
+
|
14
|
+
# Could be explicit about using :all, too
|
15
|
+
text range: :all,
|
16
|
+
str: data['type'], x: 40, y: 128, font: 'Arial 18',
|
17
|
+
width: 100, align: :center
|
18
|
+
|
19
|
+
# Ranges are inclusive, zero-based
|
20
|
+
text range: 0..1, str: "Thief and Grifter only!!", x: 25, y:200
|
21
|
+
|
22
|
+
# Integers are also allowed
|
23
|
+
text range: 0, str: "Thief only!", x: 25, y: 250
|
24
|
+
|
25
|
+
# Negatives go from the back of the deck
|
26
|
+
text range: -1, str: "Mastermind only!", x: 25, y: 250
|
27
|
+
text range: -2..-1, str: "Grifter and Mastermind only!", x: 25, y: 650
|
28
|
+
|
29
|
+
# We can use Arrays too!
|
30
|
+
text range: [0,2], str: "Thief and Mastermind only!!", x: 25, y:300
|
31
|
+
|
32
|
+
# Just about everything in Squib can be given an array that
|
33
|
+
# corresponds to the deck's cards. This allows for each card to be styled differently
|
34
|
+
# This renders three cards, with three strings that had three different colors at three different locations.
|
35
|
+
text str: %w(red green blue),
|
36
|
+
color: [:red, :green, :blue],
|
37
|
+
x: [40, 80, 120],
|
38
|
+
y: [700, 750, 800]
|
39
|
+
|
40
|
+
# Useful idiom: construct a hash from card names back to its index (ID),
|
41
|
+
# then use a range. No need to memorize IDs, and you can add cards easily
|
42
|
+
id = {} ; data['name'].each_with_index{ |name,i| id[name] = i}
|
43
|
+
text range: id['Thief']..id['Grifter'],
|
44
|
+
str: "Thief through Grifter with id lookup!!",
|
45
|
+
x:25, y: 400
|
46
|
+
|
47
|
+
# Useful idiom: generate arrays from a column called 'type'
|
48
|
+
type = {}; data['type'].each_with_index{ |t,i| (type[t] ||= []) << i}
|
49
|
+
text range: type['Thinker'],
|
50
|
+
str: "Only for Thinkers!",
|
51
|
+
x:25, y: 500
|
52
|
+
|
53
|
+
save prefix: 'ranges_', format: :png
|
54
|
+
end
|
55
|
+
|