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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfd15b0a7b12c7d9aa2413e5303318aa4bdcfd79
|
4
|
+
data.tar.gz: 0f0d28e026d3cfabaced091b79fc5416aa4c96ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d692b3e2d1b7ca7a409464514c795b82da4d4cad2a6e9ebe4ae608384267f6efc43dd7af78f6515a0112beacd1c91b0f0eb59a4e36761d4c034de8555d29896a
|
7
|
+
data.tar.gz: d3ee1a995831f2e2f68e2952df5e26cc0e38b1d1a3350f71635af4c12dda17985488fd776ea0b5738e5820b80b092a36824b614d2727ac82cde5fcc9015a78d1
|
data/.gitignore
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
.DS_Store
|
2
|
-
*.gem
|
3
|
-
*.rbc
|
4
|
-
.bundle
|
5
|
-
.config
|
6
|
-
.yardoc
|
7
|
-
.inch
|
8
|
-
Gemfile.lock
|
9
|
-
InstalledFiles
|
10
|
-
_yardoc
|
11
|
-
coverage
|
12
|
-
doc/
|
13
|
-
lib/bundler/man
|
14
|
-
pkg
|
15
|
-
rdoc
|
16
|
-
spec/reports
|
17
|
-
test/tmp
|
18
|
-
test/version_tmp
|
19
|
-
tmp
|
20
|
-
*.bundle
|
21
|
-
*.so
|
22
|
-
*.o
|
23
|
-
*.a
|
24
|
-
mkmf.log
|
25
|
-
_img
|
26
|
-
samples/_img
|
27
|
-
samples/_output/*.png
|
28
|
-
samples/_output/*.pdf
|
29
|
-
samples/_output/foo
|
1
|
+
.DS_Store
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
.yardoc
|
7
|
+
.inch
|
8
|
+
Gemfile.lock
|
9
|
+
InstalledFiles
|
10
|
+
_yardoc
|
11
|
+
coverage
|
12
|
+
doc/
|
13
|
+
lib/bundler/man
|
14
|
+
pkg
|
15
|
+
rdoc
|
16
|
+
spec/reports
|
17
|
+
test/tmp
|
18
|
+
test/version_tmp
|
19
|
+
tmp
|
20
|
+
*.bundle
|
21
|
+
*.so
|
22
|
+
*.o
|
23
|
+
*.a
|
24
|
+
mkmf.log
|
25
|
+
_img
|
26
|
+
samples/_img
|
27
|
+
samples/_output/*.png
|
28
|
+
samples/_output/*.pdf
|
29
|
+
samples/_output/foo
|
data/.travis.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.0.0
|
4
|
-
- 2.1.2
|
5
|
-
before_install: gem install bundler --version '~> 1.6'
|
6
|
-
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.0.0
|
4
|
+
- 2.1.2
|
5
|
+
before_install: gem install bundler --version '~> 1.6'
|
6
|
+
|
data/.yardopts
CHANGED
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
gemspec
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
Copyright (c) 2014 Andy Meneely
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2014 Andy Meneely
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,92 +1,245 @@
|
|
1
|
-
# Squib [![Gem Version](https://badge.fury.io/rb/squib.svg)](https://rubygems.org/gems/squib) [![Build Status](https://secure.travis-ci.org/andymeneely/squib.svg?branch=master)](https://travis-ci.org/andymeneely/squib) [![Dependency Status](https://gemnasium.com/andymeneely/squib.svg)](https://gemnasium.com/andymeneely/squib) [![Coverage Status](https://img.shields.io/coveralls/andymeneely/squib.svg)](https://coveralls.io/r/andymeneely/squib) [![Inline docs](http://inch-ci.org/github/andymeneely/squib.png?branch=master)](http://inch-ci.org/github/andymeneely/squib)
|
2
|
-
Squib is a Ruby [DSL](http://en.wikipedia.org/wiki/Domain-specific_language) for prototyping card and board games. With Squib, you just write a little bit of Ruby and you can compile your game's data and images into a series of images raedy for print-and-play or even print-on-demand. Squib is very data-driven - think of it like [nanDeck](http://www.nand.it/nandeck/) done "the Ruby way". Squib
|
3
|
-
|
4
|
-
*
|
5
|
-
*
|
6
|
-
*
|
7
|
-
*
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
$
|
51
|
-
$
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
.
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
* The `
|
78
|
-
*
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
1
|
+
# Squib [![Gem Version](https://badge.fury.io/rb/squib.svg)](https://rubygems.org/gems/squib) [![Build Status](https://secure.travis-ci.org/andymeneely/squib.svg?branch=master)](https://travis-ci.org/andymeneely/squib) [![Dependency Status](https://gemnasium.com/andymeneely/squib.svg)](https://gemnasium.com/andymeneely/squib) [![Coverage Status](https://img.shields.io/coveralls/andymeneely/squib.svg)](https://coveralls.io/r/andymeneely/squib) [![Inline docs](http://inch-ci.org/github/andymeneely/squib.png?branch=master)](http://inch-ci.org/github/andymeneely/squib)
|
2
|
+
Squib is a Ruby [DSL](http://en.wikipedia.org/wiki/Domain-specific_language) for prototyping card and board games. With Squib, you just write a little bit of Ruby and you can compile your game's data and images into a series of images raedy for print-and-play or even print-on-demand. Squib is very data-driven - think of it like [nanDeck](http://www.nand.it/nandeck/) done "the Ruby way". Squib supports:
|
3
|
+
|
4
|
+
* A concise set of rules for laying out your cards
|
5
|
+
* Loading PNGs and SVGs using [Cairo](http://cairographics.org/)
|
6
|
+
* Complex text rendering using [Pango](http://www.pango.org/)
|
7
|
+
* Reading `.xlsx` files
|
8
|
+
* Basic shape drawing
|
9
|
+
* Rendering decks to PNGs and PDFs
|
10
|
+
* Data-driven layouts
|
11
|
+
* Unit conversion
|
12
|
+
* Plus the full power of Ruby!
|
13
|
+
|
14
|
+
Check this out.
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
require 'squib'
|
18
|
+
|
19
|
+
Squib::Deck.new do
|
20
|
+
text str: 'Hello, World!'
|
21
|
+
save_png
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
That script just created a deck of with 1 image at 825x1125 with the string "Hello, World" in the upper-left corner.
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
Install it yourself with:
|
30
|
+
|
31
|
+
$ gem install squib
|
32
|
+
|
33
|
+
If you're using Bundler, add this line to your application's Gemfile:
|
34
|
+
|
35
|
+
gem 'squib'
|
36
|
+
|
37
|
+
And then execute:
|
38
|
+
|
39
|
+
$ bundle
|
40
|
+
|
41
|
+
Note: Squib has some native dependencies, such as [Cairo](https://github.com/rcairo/rcairo), [Pango](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Pango%3A%3ALayout), and [Nokogiri](http://nokogiri.org/), which all require DevKit to compile C code. This is usually not painful, but can cause headaches on some setups. For Windows users, I *strongly* recommend using the *non-64 bit* RubyInstaller at http://rubyinstaller.org. For Mac, I recommend using [rvm](https://rvm.io).
|
42
|
+
|
43
|
+
Note: Squib requires Ruby 2.0 or later.
|
44
|
+
|
45
|
+
## Getting Started
|
46
|
+
|
47
|
+
After installing Squib, you can create a project and run your first build like this:
|
48
|
+
|
49
|
+
```sh
|
50
|
+
$ squib new my-cool-game
|
51
|
+
$ cd my-cool-game
|
52
|
+
$ ruby deck.rb
|
53
|
+
```
|
54
|
+
|
55
|
+
The `squib new` command will generate files and folders like this:
|
56
|
+
|
57
|
+
```
|
58
|
+
_output
|
59
|
+
gitkeep.txt
|
60
|
+
.gitignore
|
61
|
+
ABOUT.md
|
62
|
+
config.yml
|
63
|
+
deck.rb
|
64
|
+
Gemfile
|
65
|
+
layout.yml
|
66
|
+
PNP NOTES.md
|
67
|
+
```
|
68
|
+
|
69
|
+
The central file here is `deck.rb`. Here's a [basic example](https://github.com/andymeneely/squib/tree/master/samples/basic.rb) of a deck to work from:
|
70
|
+
|
71
|
+
{include:file:samples/basic.rb basic.rb}
|
72
|
+
|
73
|
+
# Learning Squib
|
74
|
+
|
75
|
+
After going over this README, here are some other places to go learn Squib:
|
76
|
+
|
77
|
+
* The YARD-generated API documentation [for the latest Squib gem](http://rubydoc.info/gems/squib/) is a method-by-method reference. The `Deck` class is the main class to look at. If you are following Squib master, see [the latest version](http://rubydoc.info/github/andymeneely/squib)
|
78
|
+
* The `samples` directory in the [source repository](https://github.com/andymeneely/squib) has lots of examples. To run them, you will need to clone the repository and run them with Squib installed.
|
79
|
+
* Junk Land (link TBD) is my own creation that's uses Squib for both black-and-white print-and-play and full color.
|
80
|
+
|
81
|
+
## Viewing this README
|
82
|
+
|
83
|
+
If you're viewing this on Github, you might see some confusing tags like `{include:file:...}` - these are directives for YARD to show the embedded examples. The samples can be found on this repository, and are quite helpful. If you want to see this documentation in YARD,
|
84
|
+
|
85
|
+
Sadly, RubyDoc.info is buggy and doesn't support `{include:file...}` directive properly, so these online links will still not show the samples inline:
|
86
|
+
|
87
|
+
* The [latest Gem release](http://rubydoc.info/gems/squib/)
|
88
|
+
* The [master branch](http://rubydoc.info/github/andymeneely/squib) of this repository
|
89
|
+
|
90
|
+
To view this locally, you can do the following
|
91
|
+
|
92
|
+
```sh
|
93
|
+
$ gem install yard
|
94
|
+
$ yard server --gems
|
95
|
+
```
|
96
|
+
|
97
|
+
Then go to [http://localhost:8808/docs/squib/file/README.md](http://localhost:8808/docs/squib/file/README.md)
|
98
|
+
|
99
|
+
## Squib API
|
100
|
+
|
101
|
+
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.
|
102
|
+
|
103
|
+
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.
|
104
|
+
|
105
|
+
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.
|
106
|
+
|
107
|
+
## Specifying Parameters
|
108
|
+
|
109
|
+
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.
|
110
|
+
|
111
|
+
Note: you MUST use named parameters rather than positional parameters. For example: `save :png` will lead to an error like this:
|
112
|
+
|
113
|
+
C:/Ruby200/lib/ruby/gems/2.0.0/gems/squib-0.0.3/lib/squib/api/save.rb:12:in `save': wrong number of arguments (2 for 0..1) (ArgumentError)
|
114
|
+
from deck.rb:22:in `block in <main>'
|
115
|
+
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/squib-0.0.3/lib/squib/deck.rb:60:in `instance_eval'
|
116
|
+
from C:/Ruby200/lib/ruby/gems/2.0.0/gems/squib-0.0.3/lib/squib/deck.rb:60:in `initialize'
|
117
|
+
from deck.rb:18:in `new'
|
118
|
+
from deck.rb:18:in `<main>'
|
119
|
+
|
120
|
+
Instead, you must name the parameters: `save format: :png`
|
121
|
+
|
122
|
+
## Arrays and Singleton Expansion
|
123
|
+
|
124
|
+
Many inputs to Squib can accept `Arrays`, which correspond to the entire deck. In fact, under the hood, if Squib is _not_ given an array, it expands it out to an array before rendering. This allows for different styles to apply to different cards. This example comes from the [ranges.rb example](https://github.com/andymeneely/squib/tree/master/samples/ranges.rb)
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
# This renders three cards, with three strings that had three different colors at three different locations.
|
128
|
+
text str: %w(red green blue),
|
129
|
+
color: [:red, :green, :blue],
|
130
|
+
x: [40, 80, 120],
|
131
|
+
y: [700, 750, 800]
|
132
|
+
```
|
133
|
+
|
134
|
+
Under the hood, Squib actually views every argument as applied each card individually. If a single argument is given to the command, it's considered a singleton that gets expanded into a deck-sized array. Supplying the array bypasses that array. This means that any array you supply instead of a singleton ought to be the same size as the deck and align the same way the indexes in the supplied `range` are.
|
135
|
+
|
136
|
+
## Specifying Ranges
|
137
|
+
|
138
|
+
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)
|
139
|
+
|
140
|
+
{include:file:samples/ranges.rb}
|
141
|
+
|
142
|
+
## Pixels and Other Units
|
143
|
+
|
144
|
+
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)
|
145
|
+
|
146
|
+
{include:file:samples/units.rb}
|
147
|
+
|
148
|
+
## Specifying Colors
|
149
|
+
|
150
|
+
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)
|
151
|
+
|
152
|
+
{include:file:samples/colors.rb}
|
153
|
+
|
154
|
+
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).
|
155
|
+
|
156
|
+
## Specifying Files
|
157
|
+
|
158
|
+
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.
|
159
|
+
|
160
|
+
## Custom Layouts
|
161
|
+
|
162
|
+
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.
|
163
|
+
|
164
|
+
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.
|
165
|
+
|
166
|
+
Note: YAML is very finnicky about having not allowing tabs. Use two spaces for indentation instead. If you get a `Psych` syntax error, this is likely the culprit. Indendation is also strongly enforced in Yaml too. See the [Yaml docs](http://www.yaml.org/YAML_for_ruby.html).
|
167
|
+
|
168
|
+
Layouts will override Squib's defaults, but are overriden by anything specified in the command itself. Thus, the order of precedence looks like this:
|
169
|
+
|
170
|
+
* Use what the command specified
|
171
|
+
* 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)
|
172
|
+
* If still anything was not yet specified, use what was given in Squib's defaults.
|
173
|
+
|
174
|
+
Since Layouts are in Yaml, we have the full power of that data format. One particular feature you should look into are ["merge keys"](http://www.yaml.org/YAML_for_ruby.html#merge_key). With merge keys, you can define base styles in one entry, then include those keys elsewhere. For example:
|
175
|
+
|
176
|
+
```sh
|
177
|
+
icon: &icon
|
178
|
+
width: 50
|
179
|
+
height: 50
|
180
|
+
icon_left
|
181
|
+
<<: *icon
|
182
|
+
x: 100
|
183
|
+
# The layout for icon_left will have the width/height from icon!
|
184
|
+
```
|
185
|
+
|
186
|
+
See the `use_layout` sample found [here](https://github.com/andymeneely/squib/tree/master/samples/)
|
187
|
+
|
188
|
+
{include:file:samples/use_layout.rb}
|
189
|
+
|
190
|
+
## Configuration File
|
191
|
+
|
192
|
+
Squib supports various configuration properties that can be specified in an external file. The `config:` option in `Deck.new` can specify an optional configuration file in YML format. The properties there are intended to be immutable for the life of the Deck. The options include:
|
193
|
+
|
194
|
+
* `progress_bars` (Boolean, default: false). When set to `true`, long-running operations will show a progress bar on the command line.
|
195
|
+
* `dpi` (Integer, default: 300). Used in calculations when units are used (e.g. for PDF rendering and unit conversion).
|
196
|
+
* `hint` (ColorString, default: off). Text hints are used to show the boundaries of text boxes. Can be enabled/disabled for individual commands, or set globally with the `set` command. This setting is overriden by `set` and individual commands.
|
197
|
+
* `custom_colors` (Hash of Colors, default: {}). Defines globally-available colors available to the deck that can be specified in commands.
|
198
|
+
|
199
|
+
The following sample demonstrates the config file.
|
200
|
+
|
201
|
+
See the `custom_config` sample found [here](https://github.com/andymeneely/squib/tree/master/samples/)
|
202
|
+
|
203
|
+
{include:file:samples/custom_config.rb}
|
204
|
+
|
205
|
+
## Staying DRY (Don't Repeat Yourself)
|
206
|
+
|
207
|
+
Squib tries to keep you DRY with the following features:
|
208
|
+
|
209
|
+
* Custom layouts allow you to specify various arguments in a separate file. This is great for x-y coordinates and alignment properties that would otherwise clutter up perfectly readable code. Yaml's "merge keys" takes this a step further and lets you specify base styles that can then be extended by other styles.
|
210
|
+
* Flexible ranges and array handling: the `range` parameter in Squib is very flexible, meaning that one `text` command can specify different text in different fonts, styles, colors, etc. for each card. If you find yourself doing multiple `text` command for the same field across different ranges of cards, there's probably a better way to condense.
|
211
|
+
* Custom colors keep you from hardcoding magic color strings everywhere. Custom colors are entered into the `config.yml` file.
|
212
|
+
|
213
|
+
## Source control
|
214
|
+
|
215
|
+
You are using source control, right??
|
216
|
+
|
217
|
+
By default, Squib assumes Git. But it's not dogmatic about it. Tracking your progress, backing up, sharing data, topic branches, release management, and reverting into history are just some of the many, many useful things you can do with source control. For me, I tend to ignore any auto-generated files in my output folder, but version control everything else. I also try to keep my graphics vector files, so the files stay small. Version control is intended for source code, so large binary files don't usually get checked in unless absolutely necessary. For big binaries with graphics I tend to keep those
|
218
|
+
|
219
|
+
## Decks with multiple orientations or sizes
|
220
|
+
|
221
|
+
If you want to make a deck that has some portrait and some landscape cards, I recommend you use multiple `Squib::Deck`s. The pixel size of a given card is designed to not change thorughout the life of a `Squib::Deck`. To work with landscape cards, there is a `rotate` option on `save_png` so you can render your print-on-demand PNGs in portrait but keep everything ekse oriented toward landscape. The following example demonstrates how to do this, found [here](https://github.com/andymeneely/squib/tree/master/samples/portrait-landscape.rb).
|
222
|
+
|
223
|
+
{include:file:samples/portrait-landscape.rb}
|
224
|
+
|
225
|
+
# Development
|
226
|
+
|
227
|
+
Squib is currently in pre-release alpha, so the API is still maturing. If you are using Squib, however, I'd love to hear about it! Feel free to [file a bug or feature request](https://github.com/andymeneely/squib/issues).
|
228
|
+
|
229
|
+
# Contributing
|
230
|
+
|
231
|
+
Squib is an open source tool, and I would love participation. If you want your code integrated:
|
232
|
+
|
233
|
+
1. Fork it ( https://github.com/[my-github-username]/squib/fork )
|
234
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
235
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
236
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
237
|
+
5. Create a new Pull Request
|
238
|
+
|
239
|
+
# What's up the with the name?
|
240
|
+
|
241
|
+
Truthfully, I just thought it was a cool, simple word that was not used much in the Ruby community nor the board game community. But, now that I've committed to the name, I've realized that:
|
242
|
+
|
243
|
+
* Squibs are small explosive devices, much like Squib "explodes" your rules into a playable game
|
244
|
+
* Squibs are often used in heist movies, leading to a sudden plot twist that often resembles the twists of good tabletop game
|
245
|
+
* Squibs are also part of the Harry Potter world - they are people who are non-magical but wizard-born. Squib is aware of wizarding magic and comes from that heritage, but it's not magical itself.
|