squib 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +29 -29
- data/.travis.yml +6 -6
- data/.yardopts +7 -5
- data/Gemfile +2 -2
- data/LICENSE.txt +22 -22
- data/README.md +245 -92
- data/Rakefile +11 -11
- data/bin/squib +18 -18
- data/lib/squib.rb +31 -18
- data/lib/squib/api/background.rb +18 -16
- data/lib/squib/api/data.rb +52 -52
- data/lib/squib/api/image.rb +66 -48
- data/lib/squib/api/save.rb +43 -37
- data/lib/squib/api/settings.rb +38 -35
- data/lib/squib/api/shapes.rb +116 -106
- data/lib/squib/api/text.rb +50 -45
- data/lib/squib/api/units.rb +16 -16
- data/lib/squib/card.rb +42 -36
- data/lib/squib/commands/new.rb +43 -39
- data/lib/squib/constants.rb +104 -39
- data/lib/squib/deck.rb +116 -113
- data/lib/squib/graphics/background.rb +13 -12
- data/lib/squib/graphics/image.rb +47 -28
- data/lib/squib/graphics/save_doc.rb +54 -50
- data/lib/squib/graphics/save_images.rb +32 -10
- data/lib/squib/graphics/shapes.rb +59 -55
- data/lib/squib/graphics/text.rb +113 -107
- data/lib/squib/input_helpers.rb +193 -139
- data/lib/squib/progress.rb +38 -0
- data/lib/squib/project_template/.gitignore +4 -3
- 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 +20 -2
- data/lib/squib/project_template/deck.rb +5 -5
- data/lib/squib/version.rb +6 -6
- data/samples/ball.png +0 -0
- data/samples/basic.rb +19 -19
- data/samples/colors.rb +15 -16
- data/samples/custom-config.yml +6 -1
- data/samples/custom-layout.yml +39 -34
- data/samples/custom_config.rb +18 -5
- data/samples/customconfig-imgdir/shiny-purse2.png +0 -0
- data/samples/customconfig-imgdir/spanner2.svg +91 -0
- data/samples/draw_shapes.rb +18 -18
- data/samples/excel.rb +19 -19
- data/samples/grit.png +0 -0
- data/samples/hello_world.rb +6 -6
- data/samples/load_images.rb +29 -19
- data/samples/offset.svg +71 -0
- data/samples/portrait-landscape.rb +23 -0
- data/samples/ranges.rb +55 -47
- data/samples/save_pdf.rb +14 -14
- data/samples/shiny-purse.png +0 -0
- data/samples/spanner.svg +91 -91
- data/samples/text_options.rb +60 -58
- data/samples/tgc_proofs.rb +19 -19
- data/samples/units.rb +12 -12
- data/samples/use_layout.rb +28 -28
- data/spec/api/api_text_spec.rb +42 -36
- data/spec/commands/new_spec.rb +47 -47
- data/spec/data/multi-extends-single-entry.yml +13 -0
- data/spec/data/multi-level-extends.yml +10 -0
- data/spec/data/no-extends.yml +5 -0
- data/spec/data/single-extends.yml +7 -0
- data/spec/data/single-level-multi-extends.yml +12 -0
- data/spec/deck_spec.rb +147 -49
- data/spec/input_helpers_spec.rb +117 -0
- data/spec/samples_run_spec.rb +19 -14
- data/spec/spec_helper.rb +3 -0
- data/squib.gemspec +46 -42
- metadata +78 -4
- data/API.md +0 -59
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'squib/input_helpers'
|
3
|
+
|
4
|
+
class DummyDeck
|
5
|
+
include Squib::InputHelpers
|
6
|
+
attr_accessor :layout, :cards, :custom_colors
|
7
|
+
end
|
8
|
+
|
9
|
+
module Squib
|
10
|
+
def logger=(l)
|
11
|
+
@logger = l
|
12
|
+
end
|
13
|
+
module_function 'logger='
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Squib::InputHelpers do
|
17
|
+
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
@deck = DummyDeck.new
|
21
|
+
@deck.layout = {
|
22
|
+
'blah' => {x: 25},
|
23
|
+
'apples' => {x: 35},
|
24
|
+
'oranges' => {y: 45},
|
25
|
+
}
|
26
|
+
@deck.cards = %w(a b)
|
27
|
+
@deck.custom_colors = {}
|
28
|
+
end
|
29
|
+
|
30
|
+
context '#layoutify' do
|
31
|
+
it "warns on the logger when the layout doesn't exist" do
|
32
|
+
@old_logger = Squib.logger
|
33
|
+
Squib.logger = instance_double(Logger)
|
34
|
+
expect(Squib.logger).to receive(:warn).with("Layout entry 'foo' does not exist.").twice
|
35
|
+
expect(Squib.logger).to receive(:debug)
|
36
|
+
expect(@deck.send(:layoutify, {layout: :foo})).to eq({layout: [:foo,:foo]})
|
37
|
+
Squib.logger = @old_logger
|
38
|
+
end
|
39
|
+
|
40
|
+
it "applies the layout in a normal situation" do
|
41
|
+
expect(@deck.send(:layoutify, {layout: :blah})).to \
|
42
|
+
eq({layout: [:blah, :blah], x: [25, 25]})
|
43
|
+
end
|
44
|
+
|
45
|
+
it "applies two different layouts for two different situations" do
|
46
|
+
expect(@deck.send(:layoutify, {layout: ['blah', 'apples']})).to \
|
47
|
+
eq({layout: ['blah','apples'], x: [25, 35]})
|
48
|
+
end
|
49
|
+
|
50
|
+
it "still has nils when not applied two different layouts differ in structure" do
|
51
|
+
expect(@deck.send(:layoutify, {layout: ['apples', 'oranges']})).to \
|
52
|
+
eq({layout: ['apples','oranges'], x: [35], y: [nil, 45]})
|
53
|
+
#...this might behavior that is hard to debug for users. Trying to come up with a warning or something...
|
54
|
+
end
|
55
|
+
|
56
|
+
it "also looks up based on strings" do
|
57
|
+
expect(@deck.send(:layoutify, {layout: 'blah'})).to \
|
58
|
+
eq({layout: ['blah','blah'], x: [25, 25]})
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
context '#rangeify' do
|
64
|
+
it "must be within the card size range" do
|
65
|
+
expect{@deck.send(:rangeify, {range: 2..3})}.to \
|
66
|
+
raise_error(ArgumentError, '2..3 is outside of deck range of 0..1')
|
67
|
+
end
|
68
|
+
|
69
|
+
it "cannot be nil" do
|
70
|
+
expect{@deck.send(:rangeify, {range: nil})}.to \
|
71
|
+
raise_error(RuntimeError, 'Range cannot be nil')
|
72
|
+
end
|
73
|
+
|
74
|
+
it "defaults to a range of all cards if :all" do
|
75
|
+
expect(@deck.send(:rangeify, {range: :all})).to eq({range: 0..1})
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "#fileify" do
|
80
|
+
it "should throw an error if the file doesn't exist" do
|
81
|
+
expect{@deck.send(:fileify, {file: 'nonexist.txt'}, true)}.to \
|
82
|
+
raise_error(RuntimeError,"File #{File.expand_path('nonexist.txt')} does not exist!")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context "#dir" do
|
87
|
+
it "should raise an error if the directory does not exist" do
|
88
|
+
expect{@deck.send(:dirify, {dir: 'nonexist'}, :dir, false)}.to \
|
89
|
+
raise_error(RuntimeError,"'nonexist' does not exist!")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "#colorify" do
|
94
|
+
it "should parse if nillable" do
|
95
|
+
color = @deck.send(:colorify, {color: ['#fff']}, true)[:color]
|
96
|
+
expect(color.to_a[0].to_a).to eq([1.0, 1.0, 1.0, 1.0])
|
97
|
+
end
|
98
|
+
|
99
|
+
it "raises and error if the color doesn't exist" do
|
100
|
+
expect{ @deck.send(:colorify, {color: [:nonexist]}, false) }.to \
|
101
|
+
raise_error(ArgumentError, "unknown color name: nonexist")
|
102
|
+
end
|
103
|
+
|
104
|
+
it "pulls from config's custom colors" do
|
105
|
+
@deck.custom_colors['foo'] = "#abc"
|
106
|
+
expect(@deck.send(:colorify, {color: [:foo]}, false)[:color][0].to_s).to \
|
107
|
+
eq('#AABBCCFF')
|
108
|
+
end
|
109
|
+
|
110
|
+
it "pulls from config's custom colors even when a string" do
|
111
|
+
@deck.custom_colors['foo'] = "#abc"
|
112
|
+
expect(@deck.send(:colorify, {color: ['foo']}, false)[:color][0].to_s).to \
|
113
|
+
eq('#AABBCCFF')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
data/spec/samples_run_spec.rb
CHANGED
@@ -1,15 +1,20 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'squib'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'squib'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
describe Squib do
|
6
|
+
|
7
|
+
context "all samples run without error" do
|
8
|
+
it "should execute with no errors" do
|
9
|
+
p = double("ProgressBar")
|
10
|
+
allow(ProgressBar).to receive(:create).and_return(Squib::DoNothing.new)
|
11
|
+
samples = File.expand_path('../samples', File.dirname(__FILE__))
|
12
|
+
Dir["#{samples}/**/*.rb"].each do |sample|
|
13
|
+
Dir.chdir(samples) do #to save to _output
|
14
|
+
require_relative "../samples/#{File.basename(sample)}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
15
20
|
end
|
data/spec/spec_helper.rb
CHANGED
data/squib.gemspec
CHANGED
@@ -1,42 +1,46 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'squib/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.specification_version = 2 if spec.respond_to? :specification_version=
|
8
|
-
spec.required_rubygems_version = Gem::Requirement.new(">= 0") if spec.respond_to? :required_rubygems_version=
|
9
|
-
spec.rubygems_version = '2.2.2'
|
10
|
-
spec.required_ruby_version = '>= 2.0.0'
|
11
|
-
|
12
|
-
spec.name = "squib"
|
13
|
-
spec.version = Squib::VERSION
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.summary = %q{A Ruby DSL for prototyping card games}
|
17
|
-
spec.description = %q{Squib is a Ruby DSL for prototyping card games}
|
18
|
-
spec.authors = ["Andy Meneely"]
|
19
|
-
spec.email = ["playconfidencegames@gmail.com"]
|
20
|
-
spec.homepage = "https://github.com/andymeneely/squib"
|
21
|
-
|
22
|
-
spec.rdoc_options = ["--charset=UTF-8"]
|
23
|
-
spec.extra_rdoc_files = %w[README.md LICENSE.txt]
|
24
|
-
|
25
|
-
spec.files = `git ls-files -z`.split("\x0")
|
26
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
27
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
28
|
-
spec.require_paths = ["lib"]
|
29
|
-
|
30
|
-
spec.add_runtime_dependency 'cairo', '~> 1.12.9'
|
31
|
-
spec.add_runtime_dependency 'pango', '~> 2.2.0'
|
32
|
-
spec.add_runtime_dependency 'roo', '~> 1.13.2'
|
33
|
-
spec.add_runtime_dependency 'rsvg2', '~> 2.2.0'
|
34
|
-
spec.add_runtime_dependency 'mercenary', '~> 0.3.4'
|
35
|
-
|
36
|
-
|
37
|
-
spec.add_development_dependency "
|
38
|
-
spec.add_development_dependency "
|
39
|
-
spec.add_development_dependency "
|
40
|
-
spec.add_development_dependency "
|
41
|
-
|
42
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'squib/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.specification_version = 2 if spec.respond_to? :specification_version=
|
8
|
+
spec.required_rubygems_version = Gem::Requirement.new(">= 0") if spec.respond_to? :required_rubygems_version=
|
9
|
+
spec.rubygems_version = '2.2.2'
|
10
|
+
spec.required_ruby_version = '>= 2.0.0'
|
11
|
+
|
12
|
+
spec.name = "squib"
|
13
|
+
spec.version = Squib::VERSION
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.summary = %q{A Ruby DSL for prototyping card games}
|
17
|
+
spec.description = %q{Squib is a Ruby DSL for prototyping card games}
|
18
|
+
spec.authors = ["Andy Meneely"]
|
19
|
+
spec.email = ["playconfidencegames@gmail.com"]
|
20
|
+
spec.homepage = "https://github.com/andymeneely/squib"
|
21
|
+
|
22
|
+
spec.rdoc_options = ["--charset=UTF-8"]
|
23
|
+
spec.extra_rdoc_files = %w[README.md LICENSE.txt]
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0")
|
26
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
27
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_runtime_dependency 'cairo', '~> 1.12.9'
|
31
|
+
spec.add_runtime_dependency 'pango', '~> 2.2.0'
|
32
|
+
spec.add_runtime_dependency 'roo', '~> 1.13.2'
|
33
|
+
spec.add_runtime_dependency 'rsvg2', '~> 2.2.0'
|
34
|
+
spec.add_runtime_dependency 'mercenary', '~> 0.3.4'
|
35
|
+
spec.add_runtime_dependency 'ruby-progressbar', '~> 1.5.1'
|
36
|
+
|
37
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
38
|
+
spec.add_development_dependency "rake"
|
39
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
40
|
+
spec.add_development_dependency "rspec-mocks", "~> 3.0"
|
41
|
+
spec.add_development_dependency "redcarpet", '~> 3.1.2'
|
42
|
+
spec.add_development_dependency "github-markup", '~> 1.2.1'
|
43
|
+
spec.add_development_dependency "yard"
|
44
|
+
spec.add_development_dependency "coveralls"
|
45
|
+
|
46
|
+
end
|
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.0.3
|
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-
|
11
|
+
date: 2014-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cairo
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.3.4
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: ruby-progressbar
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.5.1
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.5.1
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: bundler
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +136,48 @@ dependencies:
|
|
122
136
|
- - ~>
|
123
137
|
- !ruby/object:Gem::Version
|
124
138
|
version: '3.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rspec-mocks
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '3.0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ~>
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '3.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: redcarpet
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ~>
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 3.1.2
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ~>
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 3.1.2
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: github-markup
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 1.2.1
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ~>
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 1.2.1
|
125
181
|
- !ruby/object:Gem::Dependency
|
126
182
|
name: yard
|
127
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,7 +219,6 @@ files:
|
|
163
219
|
- .gitignore
|
164
220
|
- .travis.yml
|
165
221
|
- .yardopts
|
166
|
-
- API.md
|
167
222
|
- Gemfile
|
168
223
|
- LICENSE.txt
|
169
224
|
- README.md
|
@@ -189,6 +244,7 @@ files:
|
|
189
244
|
- lib/squib/graphics/shapes.rb
|
190
245
|
- lib/squib/graphics/text.rb
|
191
246
|
- lib/squib/input_helpers.rb
|
247
|
+
- lib/squib/progress.rb
|
192
248
|
- lib/squib/project_template/.gitignore
|
193
249
|
- lib/squib/project_template/ABOUT.md
|
194
250
|
- lib/squib/project_template/Gemfile
|
@@ -199,16 +255,22 @@ files:
|
|
199
255
|
- lib/squib/project_template/layout.yml
|
200
256
|
- lib/squib/version.rb
|
201
257
|
- samples/_output/gitkeep.txt
|
258
|
+
- samples/ball.png
|
202
259
|
- samples/basic.rb
|
203
260
|
- samples/colors.rb
|
204
261
|
- samples/custom-config.yml
|
205
262
|
- samples/custom-layout.yml
|
206
263
|
- samples/custom_config.rb
|
264
|
+
- samples/customconfig-imgdir/shiny-purse2.png
|
265
|
+
- samples/customconfig-imgdir/spanner2.svg
|
207
266
|
- samples/draw_shapes.rb
|
208
267
|
- samples/excel.rb
|
268
|
+
- samples/grit.png
|
209
269
|
- samples/hello_world.rb
|
210
270
|
- samples/load_images.rb
|
271
|
+
- samples/offset.svg
|
211
272
|
- samples/pokercard.png
|
273
|
+
- samples/portrait-landscape.rb
|
212
274
|
- samples/ranges.rb
|
213
275
|
- samples/sample.xlsx
|
214
276
|
- samples/save_pdf.rb
|
@@ -220,7 +282,13 @@ files:
|
|
220
282
|
- samples/use_layout.rb
|
221
283
|
- spec/api/api_text_spec.rb
|
222
284
|
- spec/commands/new_spec.rb
|
285
|
+
- spec/data/multi-extends-single-entry.yml
|
286
|
+
- spec/data/multi-level-extends.yml
|
287
|
+
- spec/data/no-extends.yml
|
288
|
+
- spec/data/single-extends.yml
|
289
|
+
- spec/data/single-level-multi-extends.yml
|
223
290
|
- spec/deck_spec.rb
|
291
|
+
- spec/input_helpers_spec.rb
|
224
292
|
- spec/samples_run_spec.rb
|
225
293
|
- spec/spec_helper.rb
|
226
294
|
- squib.gemspec
|
@@ -245,14 +313,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
245
313
|
version: '0'
|
246
314
|
requirements: []
|
247
315
|
rubyforge_project:
|
248
|
-
rubygems_version: 2.
|
316
|
+
rubygems_version: 2.2.2
|
249
317
|
signing_key:
|
250
318
|
specification_version: 2
|
251
319
|
summary: A Ruby DSL for prototyping card games
|
252
320
|
test_files:
|
253
321
|
- spec/api/api_text_spec.rb
|
254
322
|
- spec/commands/new_spec.rb
|
323
|
+
- spec/data/multi-extends-single-entry.yml
|
324
|
+
- spec/data/multi-level-extends.yml
|
325
|
+
- spec/data/no-extends.yml
|
326
|
+
- spec/data/single-extends.yml
|
327
|
+
- spec/data/single-level-multi-extends.yml
|
255
328
|
- spec/deck_spec.rb
|
329
|
+
- spec/input_helpers_spec.rb
|
256
330
|
- spec/samples_run_spec.rb
|
257
331
|
- spec/spec_helper.rb
|
258
332
|
has_rdoc:
|
data/API.md
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
# Squib API
|
2
|
-
|
3
|
-
The Squib DSL is based on a collection of methods provided to the `Squib::Deck` class. The general philosophy of Squib is to specify as little as possible with layers of defaults, highly flexible input, and good ol' Ruby duck-typing. Ruby does a lot to make Squib useful.
|
4
|
-
|
5
|
-
# Squib::Deck and Squib::Card
|
6
|
-
|
7
|
-
Squib essentially has two main classes: `Deck` and `Card`. `Deck` is the front-end, and `Card` is the back-end. The contract of `Deck` is to do the various manipulations of options and then delegate the operation to `Card` to do the low-level graphical operations.
|
8
|
-
|
9
|
-
For most users, I recommending solely using `Deck` methods. If you want to roll up your sleeves and get your hands messy, you can access the Cairo or Pango contexts the directly via the `Card` class. The API documentation doesn't really cover these, however, so you're on your own there.
|
10
|
-
|
11
|
-
# Specifying Parameters
|
12
|
-
|
13
|
-
Squib is all about sane defaults and shorthand specification. Arguments are almost always using hashes, which look a lot like [Ruby 2.0's named parameters](http://www.ruby-doc.org/core-2.0.0/doc/syntax/calling_methods_rdoc.html#label-Keyword+Arguments). This means you can specify your parameters in any order you please. All parameters are optional. For example `x` and `y` default to 0 (i.e. the upper-left corner of the card). Any parameter that is specified in the command overrides any Squib defaults, `config.yml` settings, or layout rules.
|
14
|
-
|
15
|
-
# Specifying Ranges
|
16
|
-
|
17
|
-
Most public `Deck` methods allow a `range` to be specified as a first parameter. This parameter is used to access an internal `Array` of `Squib::Cards`. This can be an actual Ruby range, or anything that implements `#each` (thus can be an `Enumerable`). Integers are also supported for changing one card only. Negatives work from the back of the deck. Here are some examples from `samples/ranges.rb` found [here](https://github.com/andymeneely/squib/tree/master/samples/ranges.rb)
|
18
|
-
|
19
|
-
{include:file:samples/ranges.rb}
|
20
|
-
|
21
|
-
Many more examples can be found in `ranges.rb` in the [samples](https://github.com/andymeneely/squib/tree/master/samples/) folder . In particular, take a look at some idioms that uses hashes to denote things like card "types", or future-proofing against creating and deleting cards with an ID column.
|
22
|
-
|
23
|
-
# Pixels and Other Units
|
24
|
-
|
25
|
-
By default, Squib thinks in pixels. This decision was made so that we can have pixel-perfect layouts without automatically scaling everything, even though working in units is sometimes easier. To convert, we provide the `Deck#inch` method, as shown in `samples/units.rb` found [here](https://github.com/andymeneely/squib/tree/master/samples/units.rb)
|
26
|
-
|
27
|
-
{include:file:samples/units.rb}
|
28
|
-
|
29
|
-
# Specifying Colors
|
30
|
-
|
31
|
-
Colors can be specified in a wide variety of ways, mostly in a hex-string. Take a look at the examples from `samples/colors.rb`, found [here](https://github.com/andymeneely/squib/tree/master/samples/colors.rb)
|
32
|
-
|
33
|
-
{include:file:samples/colors.rb}
|
34
|
-
|
35
|
-
Under the hood, Squib uses the `rcairo` [color parser](https://github.com/rcairo/rcairo/blob/master/lib/cairo/color.rb) to accept a variety of color specifications, along with over [300 pre-defined constants](https://github.com/rcairo/rcairo/blob/master/lib/cairo/colors.rb).
|
36
|
-
|
37
|
-
# Specifying Files
|
38
|
-
|
39
|
-
All files opened for reading or writing (e.g. for `png` and `xlsx`) are opened relative to the current directory. Files opened for writing (e.g. for `save_png`) will be overwritten without warning.
|
40
|
-
|
41
|
-
# Custom Layouts
|
42
|
-
|
43
|
-
Working with x-y coordinates all the time can be tiresome, and ideally everything in a game prototype should be data-driven and easily changed. For this, many Squib methods allow for a `layout` to be set. In essence, layouts are a way of setting default values for any argument given to the command.
|
44
|
-
|
45
|
-
To use a layout, set the `layout:` option on a `Deck.new` command to point to a YAML file. Any command that allows a `layout` option can be set with a Ruby symbol or String, and the command will then load the specified `x`, `y`, `width`, and `height`. The individual command can also override these options.
|
46
|
-
|
47
|
-
Note: YAML is very finnicky about having tabs in the file. Use two spaces for indentation instead.
|
48
|
-
|
49
|
-
Layouts will override Squib's defaults, but are overriden by anything specified in the command itself. Thus, the order of precedence looks like this:
|
50
|
-
|
51
|
-
* Use what the command specified
|
52
|
-
* If anything was not yet specified, use what was given in a layout (if a layout was specified in the command and the file was given to the Deck)
|
53
|
-
* If still anything was not yet specified, use what was given in Squib's defaults.
|
54
|
-
|
55
|
-
Layouts also allow for a special `extends` field that will copy all of the settings from another entry. Only a single level of extends are supported currently (contact the developer if you want multiple levels).
|
56
|
-
|
57
|
-
See the `use_layout` sample found [here](https://github.com/andymeneely/squib/tree/master/samples/)
|
58
|
-
|
59
|
-
{include:file:samples/use_layout.rb}
|