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.
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 -7
  5. data/CHANGELOG.md +19 -0
  6. data/Gemfile +2 -2
  7. data/LICENSE.txt +22 -22
  8. data/README.md +256 -244
  9. data/Rakefile +11 -11
  10. data/bin/squib +18 -18
  11. data/lib/squib.rb +31 -31
  12. data/lib/squib/api/background.rb +18 -18
  13. data/lib/squib/api/data.rb +52 -52
  14. data/lib/squib/api/image.rb +66 -66
  15. data/lib/squib/api/save.rb +43 -43
  16. data/lib/squib/api/settings.rb +37 -38
  17. data/lib/squib/api/shapes.rb +116 -116
  18. data/lib/squib/api/text.rb +53 -50
  19. data/lib/squib/api/units.rb +16 -16
  20. data/lib/squib/card.rb +41 -41
  21. data/lib/squib/commands/new.rb +43 -43
  22. data/lib/squib/constants.rb +108 -104
  23. data/lib/squib/deck.rb +170 -116
  24. data/lib/squib/graphics/background.rb +13 -13
  25. data/lib/squib/graphics/image.rb +47 -47
  26. data/lib/squib/graphics/save_doc.rb +54 -54
  27. data/lib/squib/graphics/save_images.rb +32 -32
  28. data/lib/squib/graphics/shapes.rb +59 -59
  29. data/lib/squib/graphics/text.rb +116 -113
  30. data/lib/squib/input_helpers.rb +193 -193
  31. data/lib/squib/progress.rb +37 -37
  32. data/lib/squib/project_template/.gitignore +4 -4
  33. data/lib/squib/project_template/ABOUT.md +19 -19
  34. data/lib/squib/project_template/Gemfile +2 -2
  35. data/lib/squib/project_template/PNP NOTES.md +3 -3
  36. data/lib/squib/project_template/config.yml +19 -19
  37. data/lib/squib/project_template/deck.rb +5 -5
  38. data/lib/squib/version.rb +6 -6
  39. data/samples/autoscale_font.rb +27 -0
  40. data/samples/basic.rb +19 -19
  41. data/samples/colors.rb +15 -15
  42. data/samples/custom-config.yml +5 -5
  43. data/samples/custom-layout.yml +59 -39
  44. data/samples/custom_config.rb +18 -18
  45. data/samples/customconfig-imgdir/spanner2.svg +91 -91
  46. data/samples/draw_shapes.rb +18 -18
  47. data/samples/excel.rb +19 -19
  48. data/samples/hello_world.rb +6 -6
  49. data/samples/load_images.rb +29 -29
  50. data/samples/offset.svg +71 -71
  51. data/samples/portrait-landscape.rb +22 -22
  52. data/samples/ranges.rb +55 -55
  53. data/samples/save_pdf.rb +14 -14
  54. data/samples/spanner.svg +91 -91
  55. data/samples/text_options.rb +67 -60
  56. data/samples/tgc_proofs.rb +19 -19
  57. data/samples/units.rb +12 -12
  58. data/samples/use_layout.rb +33 -28
  59. data/spec/api/api_text_spec.rb +43 -43
  60. data/spec/commands/new_spec.rb +47 -47
  61. data/spec/data/easy-circular-extends.yml +6 -0
  62. data/spec/data/hard-circular-extends.yml +9 -0
  63. data/spec/data/multi-extends-single-entry.yml +14 -13
  64. data/spec/data/multi-level-extends.yml +9 -9
  65. data/spec/data/no-extends.yml +5 -5
  66. data/spec/data/pre-extends.yml +7 -0
  67. data/spec/data/self-circular-extends.yml +3 -0
  68. data/spec/data/single-extends.yml +7 -7
  69. data/spec/data/single-level-multi-extends.yml +11 -11
  70. data/spec/deck_spec.rb +188 -147
  71. data/spec/input_helpers_spec.rb +116 -116
  72. data/spec/samples_run_spec.rb +19 -19
  73. data/squib.gemspec +46 -46
  74. metadata +17 -7
@@ -1,43 +1,43 @@
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
-
43
- end
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, 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, 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, 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
+
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,6 @@
1
+ a:
2
+ extends: b
3
+ x: 50
4
+ b:
5
+ extends: a
6
+ x: 150
@@ -0,0 +1,9 @@
1
+ a:
2
+ extends: c
3
+ x: 50
4
+ b:
5
+ extends: a
6
+ x: 150
7
+ c:
8
+ extends: b
9
+ y: 250
@@ -1,13 +1,14 @@
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
1
+ aunt:
2
+ a: 101
3
+ b: 102
4
+ c: 103
5
+ uncle:
6
+ x: 104
7
+ y: 105
8
+ b: 106
9
+ child:
10
+ extends:
11
+ - uncle
12
+ - aunt
13
+ a: 107
14
+ x: 108
@@ -1,10 +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
1
+ frame:
2
+ x: 38
3
+ y: 38
4
+ title:
5
+ extends: frame
6
+ y: 50
7
+ width: 100
8
+ subtitle:
9
+ extends: title
10
10
  y: 150
@@ -1,5 +1,5 @@
1
- frame:
2
- x: 38
3
- valign: !ruby/symbol middle
4
- str: "blah"
5
- font: Mr. Font
1
+ frame:
2
+ x: 38
3
+ valign: !ruby/symbol middle
4
+ str: "blah"
5
+ font: Mr. Font
@@ -0,0 +1,7 @@
1
+ title:
2
+ extends: frame
3
+ y: 50
4
+ width: 100
5
+ frame:
6
+ x: 38
7
+ y: 38
@@ -0,0 +1,3 @@
1
+ a:
2
+ extends: a
3
+ x: 50
@@ -1,7 +1,7 @@
1
- frame: &frame
2
- x: 38
3
- y: 38
4
- title:
5
- <<: *frame
6
- y: 50
7
- width: 100
1
+ frame:
2
+ x: 38
3
+ y: 38
4
+ title:
5
+ extends: frame
6
+ y: 50
7
+ width: 100
@@ -1,12 +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
1
+ frame:
2
+ x: 38
3
+ y: 38
4
+ title:
5
+ extends: frame
6
+ y: 50
7
+ width: 100
8
+ title2:
9
+ extends: frame
10
+ x: 75
11
+ y: 150
12
12
  width: 150
@@ -1,147 +1,188 @@
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
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
+ 'extends' => 'frame',
72
+ 'x' => 38,
73
+ 'y' => 50,
74
+ 'width' => 100,
75
+ }
76
+ }
77
+ )
78
+ end
79
+
80
+ it "applies the extends regardless of order" do
81
+ d = Squib::Deck.new(layout: test_file('pre-extends.yml'))
82
+ expect(d.layout).to \
83
+ eq({'frame' => {
84
+ 'x' => 38,
85
+ 'y' => 38,
86
+ },
87
+ 'title' => {
88
+ 'extends' => 'frame',
89
+ 'x' => 38,
90
+ 'y' => 50,
91
+ 'width' => 100,
92
+ }
93
+ }
94
+ )
95
+ end
96
+
97
+ it "applies the single-level extends multiple times" do
98
+ d = Squib::Deck.new(layout: test_file('single-level-multi-extends.yml'))
99
+ expect(d.layout).to \
100
+ eq({'frame' => {
101
+ 'x' => 38,
102
+ 'y' => 38,
103
+ },
104
+ 'title' => {
105
+ 'extends' => 'frame',
106
+ 'x' => 38,
107
+ 'y' => 50,
108
+ 'width' => 100,
109
+ },
110
+ 'title2' => {
111
+ 'extends' => 'frame',
112
+ 'x' => 75,
113
+ 'y' => 150,
114
+ 'width' => 150,
115
+ },
116
+ }
117
+ )
118
+ end
119
+
120
+ it "applies multiple extends in a single rule" do
121
+ d = Squib::Deck.new(layout: test_file('multi-extends-single-entry.yml'))
122
+ expect(d.layout).to \
123
+ eq({'aunt' => {
124
+ 'a' => 101,
125
+ 'b' => 102,
126
+ 'c' => 103,
127
+ },
128
+ 'uncle' => {
129
+ 'x' => 104,
130
+ 'y' => 105,
131
+ 'b' => 106,
132
+ },
133
+ 'child' => {
134
+ 'extends' => ['uncle','aunt'],
135
+ 'a' => 107, # my own
136
+ 'b' => 102, # from the younger aunt
137
+ 'c' => 103, # from aunt
138
+ 'x' => 108, # my own
139
+ 'y' => 105, # from uncle
140
+ },
141
+ }
142
+ )
143
+ end
144
+
145
+ it "applies multi-level extends" do
146
+ d = Squib::Deck.new(layout: test_file('multi-level-extends.yml'))
147
+ expect(d.layout).to \
148
+ eq({'frame' => {
149
+ 'x' => 38,
150
+ 'y' => 38,
151
+ },
152
+ 'title' => {
153
+ 'extends' => 'frame',
154
+ 'x' => 38,
155
+ 'y' => 50,
156
+ 'width' => 100,
157
+ },
158
+ 'subtitle' => {
159
+ 'extends' => 'title',
160
+ 'x' => 38,
161
+ 'y' => 150,
162
+ 'width' => 100,
163
+ },
164
+ }
165
+ )
166
+ end
167
+
168
+ it "fails on a self-circular extends" do
169
+ file = test_file('self-circular-extends.yml')
170
+ expect { Squib::Deck.new(layout: file) }.to \
171
+ raise_error(RuntimeError, "Invalid layout: circular extends with 'a'")
172
+ end
173
+
174
+ it "fails on a easy-circular extends" do
175
+ file = test_file('easy-circular-extends.yml')
176
+ expect { Squib::Deck.new(layout: file) }.to \
177
+ raise_error(RuntimeError, "Invalid layout: circular extends with 'a'")
178
+ end
179
+
180
+ it "hard on a easy-circular extends" do
181
+ file = test_file('hard-circular-extends.yml')
182
+ expect { Squib::Deck.new(layout: file) }.to \
183
+ raise_error(RuntimeError, "Invalid layout: circular extends with 'a'")
184
+ end
185
+
186
+ end
187
+
188
+ end