squib 0.0.6 → 0.1.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/.travis.yml +3 -3
- data/CHANGELOG.md +15 -8
- data/README.md +20 -11
- data/RELEASE TODO.md +13 -0
- data/lib/squib/api/data.rb +3 -2
- data/lib/squib/api/image.rb +11 -9
- data/lib/squib/api/shapes.rb +25 -25
- data/lib/squib/api/text.rb +4 -4
- data/lib/squib/api/units.rb +15 -1
- data/lib/squib/card.rb +3 -0
- data/lib/squib/constants.rb +34 -1
- data/lib/squib/deck.rb +5 -2
- data/lib/squib/graphics/image.rb +7 -1
- data/lib/squib/graphics/save_doc.rb +57 -0
- data/lib/squib/input_helpers.rb +36 -1
- data/lib/squib/version.rb +1 -1
- data/samples/load_images.rb +4 -2
- data/samples/saves.rb +32 -0
- data/samples/text_options.rb +0 -2
- data/samples/unicode.rb +27 -0
- data/samples/units.rb +21 -5
- data/spec/api/api_image_spec.rb +1 -1
- data/spec/data/layouts/empty-rule.yml +1 -0
- data/spec/data/layouts/empty.yml +1 -0
- data/spec/data/samples/load_images.rb.txt +8 -0
- data/spec/data/samples/saves.rb.txt +702 -0
- data/spec/data/samples/text_options.rb.txt +198 -168
- data/spec/data/samples/units.rb.txt +19 -1
- data/spec/deck_spec.rb +12 -0
- data/spec/graphics/graphics_images_spec.rb +14 -12
- data/spec/graphics/graphics_save_doc_spec.rb +2 -2
- data/spec/input_helpers_spec.rb +65 -1
- data/spec/samples/samples_regression_spec.rb +11 -9
- data/spec/spec_helper.rb +2 -0
- metadata +14 -5
- data/samples/save_pdf.rb +0 -14
@@ -1,5 +1,5 @@
|
|
1
1
|
cairo: save([])
|
2
|
-
cairo: set_source_color([#<Cairo::Color::RGB: @alpha=1.0, @red=
|
2
|
+
cairo: set_source_color([#<Cairo::Color::RGB: @alpha=1.0, @red=0.8666666666666667, @green=0.8666666666666667, @blue=0.8666666666666667>])
|
3
3
|
cairo: paint([])
|
4
4
|
cairo: restore([])
|
5
5
|
cairo: save([])
|
@@ -11,4 +11,22 @@ cairo: rounded_rectangle([37.5, 37.5, 750.0, 1050.0, 25, 25])
|
|
11
11
|
cairo: set_source_color([#<Cairo::Color::RGB: @alpha=0.0, @red=0.0, @green=0.0, @blue=0.0>])
|
12
12
|
cairo: fill([])
|
13
13
|
cairo: restore([])
|
14
|
+
cairo: save([])
|
15
|
+
cairo: rounded_rectangle([75.0, 75.0, 675.0, 975.0, 25, 25])
|
16
|
+
cairo: set_source_color([#<Cairo::Color::RGB: @alpha=1.0, @red=0.0, @green=0.0, @blue=0.0>])
|
17
|
+
cairo: set_line_width([2.0])
|
18
|
+
cairo: stroke([])
|
19
|
+
cairo: rounded_rectangle([75.0, 75.0, 675.0, 975.0, 25, 25])
|
20
|
+
cairo: set_source_color([#<Cairo::Color::RGB: @alpha=0.0, @red=0.0, @green=0.0, @blue=0.0>])
|
21
|
+
cairo: fill([])
|
22
|
+
cairo: restore([])
|
23
|
+
cairo: save([])
|
24
|
+
cairo: rounded_rectangle([472.4409444, 472.4409444, 100, 100, 0, 0])
|
25
|
+
cairo: set_source_color([#<Cairo::Color::RGB: @alpha=1.0, @red=0.0, @green=0.0, @blue=0.0>])
|
26
|
+
cairo: set_line_width([2.0])
|
27
|
+
cairo: stroke([])
|
28
|
+
cairo: rounded_rectangle([472.4409444, 472.4409444, 100, 100, 0, 0])
|
29
|
+
cairo: set_source_color([#<Cairo::Color::RGB: @alpha=0.0, @red=0.0, @green=0.0, @blue=0.0>])
|
30
|
+
cairo: fill([])
|
31
|
+
cairo: restore([])
|
14
32
|
surface: write_to_png(["_output/units_0.png"])
|
data/spec/deck_spec.rb
CHANGED
@@ -207,6 +207,18 @@ describe Squib::Deck do
|
|
207
207
|
})
|
208
208
|
end
|
209
209
|
|
210
|
+
it 'loads nothing on an empty layout file' do
|
211
|
+
d = Squib::Deck.new(layout: layout_file('empty.yml'))
|
212
|
+
expect(d.layout).to eq({})
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'handles extends on a rule with no args' do
|
216
|
+
d = Squib::Deck.new(layout: layout_file('empty-rule.yml'))
|
217
|
+
expect(d.layout).to eq({
|
218
|
+
'empty' => nil
|
219
|
+
})
|
220
|
+
end
|
221
|
+
|
210
222
|
end
|
211
223
|
|
212
224
|
end
|
@@ -3,14 +3,15 @@ require 'squib'
|
|
3
3
|
|
4
4
|
describe Squib::Card do
|
5
5
|
|
6
|
-
before(:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
before(:example) do
|
7
|
+
@deck = double(Squib::Deck)
|
8
|
+
@context = double(Cairo::Context)
|
9
|
+
@svg = double(RSVG::Handle)
|
10
|
+
@png = double(Cairo::ImageSurface)
|
11
|
+
allow(Cairo::Context).to receive(:new).and_return(@context)
|
12
|
+
allow(Cairo::ImageSurface).to receive(:from_png).and_return(@png)
|
13
|
+
allow(Cairo::ImageSurface).to receive(:new).and_return(@png)
|
14
|
+
allow(RSVG::Handle).to receive(:new_from_file).and_return(@svg)
|
14
15
|
end
|
15
16
|
|
16
17
|
context '#png' do
|
@@ -19,13 +20,13 @@ describe Squib::Card do
|
|
19
20
|
expect(@context).to receive(:translate).with(-37, -38).once
|
20
21
|
expect(@context).to receive(:rotate).with(0.0).once
|
21
22
|
expect(@context).to receive(:translate).with(37, 38).once
|
22
|
-
expect(@context).to receive(:set_source).with(
|
23
|
+
expect(@context).to receive(:set_source).with(@png, 37, 38).once
|
23
24
|
expect(@context).to receive(:paint).with(0.9).once
|
24
25
|
expect(@context).to receive(:restore).once
|
25
26
|
|
26
27
|
card = Squib::Card.new(@deck, 100, 150)
|
27
28
|
# png(file, x, y, alpha, blend, angle)
|
28
|
-
card.png('foo.png', 37, 38, 0.9, :none, 0.0)
|
29
|
+
card.png('foo.png', 37, 38, :native, :native, 0.9, :none, 0.0)
|
29
30
|
end
|
30
31
|
|
31
32
|
it 'sets blend when needed' do
|
@@ -33,8 +34,9 @@ describe Squib::Card do
|
|
33
34
|
expect(@context).to receive(:operator=).with(:overlay).once
|
34
35
|
|
35
36
|
card = Squib::Card.new(@deck, 100, 150)
|
36
|
-
card.png('foo.png', 37, 38, 0.9, :overlay, 0.0)
|
37
|
+
card.png('foo.png', 37, 38, :native, :native, 0.9, :overlay, 0.0)
|
37
38
|
end
|
39
|
+
|
38
40
|
end
|
39
41
|
|
40
42
|
context '#svg' do
|
@@ -47,7 +49,7 @@ describe Squib::Card do
|
|
47
49
|
expect(@context).to receive(:translate).with(37, 38).once
|
48
50
|
expect(@context).to receive(:scale).with(1.0, 1.0).once
|
49
51
|
expect(@context).to receive(:render_rsvg_handle).with(@svg, 'id').once
|
50
|
-
expect(@context).to receive(:set_source).with(
|
52
|
+
expect(@context).to receive(:set_source).with(@png, 37, 38).once
|
51
53
|
expect(@context).to receive(:paint).with(0.9).once
|
52
54
|
expect(@context).to receive(:restore).once
|
53
55
|
|
@@ -25,7 +25,7 @@ describe Squib::Deck, '#save_pdf' do
|
|
25
25
|
args = { file: 'foo.pdf', dir: '_out', margin: 75, gap: 5, trim: 37 }
|
26
26
|
deck = Squib::Deck.new(cards: num_cards, width: 825, height: 1125)
|
27
27
|
mock_squib_logger(@old_logger) do
|
28
|
-
expect(Squib.logger).to receive(:debug).
|
28
|
+
expect(Squib.logger).to receive(:debug).at_least(:once)
|
29
29
|
expect(Cairo::Context).to receive(:new).and_return(@context).exactly(num_cards + 1).times
|
30
30
|
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir
|
31
31
|
|
@@ -49,7 +49,7 @@ describe Squib::Deck, '#save_pdf' do
|
|
49
49
|
args = { range: 2..4, file: 'foo.pdf', dir: '_out', margin: 75, gap: 5, trim: 37 }
|
50
50
|
deck = Squib::Deck.new(cards: num_cards, width: 825, height: 1125)
|
51
51
|
mock_squib_logger(@old_logger) do
|
52
|
-
expect(Squib.logger).to receive(:debug).
|
52
|
+
expect(Squib.logger).to receive(:debug).at_least(:once)
|
53
53
|
expect(Cairo::Context).to receive(:new).and_return(@context).exactly(4).times
|
54
54
|
expect(deck).to receive(:dirify) { |arg| arg } #don't create the dir
|
55
55
|
|
data/spec/input_helpers_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'squib/input_helpers'
|
|
4
4
|
|
5
5
|
class DummyDeck
|
6
6
|
include Squib::InputHelpers
|
7
|
-
attr_accessor :layout, :cards, :custom_colors
|
7
|
+
attr_accessor :layout, :cards, :custom_colors, :width, :height, :dpi
|
8
8
|
end
|
9
9
|
|
10
10
|
describe Squib::InputHelpers do
|
@@ -18,6 +18,9 @@ describe Squib::InputHelpers do
|
|
18
18
|
}
|
19
19
|
@deck.cards = %w(a b)
|
20
20
|
@deck.custom_colors = {}
|
21
|
+
@deck.width = 100
|
22
|
+
@deck.height = 200
|
23
|
+
@deck.dpi = 300
|
21
24
|
end
|
22
25
|
|
23
26
|
context '#layoutify' do
|
@@ -135,4 +138,65 @@ describe Squib::InputHelpers do
|
|
135
138
|
end
|
136
139
|
end
|
137
140
|
|
141
|
+
context '#convert_units' do
|
142
|
+
it 'does not touch arrays integers' do
|
143
|
+
args = {x: [156]}
|
144
|
+
needed_params = [:x]
|
145
|
+
opts = @deck.send(:convert_units, args, needed_params)
|
146
|
+
expect(opts).to eq({ :x => [156] })
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'does not touch arrays floats' do
|
150
|
+
args = {x: [156.2]}
|
151
|
+
needed_params = [:x]
|
152
|
+
opts = @deck.send(:convert_units, args, needed_params)
|
153
|
+
expect(opts).to eq({ :x => [156.2] })
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'converts array of all inches' do
|
157
|
+
args = {x: ['1in', '2in']}
|
158
|
+
needed_params = [:x]
|
159
|
+
opts = @deck.send(:convert_units, args, needed_params)
|
160
|
+
expect(opts).to eq({:x => [300.0, 600.0] }) #assume 300dpi default
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'converts array of some inches' do
|
164
|
+
args = {x: [156, '2in']}
|
165
|
+
needed_params = [:x]
|
166
|
+
opts = @deck.send(:convert_units, args, needed_params)
|
167
|
+
expect(opts).to eq({:x => [156.0, 600.0]}) #assume 300dpi default
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'handles whitespace' do
|
171
|
+
args = {x: ['1in ']}
|
172
|
+
needed_params = [:x]
|
173
|
+
opts = @deck.send(:convert_units, args, needed_params)
|
174
|
+
expect(opts).to eq({:x => [300.0] }) #assume 300dpi default
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'converts centimeters' do
|
178
|
+
args = {x: ['2cm']}
|
179
|
+
needed_params = [:x]
|
180
|
+
opts = @deck.send(:convert_units, args, needed_params)
|
181
|
+
expect(opts).to eq({:x => [236.2204722] }) #assume 300dpi default
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
context '#rowify' do
|
187
|
+
it 'does nothing on an integer' do
|
188
|
+
opts = @deck.send(:rowify, {columns: 2, rows: 2})
|
189
|
+
expect(opts).to eq({ columns: 2,
|
190
|
+
rows: 2
|
191
|
+
})
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'computes properly on non-integer' do
|
195
|
+
opts = @deck.send(:rowify, {columns: 1, rows: :infinite})
|
196
|
+
expect(opts).to eq({ columns: 1,
|
197
|
+
rows: 2
|
198
|
+
})
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
138
202
|
end
|
@@ -12,6 +12,7 @@ describe "Squib samples" do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should execute with no errors' do
|
15
|
+
allow(Squib.logger).to receive(:warn) {}
|
15
16
|
allow(ProgressBar).to receive(:create).and_return(Squib::DoNothing.new)
|
16
17
|
Dir["#{samples_dir}/**/*.rb"].each do |sample|
|
17
18
|
load sample
|
@@ -43,21 +44,22 @@ describe "Squib samples" do
|
|
43
44
|
# FOR NOW!! These two I can't get working on Travis, so I'm disabling
|
44
45
|
# Has to do with UTF-8 encoding of a special characters
|
45
46
|
# layouts.rb
|
46
|
-
#
|
47
|
-
%w(
|
48
|
-
autoscale_font.rb
|
49
|
-
save_pdf.rb
|
50
|
-
custom_config.rb
|
51
|
-
load_images.rb
|
47
|
+
# unicode.rb
|
48
|
+
%w( autoscale_font.rb
|
52
49
|
basic.rb
|
53
50
|
cairo_access.rb
|
54
|
-
draw_shapes.rb
|
55
51
|
colors.rb
|
56
|
-
excel.rb
|
57
52
|
csv_import.rb
|
53
|
+
custom_config.rb
|
54
|
+
draw_shapes.rb
|
55
|
+
excel.rb
|
56
|
+
hello_world.rb
|
57
|
+
load_images.rb
|
58
58
|
portrait-landscape.rb
|
59
|
-
tgc_proofs.rb
|
60
59
|
ranges.rb
|
60
|
+
saves.rb
|
61
|
+
text_options.rb
|
62
|
+
tgc_proofs.rb
|
61
63
|
units.rb
|
62
64
|
).each do |sample|
|
63
65
|
it "has not changed for #{sample}" do
|
data/spec/spec_helper.rb
CHANGED
@@ -54,9 +54,11 @@ def mock_cairo(strio)
|
|
54
54
|
cxt = double(Cairo::Context)
|
55
55
|
surface = double(Cairo::ImageSurface)
|
56
56
|
pango = double(Pango::Layout)
|
57
|
+
allow(Squib.logger).to receive(:warn) {}
|
57
58
|
allow(ProgressBar).to receive(:create).and_return(Squib::DoNothing.new)
|
58
59
|
allow(Cairo::ImageSurface).to receive(:new).and_return(surface)
|
59
60
|
allow(surface).to receive(:width).and_return(100)
|
61
|
+
allow(surface).to receive(:height).and_return(101)
|
60
62
|
allow(Cairo::Context).to receive(:new).and_return(cxt)
|
61
63
|
allow(cxt).to receive(:create_pango_layout).and_return(pango)
|
62
64
|
allow(cxt).to receive(:target).and_return(surface)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: squib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Meneely
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cairo
|
@@ -226,9 +226,10 @@ extra_rdoc_files:
|
|
226
226
|
- samples/load_images.rb
|
227
227
|
- samples/portrait-landscape.rb
|
228
228
|
- samples/ranges.rb
|
229
|
-
- samples/
|
229
|
+
- samples/saves.rb
|
230
230
|
- samples/text_options.rb
|
231
231
|
- samples/tgc_proofs.rb
|
232
|
+
- samples/unicode.rb
|
232
233
|
- samples/units.rb
|
233
234
|
files:
|
234
235
|
- .gitignore
|
@@ -238,6 +239,7 @@ files:
|
|
238
239
|
- Gemfile
|
239
240
|
- LICENSE.txt
|
240
241
|
- README.md
|
242
|
+
- RELEASE TODO.md
|
241
243
|
- Rakefile
|
242
244
|
- bin/squib
|
243
245
|
- lib/squib.rb
|
@@ -297,11 +299,12 @@ files:
|
|
297
299
|
- samples/ranges.rb
|
298
300
|
- samples/sample.csv
|
299
301
|
- samples/sample.xlsx
|
300
|
-
- samples/
|
302
|
+
- samples/saves.rb
|
301
303
|
- samples/shiny-purse.png
|
302
304
|
- samples/spanner.svg
|
303
305
|
- samples/text_options.rb
|
304
306
|
- samples/tgc_proofs.rb
|
307
|
+
- samples/unicode.rb
|
305
308
|
- samples/units.rb
|
306
309
|
- spec/api/api_data_spec.rb
|
307
310
|
- spec/api/api_image_spec.rb
|
@@ -311,6 +314,8 @@ files:
|
|
311
314
|
- spec/data/csv/dup_cols.csv
|
312
315
|
- spec/data/csv/with_spaces.csv
|
313
316
|
- spec/data/layouts/easy-circular-extends.yml
|
317
|
+
- spec/data/layouts/empty-rule.yml
|
318
|
+
- spec/data/layouts/empty.yml
|
314
319
|
- spec/data/layouts/hard-circular-extends.yml
|
315
320
|
- spec/data/layouts/multi-extends-single-entry.yml
|
316
321
|
- spec/data/layouts/multi-level-extends.yml
|
@@ -337,6 +342,7 @@ files:
|
|
337
342
|
- spec/data/samples/portrait-landscape.rb.txt
|
338
343
|
- spec/data/samples/ranges.rb.txt
|
339
344
|
- spec/data/samples/save_pdf.rb.txt
|
345
|
+
- spec/data/samples/saves.rb.txt
|
340
346
|
- spec/data/samples/text_options.rb.txt
|
341
347
|
- spec/data/samples/tgc_proofs.rb.txt
|
342
348
|
- spec/data/samples/units.rb.txt
|
@@ -370,7 +376,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
370
376
|
version: '0'
|
371
377
|
requirements: []
|
372
378
|
rubyforge_project:
|
373
|
-
rubygems_version: 2.
|
379
|
+
rubygems_version: 2.0.14
|
374
380
|
signing_key:
|
375
381
|
specification_version: 2
|
376
382
|
summary: A Ruby DSL for prototyping card games
|
@@ -383,6 +389,8 @@ test_files:
|
|
383
389
|
- spec/data/csv/dup_cols.csv
|
384
390
|
- spec/data/csv/with_spaces.csv
|
385
391
|
- spec/data/layouts/easy-circular-extends.yml
|
392
|
+
- spec/data/layouts/empty-rule.yml
|
393
|
+
- spec/data/layouts/empty.yml
|
386
394
|
- spec/data/layouts/hard-circular-extends.yml
|
387
395
|
- spec/data/layouts/multi-extends-single-entry.yml
|
388
396
|
- spec/data/layouts/multi-level-extends.yml
|
@@ -409,6 +417,7 @@ test_files:
|
|
409
417
|
- spec/data/samples/portrait-landscape.rb.txt
|
410
418
|
- spec/data/samples/ranges.rb.txt
|
411
419
|
- spec/data/samples/save_pdf.rb.txt
|
420
|
+
- spec/data/samples/saves.rb.txt
|
412
421
|
- spec/data/samples/text_options.rb.txt
|
413
422
|
- spec/data/samples/tgc_proofs.rb.txt
|
414
423
|
- spec/data/samples/units.rb.txt
|
data/samples/save_pdf.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'squib'
|
3
|
-
|
4
|
-
Squib::Deck.new(width: 825, height: 1125, cards: 16) do
|
5
|
-
background color: :gray
|
6
|
-
rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38
|
7
|
-
|
8
|
-
text str: (1..16).to_a, x: 220, y: 78, font: 'Arial 54'
|
9
|
-
|
10
|
-
save_pdf file: 'sample-save-pdf.pdf', margin: 75, gap: 5, trim: 37
|
11
|
-
|
12
|
-
#Note that our PNGs still are not trimmed even though the pdf ones are
|
13
|
-
save_png range: 1, prefix: 'save_pdf_'
|
14
|
-
end
|