squib 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +29 -29
  3. data/.travis.yml +6 -6
  4. data/.yardopts +7 -5
  5. data/Gemfile +2 -2
  6. data/LICENSE.txt +22 -22
  7. data/README.md +245 -92
  8. data/Rakefile +11 -11
  9. data/bin/squib +18 -18
  10. data/lib/squib.rb +31 -18
  11. data/lib/squib/api/background.rb +18 -16
  12. data/lib/squib/api/data.rb +52 -52
  13. data/lib/squib/api/image.rb +66 -48
  14. data/lib/squib/api/save.rb +43 -37
  15. data/lib/squib/api/settings.rb +38 -35
  16. data/lib/squib/api/shapes.rb +116 -106
  17. data/lib/squib/api/text.rb +50 -45
  18. data/lib/squib/api/units.rb +16 -16
  19. data/lib/squib/card.rb +42 -36
  20. data/lib/squib/commands/new.rb +43 -39
  21. data/lib/squib/constants.rb +104 -39
  22. data/lib/squib/deck.rb +116 -113
  23. data/lib/squib/graphics/background.rb +13 -12
  24. data/lib/squib/graphics/image.rb +47 -28
  25. data/lib/squib/graphics/save_doc.rb +54 -50
  26. data/lib/squib/graphics/save_images.rb +32 -10
  27. data/lib/squib/graphics/shapes.rb +59 -55
  28. data/lib/squib/graphics/text.rb +113 -107
  29. data/lib/squib/input_helpers.rb +193 -139
  30. data/lib/squib/progress.rb +38 -0
  31. data/lib/squib/project_template/.gitignore +4 -3
  32. data/lib/squib/project_template/ABOUT.md +19 -19
  33. data/lib/squib/project_template/Gemfile +2 -2
  34. data/lib/squib/project_template/PNP NOTES.md +3 -3
  35. data/lib/squib/project_template/config.yml +20 -2
  36. data/lib/squib/project_template/deck.rb +5 -5
  37. data/lib/squib/version.rb +6 -6
  38. data/samples/ball.png +0 -0
  39. data/samples/basic.rb +19 -19
  40. data/samples/colors.rb +15 -16
  41. data/samples/custom-config.yml +6 -1
  42. data/samples/custom-layout.yml +39 -34
  43. data/samples/custom_config.rb +18 -5
  44. data/samples/customconfig-imgdir/shiny-purse2.png +0 -0
  45. data/samples/customconfig-imgdir/spanner2.svg +91 -0
  46. data/samples/draw_shapes.rb +18 -18
  47. data/samples/excel.rb +19 -19
  48. data/samples/grit.png +0 -0
  49. data/samples/hello_world.rb +6 -6
  50. data/samples/load_images.rb +29 -19
  51. data/samples/offset.svg +71 -0
  52. data/samples/portrait-landscape.rb +23 -0
  53. data/samples/ranges.rb +55 -47
  54. data/samples/save_pdf.rb +14 -14
  55. data/samples/shiny-purse.png +0 -0
  56. data/samples/spanner.svg +91 -91
  57. data/samples/text_options.rb +60 -58
  58. data/samples/tgc_proofs.rb +19 -19
  59. data/samples/units.rb +12 -12
  60. data/samples/use_layout.rb +28 -28
  61. data/spec/api/api_text_spec.rb +42 -36
  62. data/spec/commands/new_spec.rb +47 -47
  63. data/spec/data/multi-extends-single-entry.yml +13 -0
  64. data/spec/data/multi-level-extends.yml +10 -0
  65. data/spec/data/no-extends.yml +5 -0
  66. data/spec/data/single-extends.yml +7 -0
  67. data/spec/data/single-level-multi-extends.yml +12 -0
  68. data/spec/deck_spec.rb +147 -49
  69. data/spec/input_helpers_spec.rb +117 -0
  70. data/spec/samples_run_spec.rb +19 -14
  71. data/spec/spec_helper.rb +3 -0
  72. data/squib.gemspec +46 -42
  73. metadata +78 -4
  74. data/API.md +0 -59
@@ -1,20 +1,20 @@
1
- #!/usr/bin/env ruby
2
- require 'squib'
3
-
4
- # This sample uses a proof overlay from TheGameCrafter.com to check bleed
5
- Squib::Deck.new(width: 825, height: 1125, cards: 1) do
6
- background color: :white
7
- rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38
8
- rect x: 75, y: 75, width: 128, height: 128, x_radius: 25, y_radius: 25
9
-
10
- text str: 'Mastermind', x: 220, y: 78, font: 'Arial 54'
11
- text str: 3, x: 75, y: 85, width: 128, font: 'Arial 72', align: :center
12
-
13
- png file: 'shiny-purse.png', x: 620, y: 75
14
- svg file: 'spanner.svg', x: 620, y: 218
15
-
16
- # TGC proof overlay
17
- png file: 'pokercard.png', x:0, y:0, alpha: 0.5
18
-
19
- save_png prefix: 'tgc_sample_'
1
+ #!/usr/bin/env ruby
2
+ require 'squib'
3
+
4
+ # This sample uses a proof overlay from TheGameCrafter.com to check bleed
5
+ Squib::Deck.new(width: 825, height: 1125, cards: 1) do
6
+ background color: :white
7
+ rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38
8
+ rect x: 75, y: 75, width: 128, height: 128, x_radius: 25, y_radius: 25
9
+
10
+ text str: 'Mastermind', x: 220, y: 78, font: 'Arial 54'
11
+ text str: 3, x: 75, y: 85, width: 128, font: 'Arial 72', align: :center
12
+
13
+ png file: 'shiny-purse.png', x: 620, y: 75
14
+ svg file: 'spanner.svg', x: 620, y: 218
15
+
16
+ # TGC proof overlay
17
+ png file: 'pokercard.png', x:0, y:0, alpha: 0.5
18
+
19
+ save_png prefix: 'tgc_sample_'
20
20
  end
@@ -1,12 +1,12 @@
1
- require 'squib'
2
-
3
- Squib::Deck.new(width: 825, height: 1125, cards: 3) do
4
- background color: :white
5
-
6
- bleed = inches(0.125)
7
- cut_width = inches(2.5)
8
- cut_height = inches(3.5)
9
- rect x: bleed, y: bleed, width: cut_width, height: cut_height, radius: 25
10
-
11
- save prefix: 'units_', format: :png
12
- end
1
+ require 'squib'
2
+
3
+ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
4
+ background color: :white
5
+
6
+ bleed = inches(0.125)
7
+ cut_width = inches(2.5)
8
+ cut_height = inches(3.5)
9
+ rect x: bleed, y: bleed, width: cut_width, height: cut_height, radius: 25
10
+
11
+ save prefix: 'units_', format: :png
12
+ end
@@ -1,29 +1,29 @@
1
- require 'squib'
2
-
3
- Squib::Deck.new(layout: 'custom-layout.yml') do
4
- background color: :white
5
- hint text: :cyan
6
-
7
- # Layouts are YAML files that specify any option as a default
8
- rect layout: :frame
9
-
10
- # You can also override a given layout entry in the command
11
- circle layout: :frame, x: 50, y: 50, radius: 25
12
-
13
- # Lots of commands have the :layout option
14
- text str: 'The Title', layout: :title
15
-
16
- # Layouts also support an "extends" attribute to reuse settings
17
- svg file: 'spanner.svg', layout: :icon_left
18
- png file: 'shiny-purse.png', layout: :icon_middle
19
- svg file: 'spanner.svg', layout: :icon_right
20
-
21
- # Strings can also be used to specify a layout (e.g. from a data file)
22
- text str: 'subtitle', layout: 'subtitle'
23
-
24
- # For debugging purposes, you can always print out the loaded layout
25
- #require 'pp'
26
- #pp @layout
27
-
28
- save_png prefix: 'layout_'
1
+ require 'squib'
2
+
3
+ Squib::Deck.new(layout: 'custom-layout.yml') do
4
+ background color: :white
5
+ hint text: :cyan
6
+
7
+ # Layouts are YAML files that specify any option as a default
8
+ rect layout: :frame
9
+
10
+ # You can also override a given layout entry in the command
11
+ circle layout: :frame, x: 50, y: 50, radius: 25
12
+
13
+ # Lots of commands have the :layout option
14
+ text str: 'The Title', layout: :title
15
+
16
+ # Layouts also support an "extends" attribute to reuse settings
17
+ svg file: 'spanner.svg', layout: :icon_left
18
+ png file: 'shiny-purse.png', layout: :icon_middle
19
+ svg file: 'spanner.svg', layout: :icon_right
20
+
21
+ # Strings can also be used to specify a layout (e.g. from a data file)
22
+ text str: 'subtitle', layout: 'subtitle'
23
+
24
+ # For debugging purposes, you can always print out the loaded layout
25
+ #require 'pp'
26
+ #pp @layout
27
+
28
+ save_png prefix: 'layout_'
29
29
  end
@@ -1,37 +1,43 @@
1
- require 'spec_helper'
2
- require 'squib'
3
-
4
- describe Squib::Deck, '#text' do
5
-
6
- context "when working with fonts" do
7
- it"should use the default font when #text and #set_font don't specify" do
8
- card = instance_double(Squib::Card)
9
- expect(card).to receive(:text).with('a', 'Arial 36', anything, anything, anything, anything).once
10
- Squib::Deck.new do
11
- @cards = [card]
12
- text str: 'a'
13
- end
14
- end
15
-
16
- it "should use the #set_font when #text doesn't specify" do
17
- card = instance_double(Squib::Card)
18
- expect(card).to receive(:text).with('a', 'Times New Roman 16', anything, anything, anything, anything).once
19
- Squib::Deck.new do
20
- @cards = [card]
21
- set font: 'Times New Roman 16'
22
- text str: 'a'
23
- end
24
- end
25
-
26
- it "should use the specified font no matter what" do
27
- card = instance_double(Squib::Card)
28
- expect(card).to receive(:text).with('a', 'Arial 18', anything, anything, anything, anything).once
29
- Squib::Deck.new do
30
- @cards = [card]
31
- set font: 'Times New Roman 16'
32
- text str: 'a', font: 'Arial 18'
33
- end
34
- end
35
- end
36
-
1
+ require 'spec_helper'
2
+ require 'squib'
3
+
4
+ describe Squib::Deck, '#text' do
5
+
6
+ context "fonts" do
7
+ it "should use the default font when #text and #set_font don't specify" do
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
11
+ ).once
12
+ Squib::Deck.new do
13
+ @cards = [card]
14
+ text str: 'a'
15
+ end
16
+ end
17
+
18
+ it "should use the #set_font when #text doesn't specify" do
19
+ 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
22
+ ).once
23
+ Squib::Deck.new do
24
+ @cards = [card]
25
+ set font: 'Times New Roman 16'
26
+ text str: 'a'
27
+ end
28
+ end
29
+
30
+ it "should use the specified font no matter what" do
31
+ 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
34
+ ).once
35
+ Squib::Deck.new do
36
+ @cards = [card]
37
+ set font: 'Times New Roman 16'
38
+ text str: 'a', font: 'Arial 18'
39
+ end
40
+ end
41
+ end
42
+
37
43
  end
@@ -1,48 +1,48 @@
1
- require 'spec_helper'
2
- require 'squib'
3
-
4
- describe Squib::Commands::New do
5
-
6
- describe "#process" do
7
- before(:all) do
8
- @old_stderr = $stderr
9
- $stderr = StringIO.new
10
- @oldpwd = Dir.pwd
11
- Dir.chdir(File.expand_path('../../samples/_output', File.dirname(__FILE__)))
12
- end
13
-
14
- before(:each) do
15
- FileUtils.rm_rf('foo', secure: true)
16
- @cmd = Squib::Commands::New.new
17
- end
18
-
19
- it "raises an error if no directory was specified" do
20
- expect{@cmd.process([])}.to raise_error(ArgumentError, 'Please specify a path.')
21
- end
22
-
23
- it "creates a new template on an fresh directory" do
24
- @cmd.process(['foo'])
25
- expect(File.exists?('foo/deck.rb')).to be true
26
- end
27
-
28
- it "creates a new template on an empty directory" do
29
- Dir.mkdir('foo')
30
- @cmd.process(['foo'])
31
- expect(File.exists?('foo/deck.rb')).to be true
32
- end
33
-
34
- it "does not create a new template on an empty " do
35
- Dir.mkdir('foo')
36
- File.new('foo/somefile.txt', 'w+')
37
- @cmd.process(['foo'])
38
- $stderr.rewind
39
- expect($stderr.string.chomp).to end_with " exists and is not empty. Doing nothing and quitting."
40
- end
41
-
42
- after(:all) do
43
- $stderr = @old_stderr
44
- Dir.chdir(@oldpwd)
45
- end
46
- end
47
-
1
+ require 'spec_helper'
2
+ require 'squib'
3
+
4
+ describe Squib::Commands::New do
5
+
6
+ describe "#process" do
7
+ before(:all) do
8
+ @old_stderr = $stderr
9
+ $stderr = StringIO.new
10
+ @oldpwd = Dir.pwd
11
+ Dir.chdir(File.expand_path('../../samples/_output', File.dirname(__FILE__)))
12
+ end
13
+
14
+ before(:each) do
15
+ FileUtils.rm_rf('foo', secure: true)
16
+ @cmd = Squib::Commands::New.new
17
+ end
18
+
19
+ it "raises an error if no directory was specified" do
20
+ expect{@cmd.process([])}.to raise_error(ArgumentError, 'Please specify a path.')
21
+ end
22
+
23
+ it "creates a new template on an fresh directory" do
24
+ @cmd.process(['foo'])
25
+ expect(File.exists?('foo/deck.rb')).to be true
26
+ end
27
+
28
+ it "creates a new template on an empty directory" do
29
+ Dir.mkdir('foo')
30
+ @cmd.process(['foo'])
31
+ expect(File.exists?('foo/deck.rb')).to be true
32
+ end
33
+
34
+ it "does not create a new template on an empty " do
35
+ Dir.mkdir('foo')
36
+ File.new('foo/somefile.txt', 'w+')
37
+ @cmd.process(['foo'])
38
+ $stderr.rewind
39
+ expect($stderr.string.chomp).to end_with " exists and is not empty. Doing nothing and quitting."
40
+ end
41
+
42
+ after(:all) do
43
+ $stderr = @old_stderr
44
+ Dir.chdir(@oldpwd)
45
+ end
46
+ end
47
+
48
48
  end
@@ -0,0 +1,13 @@
1
+ aunt: &aunt
2
+ a: 101
3
+ b: 102
4
+ c: 103
5
+ uncle: &uncle
6
+ x: 104
7
+ y: 105
8
+ b: 106
9
+ child:
10
+ <<: *uncle
11
+ <<: *aunt
12
+ a: 107
13
+ x: 108
@@ -0,0 +1,10 @@
1
+ frame: &frame
2
+ x: 38
3
+ y: 38
4
+ title: &title
5
+ <<: *frame
6
+ y: 50
7
+ width: 100
8
+ subtitle:
9
+ <<: *title
10
+ y: 150
@@ -0,0 +1,5 @@
1
+ frame:
2
+ x: 38
3
+ valign: !ruby/symbol middle
4
+ str: "blah"
5
+ font: Mr. Font
@@ -0,0 +1,7 @@
1
+ frame: &frame
2
+ x: 38
3
+ y: 38
4
+ title:
5
+ <<: *frame
6
+ y: 50
7
+ width: 100
@@ -0,0 +1,12 @@
1
+ frame: &frame
2
+ x: 38
3
+ y: 38
4
+ title:
5
+ <<: *frame
6
+ y: 50
7
+ width: 100
8
+ title2:
9
+ <<: *frame
10
+ x: 75
11
+ y: 150
12
+ width: 150
@@ -1,49 +1,147 @@
1
- require 'spec_helper'
2
- require 'squib/deck'
3
-
4
- describe Squib::Deck do
5
-
6
- it "initializes with default parameters" do
7
- d = Squib::Deck.new
8
- expect(d.width).to eq(825)
9
- expect(d.height).to eq(1125)
10
- expect(d.cards.size).to eq(1)
11
- end
12
-
13
- context "in dealing with ranges" do
14
- it "calls text on all cards by default" do
15
- card1 = instance_double(Squib::Card)
16
- card2 = instance_double(Squib::Card)
17
- expect(card1).to receive(:text).once
18
- expect(card2).to receive(:text).once
19
- Squib::Deck.new do
20
- @cards = [card1, card2]
21
- text str: 'blah'
22
- end
23
- end
24
-
25
- it "calls text on some cards with an integer" do
26
- card1 = instance_double(Squib::Card)
27
- card2 = instance_double(Squib::Card)
28
- expect(card2).to receive(:text).once
29
- Squib::Deck.new do
30
- @cards = [card1, card2]
31
- text range: 1, str: 'blah'
32
- end
33
- end
34
-
35
- it "calls text with ranges" do
36
- card1 = instance_double(Squib::Card)
37
- card2 = instance_double(Squib::Card)
38
- card3 = instance_double(Squib::Card)
39
- expect(card1).to receive(:text).once
40
- expect(card2).to receive(:text).once
41
- Squib::Deck.new do
42
- @cards = [card1, card2, card3]
43
- text range: 0..1, str: 'blah'
44
- end
45
- end
46
- end
47
-
48
- end#describe
49
-
1
+ require 'spec_helper'
2
+ require 'squib/deck'
3
+
4
+ describe Squib::Deck do
5
+
6
+ it "initializes with default parameters" do
7
+ d = Squib::Deck.new
8
+ expect(d.width).to eq(825)
9
+ expect(d.height).to eq(1125)
10
+ expect(d.cards.size).to eq(1)
11
+ end
12
+
13
+ context "in dealing with ranges" do
14
+ it "calls text on all cards by default" do
15
+ card1 = instance_double(Squib::Card)
16
+ card2 = instance_double(Squib::Card)
17
+ expect(card1).to receive(:text).once
18
+ expect(card2).to receive(:text).once
19
+ Squib::Deck.new do
20
+ @cards = [card1, card2]
21
+ text str: 'blah'
22
+ end
23
+ end
24
+
25
+ it "calls text on some cards with an integer" do
26
+ card1 = instance_double(Squib::Card)
27
+ card2 = instance_double(Squib::Card)
28
+ expect(card2).to receive(:text).once
29
+ Squib::Deck.new do
30
+ @cards = [card1, card2]
31
+ text range: 1, str: 'blah'
32
+ end
33
+ end
34
+
35
+ it "calls text with ranges" do
36
+ card1 = instance_double(Squib::Card)
37
+ card2 = instance_double(Squib::Card)
38
+ card3 = instance_double(Squib::Card)
39
+ expect(card1).to receive(:text).once
40
+ expect(card2).to receive(:text).once
41
+ Squib::Deck.new do
42
+ @cards = [card1, card2, card3]
43
+ text range: 0..1, str: 'blah'
44
+ end
45
+ end
46
+ end
47
+
48
+ context "#load_layout" do
49
+
50
+ it "loads a normal layout with no extends" do
51
+ d = Squib::Deck.new(layout: test_file('no-extends.yml'))
52
+ expect(d.layout).to \
53
+ eq({'frame' => {
54
+ 'x' => 38,
55
+ 'valign' => :middle,
56
+ 'str' => "blah",
57
+ 'font' => "Mr. Font",
58
+ }
59
+ }
60
+ )
61
+ end
62
+
63
+ it "loads with a single extends" do
64
+ d = Squib::Deck.new(layout: test_file('single-extends.yml'))
65
+ expect(d.layout).to \
66
+ eq({'frame' => {
67
+ 'x' => 38,
68
+ 'y' => 38,
69
+ },
70
+ 'title' => {
71
+ 'x' => 38,
72
+ 'y' => 50,
73
+ 'width' => 100,
74
+ }
75
+ }
76
+ )
77
+ end
78
+
79
+ it "applies the single-level extends multiple times" do
80
+ d = Squib::Deck.new(layout: test_file('single-level-multi-extends.yml'))
81
+ expect(d.layout).to \
82
+ eq({'frame' => {
83
+ 'x' => 38,
84
+ 'y' => 38,
85
+ },
86
+ 'title' => {
87
+ 'x' => 38,
88
+ 'y' => 50,
89
+ 'width' => 100,
90
+ },
91
+ 'title2' => {
92
+ 'x' => 75,
93
+ 'y' => 150,
94
+ 'width' => 150,
95
+ },
96
+ }
97
+ )
98
+ end
99
+
100
+ it "applies multiple extends in a single rule" do
101
+ d = Squib::Deck.new(layout: test_file('multi-extends-single-entry.yml'))
102
+ expect(d.layout).to \
103
+ eq({'aunt' => {
104
+ 'a' => 101,
105
+ 'b' => 102,
106
+ 'c' => 103,
107
+ },
108
+ 'uncle' => {
109
+ 'x' => 104,
110
+ 'y' => 105,
111
+ 'b' => 106,
112
+ },
113
+ 'child' => {
114
+ 'a' => 107, # my own
115
+ 'b' => 102, # from the younger aunt
116
+ 'c' => 103, # from aunt
117
+ 'x' => 108, # my own
118
+ 'y' => 105, # from uncle
119
+ },
120
+ }
121
+ )
122
+ end
123
+
124
+ it "applies multi-level extends" do
125
+ d = Squib::Deck.new(layout: test_file('multi-level-extends.yml'))
126
+ expect(d.layout).to \
127
+ eq({'frame' => {
128
+ 'x' => 38,
129
+ 'y' => 38,
130
+ },
131
+ 'title' => {
132
+ 'x' => 38,
133
+ 'y' => 50,
134
+ 'width' => 100,
135
+ },
136
+ 'subtitle' => {
137
+ 'x' => 38,
138
+ 'y' => 150,
139
+ 'width' => 100,
140
+ },
141
+ }
142
+ )
143
+ end
144
+
145
+ end
146
+
147
+ end