squib 0.0.3 → 0.0.4

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 -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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cfd15b0a7b12c7d9aa2413e5303318aa4bdcfd79
4
- data.tar.gz: 0f0d28e026d3cfabaced091b79fc5416aa4c96ca
3
+ metadata.gz: 1eaf4fffac6ef2713fd716e57d2162ccbdae7bf1
4
+ data.tar.gz: 6b4356a3d3eed20f2ca31afc9c2c0d793d99f56d
5
5
  SHA512:
6
- metadata.gz: d692b3e2d1b7ca7a409464514c795b82da4d4cad2a6e9ebe4ae608384267f6efc43dd7af78f6515a0112beacd1c91b0f0eb59a4e36761d4c034de8555d29896a
7
- data.tar.gz: d3ee1a995831f2e2f68e2952df5e26cc0e38b1d1a3350f71635af4c12dda17985488fd776ea0b5738e5820b80b092a36824b614d2727ac82cde5fcc9015a78d1
6
+ metadata.gz: 529ff608835a86dd65af5ff327d494ec26940077253d9f3d543fe1cff952f5f6cc7263879ab4a0e3a8dfd271c1803f61be54eef6ee9c8c55ac4eeba46a98e087
7
+ data.tar.gz: fc032c6d63a16ca605084793c8e44e10eae6973d239cf694e46f0e27e2df239a77ccd46cb2f45892a8f260a97d4acd65a3201ec0345b770a79d56aa88a96156c
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
@@ -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
@@ -1,8 +1,8 @@
1
- --readme README.md
2
- --markup-provider=redcarpet
3
- --markup markdown
4
- --api public
5
- --asset samples:samples
6
- -
7
- samples/**/*.rb
1
+ --readme README.md
2
+ --markup-provider=redcarpet
3
+ --markup markdown
4
+ --api public
5
+ --asset samples:samples
6
+ -
7
+ samples/**/*.rb
8
8
  LICENSE.txt
@@ -0,0 +1,19 @@
1
+ # Squib CHANGELOG
2
+
3
+ ## v0.0.4
4
+ * Added a font size override so you can vary the font size with the same style across strings more easily
5
+ * Added text autoscale sample
6
+ * Added `extends` to custom layouts, allowing ways to modify parent data instead of just overriding it.
7
+ * Upgraded ruby-progressbar version
8
+ * Added text rotation (thanks novalis!)
9
+ * Fixed a mapping problem with triangles (thanks novalis!)
10
+ * Fixed global hint togglability
11
+
12
+ ## v0.0.3
13
+ * Redesigned the dynamic options system to make adding new commands much easier
14
+ * Singleton expansion
15
+ * Better documentation in README and throughout
16
+ * Implemented Junk Land in this version
17
+
18
+ ## v0.0.1-v0.0.2
19
+ * Primordial era - base functionality
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source 'https://rubygems.org'
2
- gemspec
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -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,245 +1,257 @@
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
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 ready 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
+ We just created a deck with 1 card, 825x1125 pixels, with the string "Hello, World" in the upper-left corner, saved to a PNG.
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](https://github.com/andymeneely/junk-land) 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
+ ```yaml
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
+ Also!! Squib provides a more feature-rich way of merging: the `extends` key in layouts. When defining an extends key, we can merge in another key and modify data coming in if we want to. This allows us to do things like set an inner object that changes its location based on its parent.
187
+
188
+ ```yaml
189
+ yin:
190
+ x: 100
191
+ y: 100
192
+ radius: 100
193
+ yang:
194
+ extends: yin
195
+ x: += 50
196
+ ```
197
+
198
+ See the `use_layout` sample found [here](https://github.com/andymeneely/squib/tree/master/samples/)
199
+
200
+ {include:file:samples/use_layout.rb}
201
+
202
+ ## Configuration File
203
+
204
+ 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:
205
+
206
+ * `progress_bars` (Boolean, default: false). When set to `true`, long-running operations will show a progress bar on the command line.
207
+ * `dpi` (Integer, default: 300). Used in calculations when units are used (e.g. for PDF rendering and unit conversion).
208
+ * `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.
209
+ * `custom_colors` (Hash of Colors, default: {}). Defines globally-available colors available to the deck that can be specified in commands.
210
+
211
+ The following sample demonstrates the config file.
212
+
213
+ See the `custom_config` sample found [here](https://github.com/andymeneely/squib/tree/master/samples/)
214
+
215
+ {include:file:samples/custom_config.rb}
216
+
217
+ ## Staying DRY (Don't Repeat Yourself)
218
+
219
+ Squib tries to keep you DRY with the following features:
220
+
221
+ * 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.
222
+ * 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.
223
+ * Custom colors keep you from hardcoding magic color strings everywhere. Custom colors are entered into the `config.yml` file.
224
+
225
+ ## Source control
226
+
227
+ You are using source control, right??
228
+
229
+ 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
230
+
231
+ ## Decks with multiple orientations or sizes
232
+
233
+ 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).
234
+
235
+ {include:file:samples/portrait-landscape.rb}
236
+
237
+ # Development
238
+
239
+ 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).
240
+
241
+ # Contributing
242
+
243
+ Squib is an open source tool, and I would love participation. If you want your code integrated:
244
+
245
+ 1. Fork it ( https://github.com/[my-github-username]/squib/fork )
246
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
247
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
248
+ 4. Push to the branch (`git push origin my-new-feature`)
249
+ 5. Create a new Pull Request
250
+
251
+ # What's up the with the name?
252
+
253
+ 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:
254
+
255
+ * Squibs are small explosive devices, much like Squib "explodes" your rules into a playable game
256
+ * Squibs are often used in heist movies, leading to a sudden plot twist that often resembles the twists of good tabletop game
245
257
  * 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.