squib 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +9 -0
  4. data/README.md +38 -33
  5. data/Rakefile +1 -1
  6. data/bin/squib +6 -6
  7. data/lib/squib.rb +8 -8
  8. data/lib/squib/api/background.rb +3 -3
  9. data/lib/squib/api/data.rb +5 -6
  10. data/lib/squib/api/image.rb +13 -10
  11. data/lib/squib/api/save.rb +4 -5
  12. data/lib/squib/api/settings.rb +4 -4
  13. data/lib/squib/api/shapes.rb +20 -20
  14. data/lib/squib/api/text.rb +11 -11
  15. data/lib/squib/api/units.rb +4 -4
  16. data/lib/squib/card.rb +5 -5
  17. data/lib/squib/commands/new.rb +5 -5
  18. data/lib/squib/constants.rb +10 -10
  19. data/lib/squib/deck.rb +24 -22
  20. data/lib/squib/graphics/background.rb +3 -3
  21. data/lib/squib/graphics/image.rb +13 -6
  22. data/lib/squib/graphics/save_doc.rb +13 -11
  23. data/lib/squib/graphics/save_images.rb +3 -3
  24. data/lib/squib/graphics/shapes.rb +9 -8
  25. data/lib/squib/graphics/text.rb +61 -59
  26. data/lib/squib/input_helpers.rb +13 -13
  27. data/lib/squib/progress.rb +4 -4
  28. data/lib/squib/project_template/Gemfile +1 -1
  29. data/lib/squib/project_template/deck.rb +3 -3
  30. data/lib/squib/version.rb +6 -2
  31. data/samples/autoscale_font.rb +4 -4
  32. data/samples/basic.rb +6 -7
  33. data/samples/cairo_access.rb +27 -0
  34. data/samples/colors.rb +2 -2
  35. data/samples/custom-layout.yml +5 -5
  36. data/samples/custom_config.rb +4 -4
  37. data/samples/draw_shapes.rb +8 -8
  38. data/samples/hello_world.rb +2 -3
  39. data/samples/load_images.rb +6 -1
  40. data/samples/portrait-landscape.rb +7 -7
  41. data/samples/ranges.rb +13 -14
  42. data/samples/save_pdf.rb +2 -2
  43. data/samples/text_options.rb +17 -17
  44. data/samples/tgc_proofs.rb +3 -3
  45. data/samples/use_layout.rb +3 -3
  46. data/spec/api/api_text_spec.rb +11 -17
  47. data/spec/commands/new_spec.rb +10 -10
  48. data/spec/data/easy-circular-extends.yml +1 -1
  49. data/spec/data/hard-circular-extends.yml +2 -2
  50. data/spec/data/multi-extends-single-entry.yml +3 -3
  51. data/spec/data/multi-level-extends.yml +1 -1
  52. data/spec/data/no-extends.yml +2 -2
  53. data/spec/data/pre-extends.yml +1 -1
  54. data/spec/data/self-circular-extends.yml +1 -1
  55. data/spec/data/single-extends.yml +1 -1
  56. data/spec/data/single-level-multi-extends.yml +1 -1
  57. data/spec/deck_spec.rb +62 -62
  58. data/spec/graphics/graphics_images_spec.rb +79 -0
  59. data/spec/graphics/graphics_save_doc_spec.rb +66 -0
  60. data/spec/graphics/graphics_shapes_spec.rb +74 -0
  61. data/spec/graphics/graphics_text_spec.rb +135 -0
  62. data/spec/input_helpers_spec.rb +61 -40
  63. data/spec/samples_run_spec.rb +6 -6
  64. data/spec/spec_helper.rb +32 -1
  65. data/squib.gemspec +21 -21
  66. metadata +22 -14
data/samples/basic.rb CHANGED
@@ -1,7 +1,6 @@
1
- #!/usr/bin/env ruby
2
1
  require 'squib'
3
2
 
4
- data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
3
+ data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
5
4
  'level' => [1,2,3]}
6
5
 
7
6
  Squib::Deck.new(width: 825, height: 1125, cards: 3) do
@@ -10,11 +9,11 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
10
9
  rect x: 75, y: 75, width: 128, height: 128, radius: 25
11
10
 
12
11
  text str: data['name'], x: 220, y: 78, font: 'Arial 54'
13
- text str: data['level'], x: 75, y: 85, width: 128,
12
+ text str: data['level'], x: 75, y: 85, width: 128,
14
13
  font: 'Arial 72', align: :center
15
14
 
16
- png range: [0,2], file: 'shiny-purse.png', x: 620, y: 75
17
- svg range: 1..2, file: 'spanner.svg', x: 620, y: 218
15
+ png range: [0,2], file: 'shiny-purse.png', x: 620, y: 75
16
+ svg range: 1..2, file: 'spanner.svg', x: 620, y: 218
18
17
 
19
- save prefix: 'basic_', format: :png#, progress_bar: true
20
- end
18
+ save prefix: 'basic_', format: :png
19
+ end
@@ -0,0 +1,27 @@
1
+ require 'squib'
2
+
3
+ Squib::Deck.new(cards: 2) do
4
+
5
+ # If you really need something custom-made, the underlying cairo context
6
+ # can be accessed directly via each Squib::Card
7
+ #
8
+ # WARNING! Input validation is not done on Squib::Cards. Proceed at your own risk.
9
+
10
+ # The recommended approach is to use Deck's Enumerable, which iterates over Squib::Cards
11
+ # I also recommend wrapping it in a Cairo save/restore, which Squib calls "use_cairo"
12
+ each do |card|
13
+ card.use_cairo do |cairo_context|
14
+ cairo_context.set_source_color(:white)
15
+ cairo_context.paint
16
+ end
17
+ end
18
+
19
+ # Or the square bracket accessors []
20
+ self[1].use_cairo do |cairo_context|
21
+ cairo_context.circle(50, 50, 50)
22
+ cairo_context.set_source_color(:red)
23
+ cairo_context.fill
24
+ end
25
+
26
+ save_png prefix: 'cairo_access_'
27
+ end
data/samples/colors.rb CHANGED
@@ -12,5 +12,5 @@ Squib::Deck.new(width: 825, height: 1125, cards: 1) do
12
12
  text color: '#ffff000000009999', str: '12-hex (alpha)', x: 50, y: y+=50
13
13
  text color: :burnt_orange, str: 'Symbols of constants too', x: 50, y: y+=50
14
14
 
15
- save_png prefix: "colors_"
16
- end
15
+ save_png prefix: 'colors_'
16
+ end
@@ -1,4 +1,4 @@
1
- frame:
1
+ frame:
2
2
  x: 38
3
3
  y: 38
4
4
  width: 750
@@ -10,7 +10,7 @@ title:
10
10
  width: 625
11
11
  height: 100
12
12
  align: !ruby/symbol center #see http://www.yaml.org/YAML_for_ruby.html#symbols
13
- valign: !ruby/symbol middle
13
+ valign: !ruby/symbol middle
14
14
  subtitle:
15
15
  x: 150
16
16
  y: 150
@@ -37,15 +37,15 @@ icon_right:
37
37
  # Called "extends"
38
38
  # Any layout can extend another layout, so long as it's not a circle
39
39
  # Order doesn't matter since it's done after YAML procesing
40
- # And, if the entry overrides
40
+ # And, if the entry overrides
41
41
  bonus: #becomes our bonus rectangle
42
42
  x: 250
43
43
  y: 600
44
44
  width: 300
45
45
  height: 200
46
46
  radius: 32
47
- bonus_inner:
48
- extends: bonus
47
+ bonus_inner:
48
+ extends: bonus
49
49
  x: += 10 # i.e. 260
50
50
  y: += 10 # i.e. 610
51
51
  width: -= 20 # i.e. 180
@@ -3,10 +3,10 @@ require 'squib'
3
3
 
4
4
  Squib::Deck.new(config: 'custom-config.yml') do
5
5
  # Custom color defined in our config
6
- background color: :foo
6
+ background color: :foo
7
7
 
8
8
  # Hints are turned on in the config file
9
- text str: "The Title", x: 0, y: 78, width: 825,
9
+ text str: 'The Title', x: 0, y: 78, width: 825,
10
10
  font: 'Arial 72', align: :center
11
11
 
12
12
  # Progress bars are shown for these commands
@@ -14,6 +14,6 @@ Squib::Deck.new(config: 'custom-config.yml') do
14
14
  png file: 'shiny-purse2.png', x: 620, y: 75
15
15
  svg file: 'spanner2.svg', x: 620, y: 218
16
16
  save_png prefix: 'custom-config_'
17
- save_pdf file: "custom-config-out.pdf"
17
+ save_pdf file: 'custom-config-out.pdf'
18
18
 
19
- end
19
+ end
@@ -1,19 +1,19 @@
1
1
  require 'squib'
2
2
 
3
- Squib::Deck.new do
4
- rect x: 300, y: 300, width: 400, height: 400,
3
+ Squib::Deck.new do
4
+ rect x: 300, y: 300, width: 400, height: 400,
5
5
  fill_color: :blue, stroke_color: :red, stroke_width: 50.0
6
6
 
7
7
  circle x: 600, y: 600, radius: 75,
8
- fill_color: :gray, stroke_color: :green, stroke_width: 8.0
8
+ fill_color: :gray, stroke_color: :green, stroke_width: 8.0
9
9
 
10
- triangle x1: 50, y1: 50,
11
- x2: 150, y2: 150,
10
+ triangle x1: 50, y1: 50,
11
+ x2: 150, y2: 150,
12
12
  x3: 75, y3: 250
13
13
 
14
- line x1: 50, y1: 550,
14
+ line x1: 50, y1: 550,
15
15
  x2: 150, y2: 650,
16
- stroke_width: 25.0
16
+ stroke_width: 25.0
17
17
 
18
18
  save_png prefix: 'shape_'
19
- end
19
+ end
@@ -1,7 +1,6 @@
1
- #!/usr/bin/env ruby
2
1
  require 'squib'
3
2
 
4
- Squib::Deck.new do
5
- text str: 'Hello, World!'
3
+ Squib::Deck.new(cards: 2) do
4
+ text str: %w(Hello World!)
6
5
  save_png
7
6
  end
@@ -19,11 +19,16 @@ Squib::Deck.new(width: 825, height: 1125, cards: 1) do
19
19
  # relative to the SVG page. See this example in an SVG editor
20
20
  svg file: 'offset.svg', id: 'thing', x: 0, y: 0, width: 600, height: 600
21
21
 
22
- # Over 15 different blending operators are supported.
22
+ # Over 15 different blending operators are supported.
23
23
  # See http://cairographics.org/operators
24
24
  # Alpha transparency too
25
25
  png file: 'ball.png', x: 50, y: 700
26
26
  png file: 'grit.png', x: 70, y: 750, blend: :color_burn, alpha: 0.75
27
27
 
28
+ # Images can be rotated around their upper-left corner
29
+ png file: 'shiny-purse.png', x: 300, y: 700, angle: 0.0 # default (no rotate)
30
+ png file: 'shiny-purse.png', x: 300, y: 800, angle: Math::PI / 4
31
+ svg file: 'spanner.svg', x: 300, y: 900, angle: Math::PI / 2 - 0.1
32
+
28
33
  save prefix: 'load_images_', format: :png
29
34
  end
@@ -1,23 +1,23 @@
1
1
  require 'squib'
2
2
 
3
3
  # For decks with both landscape and portrait orientations,
4
- # we recommend using two separate decks.
4
+ # we recommend using two separate decks.
5
5
  # For print-on-demand, we can rotate all of the images in the final step.
6
6
 
7
7
  # Normal cards
8
- Squib::Deck.new(width: 825, height: 1125) do
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'
12
12
 
13
- save_png prefix: "portrait_"
13
+ save_png prefix: 'portrait_'
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'
21
21
 
22
- save_png prefix: "landscape_", rotate: true
23
- end
22
+ save_png prefix: 'landscape_', rotate: true
23
+ end
data/samples/ranges.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'squib'
3
3
 
4
- data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
4
+ data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
5
5
  'type' => ['Thug', 'Thinker', 'Thinker'],
6
6
  'level' => [1,2,3]}
7
7
 
@@ -12,22 +12,22 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
12
12
  text str: data['level'], x: 65, y: 40, font: 'Arial 72'
13
13
 
14
14
  # Could be explicit about using :all, too
15
- text range: :all,
16
- str: data['type'], x: 40, y: 128, font: 'Arial 18',
15
+ text range: :all,
16
+ str: data['type'], x: 40, y: 128, font: 'Arial 18',
17
17
  width: 100, align: :center
18
18
 
19
19
  # Ranges are inclusive, zero-based
20
- text range: 0..1, str: "Thief and Grifter only!!", x: 25, y:200
20
+ text range: 0..1, str: 'Thief and Grifter only!!', x: 25, y:200
21
21
 
22
22
  # Integers are also allowed
23
- text range: 0, str: "Thief only!", x: 25, y: 250
23
+ text range: 0, str: 'Thief only!', x: 25, y: 250
24
24
 
25
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
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
28
 
29
29
  # We can use Arrays too!
30
- text range: [0,2], str: "Thief and Mastermind only!!", x: 25, y:300
30
+ text range: [0,2], str: 'Thief and Mastermind only!!', x: 25, y:300
31
31
 
32
32
  # Just about everything in Squib can be given an array that
33
33
  # corresponds to the deck's cards. This allows for each card to be styled differently
@@ -40,16 +40,15 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
40
40
  # Useful idiom: construct a hash from card names back to its index (ID),
41
41
  # then use a range. No need to memorize IDs, and you can add cards easily
42
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!!",
43
+ text range: id['Thief']..id['Grifter'],
44
+ str: 'Thief through Grifter with id lookup!!',
45
45
  x:25, y: 400
46
46
 
47
47
  # Useful idiom: generate arrays from a column called 'type'
48
48
  type = {}; data['type'].each_with_index{ |t,i| (type[t] ||= []) << i}
49
- text range: type['Thinker'],
50
- str: "Only for Thinkers!",
49
+ text range: type['Thinker'],
50
+ str: 'Only for Thinkers!',
51
51
  x:25, y: 500
52
-
52
+
53
53
  save prefix: 'ranges_', format: :png
54
54
  end
55
-
data/samples/save_pdf.rb CHANGED
@@ -7,8 +7,8 @@ Squib::Deck.new(width: 825, height: 1125, cards: 16) do
7
7
 
8
8
  text str: (1..16).to_a, x: 220, y: 78, font: 'Arial 54'
9
9
 
10
- save_pdf file: "sample-save-pdf.pdf", margin: 75, gap: 5, trim: 37
10
+ save_pdf file: 'sample-save-pdf.pdf', margin: 75, gap: 5, trim: 37
11
11
 
12
12
  #Note that our PNGs still are not trimmed even though the pdf ones are
13
- save_png range: 1, prefix: "save_pdf_"
13
+ save_png range: 1, prefix: 'save_pdf_'
14
14
  end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'squib'
3
3
 
4
- data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
4
+ data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
5
5
  'level' => [1,2,3]}
6
6
  longtext = "This is left-justified text.\nWhat do you know about tweetle beetles? well... \nWhen 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. AND... When beetles fight these battles in a bottle with their paddles and the bottle's on a poodle and the poodle's eating noodles... ...they call this a muddle puddle tweetle poodle beetle noodle bottle paddle battle."
7
7
 
@@ -16,52 +16,52 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
16
16
 
17
17
  text str: "UTF-8 \u2663", x: 565, y: 150, font: 'Arial weight=900 36'
18
18
 
19
- text str: "Font strings are expressive!", x:65, y: 200,
19
+ text str: 'Font strings are expressive!', x:65, y: 200,
20
20
  font: 'Impact bold italic 36'
21
21
 
22
- text str: "Font strings are expressive!", x:65, y: 300,
22
+ text str: 'Font strings are expressive!', x:65, y: 300,
23
23
  font: 'Arial,Verdana weight=900 style=oblique 36'
24
24
 
25
- text str: "Font string sizes can be overridden per card.", x: 65, y: 350,
25
+ text str: 'Font string sizes can be overridden per card.', x: 65, y: 350,
26
26
  font: 'Impact 36', font_size: [16, 20, 24]
27
27
 
28
- text str: "This text has fixed width, fixed height, center-aligned, middle-valigned, and has a red hint",
28
+ text str: 'This text has fixed width, fixed height, center-aligned, middle-valigned, and has a red hint',
29
29
  hint: :red,
30
30
  x: 65, y: 400,
31
31
  width: 300, height: 200,
32
- align: :center, valign: :middle,
32
+ align: :center, valign: 'MIDDLE', #case-insenstive strings allowed too.
33
33
  font: 'Arial 18'
34
34
 
35
- text str: "Ellipsization!\nThe ultimate question of life, the universe, and everything to life and everything is 42",
35
+ text str: 'Ellipsization!\nThe ultimate question of life, the universe, and everything to life and everything is 42',
36
36
  hint: :green, font: 'Arial 22',
37
37
  x: 450, y: 400,
38
38
  width: 280, height: 180,
39
39
  ellipsize: true
40
40
 
41
41
  hint text: :cyan
42
- text str: "Text hints are also globally togglable!",
42
+ text str: 'Text hints are also globally togglable!',
43
43
  x: 65, y: 625,
44
44
  font: 'Arial 22'
45
45
  hint text: :off
46
- text str: "See? No hint here.",
46
+ text str: 'See? No hint here.',
47
47
  x: 565, y: 625,
48
48
  font: 'Arial 22'
49
49
 
50
- text str: "Rotated",
51
- x: 565, y: 675, angle: 0.1,
52
- font: 'Arial 18'
50
+ text str: 'Rotated',
51
+ x: 565, y: 675, angle: 0.2,
52
+ font: 'Arial 18', hint: :red
53
53
 
54
54
  text str: longtext, font: 'Arial 16',
55
- x: 65, y: 700,
56
- width: inches(2.25), height: inches(1),
55
+ x: 65, y: 700,
56
+ width: inches(2.25), height: inches(1),
57
57
  justify: true
58
58
 
59
- text str: "<b>Markup</b> is also <i>quite</i> <s>easy</s> awesome",
59
+ text str: '<b>Markup</b> is also <i>quite</i> <s>easy</s> awesome',
60
60
  markup: true,
61
61
  x: 50, y: 1000,
62
- width: 750, height: 100,
62
+ width: 750, height: 100,
63
63
  valign: :bottom,
64
64
  font: 'Arial 32', hint: :cyan
65
-
65
+
66
66
  save prefix: 'text_', format: :png
67
67
  end
@@ -2,7 +2,7 @@
2
2
  require 'squib'
3
3
 
4
4
  # This sample uses a proof overlay from TheGameCrafter.com to check bleed
5
- Squib::Deck.new(width: 825, height: 1125, cards: 1) do
5
+ Squib::Deck.new(width: 825, height: 1125, cards: 1) do
6
6
  background color: :white
7
7
  rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38
8
8
  rect x: 75, y: 75, width: 128, height: 128, x_radius: 25, y_radius: 25
@@ -15,6 +15,6 @@ Squib::Deck.new(width: 825, height: 1125, cards: 1) do
15
15
 
16
16
  # TGC proof overlay
17
17
  png file: 'pokercard.png', x:0, y:0, alpha: 0.5
18
-
18
+
19
19
  save_png prefix: 'tgc_sample_'
20
- end
20
+ end
@@ -1,6 +1,6 @@
1
1
  require 'squib'
2
2
 
3
- Squib::Deck.new(layout: 'custom-layout.yml') do
3
+ Squib::Deck.new(layout: 'custom-layout.yml') do
4
4
  background color: :white
5
5
  hint text: :cyan
6
6
 
@@ -29,6 +29,6 @@ Squib::Deck.new(layout: 'custom-layout.yml') do
29
29
  # For debugging purposes, you can always print out the loaded layout
30
30
  #require 'pp'
31
31
  #pp @layout
32
-
32
+
33
33
  save_png prefix: 'layout_'
34
- end
34
+ end
@@ -3,37 +3,31 @@ require 'squib'
3
3
 
4
4
  describe Squib::Deck, '#text' do
5
5
 
6
- context "fonts" do
6
+ context 'fonts' do
7
7
  it "should use the default font when #text and #set_font don't specify" do
8
8
  card = instance_double(Squib::Card)
9
- expect(card).to receive(:text).with('a', 'Arial 36',
10
- anything, anything, anything,anything,anything,anything, anything, anything, anything,anything, anything, anything, anything, anything, anything
11
- ).once
12
- Squib::Deck.new do
13
- @cards = [card]
9
+ expect(card).to receive(:text).with('a', 'Arial 36', *([anything] * 15)).once
10
+ Squib::Deck.new do
11
+ @cards = [card]
14
12
  text str: 'a'
15
13
  end
16
14
  end
17
15
 
18
16
  it "should use the #set_font when #text doesn't specify" do
19
17
  card = instance_double(Squib::Card)
20
- expect(card).to receive(:text).with('a', 'Times New Roman 16',
21
- anything, anything, anything, anything,anything,anything, anything, anything, anything,anything, anything, anything, anything, anything, anything
22
- ).once
23
- Squib::Deck.new do
24
- @cards = [card]
18
+ expect(card).to receive(:text).with('a', 'Times New Roman 16', *([anything] * 15)).once
19
+ Squib::Deck.new do
20
+ @cards = [card]
25
21
  set font: 'Times New Roman 16'
26
22
  text str: 'a'
27
23
  end
28
24
  end
29
25
 
30
- it "should use the specified font no matter what" do
26
+ it 'should use the specified font no matter what' do
31
27
  card = instance_double(Squib::Card)
32
- expect(card).to receive(:text).with('a', 'Arial 18',
33
- anything, anything, anything, anything,anything,anything,anything, anything, anything,anything, anything, anything, anything, anything, anything
34
- ).once
35
- Squib::Deck.new do
36
- @cards = [card]
28
+ expect(card).to receive(:text).with('a', 'Arial 18', *([anything] * 15)).once
29
+ Squib::Deck.new do
30
+ @cards = [card]
37
31
  set font: 'Times New Roman 16'
38
32
  text str: 'a', font: 'Arial 18'
39
33
  end