squib 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +5 -4
- data/CHANGELOG.md +12 -2
- data/Gemfile +2 -0
- data/README.md +177 -31
- data/Rakefile +1 -0
- data/lib/squib/api/shapes.rb +25 -0
- data/lib/squib/api/text.rb +9 -3
- data/lib/squib/api/text_embed.rb +64 -0
- data/lib/squib/args/typographer.rb +112 -0
- data/lib/squib/args/unit_conversion.rb +4 -0
- data/lib/squib/card.rb +2 -1
- data/lib/squib/constants.rb +32 -1
- data/lib/squib/deck.rb +6 -1
- data/lib/squib/graphics/cairo_context_wrapper.rb +9 -1
- data/lib/squib/graphics/save_doc.rb +1 -1
- data/lib/squib/graphics/shapes.rb +16 -0
- data/lib/squib/graphics/showcase.rb +2 -0
- data/lib/squib/graphics/text.rb +105 -23
- data/lib/squib/project_template/config.yml +13 -0
- data/lib/squib/version.rb +1 -1
- data/samples/config_disable_quotes.yml +3 -0
- data/samples/config_text_markup.rb +20 -0
- data/samples/config_text_markup.yml +9 -0
- data/samples/draw_shapes.rb +5 -0
- data/samples/embed_text.rb +90 -0
- data/samples/text_options.rb +21 -7
- data/spec/api/api_text_spec.rb +3 -3
- data/spec/args/typographer_spec.rb +71 -0
- data/spec/data/samples/autoscale_font.rb.txt +9 -9
- data/spec/data/samples/basic.rb.txt +12 -12
- data/spec/data/samples/config_text_markup.rb.txt +75 -0
- data/spec/data/samples/csv_import.rb.txt +12 -12
- data/spec/data/samples/custom_config.rb.txt +2 -6
- data/spec/data/samples/draw_shapes.rb.txt +11 -0
- data/spec/data/samples/embed_text.rb.txt +295 -0
- data/spec/data/samples/excel.rb.txt +18 -18
- data/spec/data/samples/gradients.rb.txt +2 -2
- data/spec/data/samples/hello_world.rb.txt +2 -2
- data/spec/data/samples/portrait-landscape.rb.txt +2 -2
- data/spec/data/samples/ranges.rb.txt +48 -48
- data/spec/data/samples/saves.rb.txt +32 -32
- data/spec/data/samples/showcase.rb.txt +8 -8
- data/spec/data/samples/text_options.rb.txt +162 -120
- data/spec/data/samples/tgc_proofs.rb.txt +4 -4
- data/spec/graphics/graphics_text_spec.rb +13 -11
- data/spec/samples/samples_regression_spec.rb +2 -0
- data/spec/spec_helper.rb +22 -5
- data/squib.gemspec +1 -1
- data/squib.sublime-project +49 -0
- metadata +17 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c5c85ffb9c9c92b81c4f2ad180fd3965ab5c494
|
4
|
+
data.tar.gz: 81462e7d7476b0e874d4fe2bb6eba4928e08876c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43b399f4f92899eef5694dca52405126a8de832f79d7cb1703d365fe3671bd54fbab54a9e801ffa509fa358b7c74de23d94b8125e2b02809eacf1315fc12aaf9
|
7
|
+
data.tar.gz: c334016446d1784927b72d538391d72ec963fdca231aa101151f6dfa25a8c7b88b96b70272f6d79b6c9ccfbc300eade29b66aa7b1adac06a8f45e05c47787fa5
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,18 @@
|
|
1
1
|
# Squib CHANGELOG
|
2
2
|
|
3
|
-
|
3
|
+
## v0.5.0
|
4
|
+
* Embedding of SVGs and PNGs into text! See README, `text_options.rb`, and `embed_text.rb`, and API documentation. This was a finnicky feature, so feedback and bug reports are welcome. (#30)
|
5
|
+
* Curves! We can now do Bezier curves. Documented, and added to the sample `draw_shapes.rb` (#37).
|
6
|
+
* Smart Quotes! The `text` rule now has a `quotes: 'smart'` option where straight quotes get converted to curly quotes. Assumes UTF-8, or you can specify your own quote characters if you're not in UTF-8. (#50)
|
7
|
+
|
8
|
+
Known issues
|
9
|
+
* OSX Yosemite will show this warning: `<Error>: The function ‘CGFontGetGlyphPath’ is obsolete and will be removed in an upcoming update. Unfortunately, this application, or a library it uses, is using this obsolete function, and is thereby contributing to an overall degradation of system performance.` This warning will go away when the Ruby Cairo bindings upgrades from 1.14.1 to 1.14.2.
|
10
|
+
|
11
|
+
Special thanks to [pickfifteen](https://github.com/pickfifteen) for testing, feedback, and pull requests!!
|
12
|
+
|
13
|
+
## v0.4.0
|
4
14
|
* SVG backend support! You can now set the deck's back end to work with SVGs instead of images, making the resulting PDFs vectorized. (You can still save to PNGs too.) This was a big change for Squib, and it's got at least one known issue and probably a few more here and there. See discussion on the README for more details.
|
5
|
-
* Added config option for antialiasing method. My benchmarks showed that 'best' is only 10% slower than 'fast' on extremely alias-intensive tasks, so
|
15
|
+
* Added config option for antialiasing method. My benchmarks showed that 'best' is only 10% slower than 'fast' on extremely alias-intensive tasks, so 'best' is the Squib default now.
|
6
16
|
* Bugfix: Stray stroke on circles after text (#35)
|
7
17
|
* Bugfix: Progress bar increment error (#34)
|
8
18
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -40,9 +40,12 @@ And then execute:
|
|
40
40
|
|
41
41
|
$ bundle
|
42
42
|
|
43
|
-
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 may require compiling C code to install. This is usually not painful at all, but can cause headaches on some setups.
|
43
|
+
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 may require compiling C code to install. This is usually not painful at all, but can cause headaches on some setups.
|
44
|
+
* Windows: I *strongly* recommend using the *non-64 bit* RubyInstaller at http://rubyinstaller.org along with installing DevKit.
|
45
|
+
* Mac: I recommend using [rvm](https://rvm.io).
|
46
|
+
* Cywgin is not 100% supported, but could potentially work with extra installation steps. See [this thread](http://boardgamegeek.com/article/18508113#18508113)
|
44
47
|
|
45
|
-
|
48
|
+
Squib requires Ruby 2.0 or later.
|
46
49
|
|
47
50
|
## Getting Started
|
48
51
|
|
@@ -82,15 +85,14 @@ About the other files:
|
|
82
85
|
|
83
86
|
# Learning Squib
|
84
87
|
|
85
|
-
|
88
|
+
In addition to this README, be sure to also check out the following resources for more details:
|
86
89
|
|
87
|
-
* 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)
|
88
90
|
* The `samples` directory in the [source repository](https://github.com/andymeneely/squib) has lots of examples.
|
89
91
|
* [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.
|
90
92
|
|
91
93
|
## Viewing this README
|
92
94
|
|
93
|
-
The best place to read this documentation is on [our website](http://andymeneely.github.io/squib/doc).
|
95
|
+
The best place to read this documentation is on [our website](http://andymeneely.github.io/squib/doc). Be sure to check out the method-by-method documentation, particularly for the [Deck](Squib/Deck.html) class.
|
94
96
|
|
95
97
|
If you want to view it offline, you can do the following
|
96
98
|
|
@@ -102,9 +104,9 @@ Then go to [http://localhost:8808/docs/squib/file/README.md](http://localhost:88
|
|
102
104
|
|
103
105
|
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. Github doesn't render those and you might find them helpful.
|
104
106
|
|
105
|
-
Also, RubyDoc.info linked from RubyGems
|
107
|
+
Also, RubyDoc.info linked from RubyGems appears to be perpetually broken and doesn't support `{include:file...}` directive properly, so the embedded samples will also not show up there, either.
|
106
108
|
|
107
|
-
## Squib
|
109
|
+
## Squib Decks and Cards
|
108
110
|
|
109
111
|
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.
|
110
112
|
|
@@ -139,7 +141,7 @@ text str: %w(red green blue),
|
|
139
141
|
y: [700, 750, 800]
|
140
142
|
```
|
141
143
|
|
142
|
-
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
|
144
|
+
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 expansion - which 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. If you don't, Ruby will fill that up with nils and not apply the rule across those cards.
|
143
145
|
|
144
146
|
## Specifying Ranges
|
145
147
|
|
@@ -187,29 +189,149 @@ Check out the following sample from `samples/gradients.rb`, found [here](https:/
|
|
187
189
|
|
188
190
|
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.
|
189
191
|
|
192
|
+
If you find that you `cd` a lot while working on the command line, your `_output` folder might get generated in multiple places. An easy way to fix this is to use a `Rakefile`, [see below](#Rakefile)
|
193
|
+
|
194
|
+
## Working with Text
|
195
|
+
The `text` method is a particularly powerful method with a ton of options. Be sure to check the [API docs](docs/Squib/Deck#text-instance_method) on an option-by-option discussion, but here are the highlights.
|
196
|
+
|
197
|
+
**Fonts**. The font is specified in a given Pango "font string", which can involve a ton of options embedded there in the string. In addition to the typical bold and italic variations, you can also specify all-caps, the specific boldness weight (e.g. 900), or go with oblique. These options are only available if the underlying font supports them, however. Here's are some example Pango font strings:
|
198
|
+
|
199
|
+
```
|
200
|
+
Sans 18
|
201
|
+
Arial,Verdana weight=900 style=oblique 36
|
202
|
+
Times New Roman,Sans 25
|
203
|
+
```
|
204
|
+
|
205
|
+
Note: When the font has a space it, you'll need to put a backup to get Pango's parsing to work.
|
206
|
+
|
207
|
+
It's also important to note that most of the font rendering is done by a combination of your installed fonts, your OS, and your graphics card. Thus, different systems will render text slightly differently.
|
208
|
+
|
209
|
+
Furthermore, options like `font_size` allow you to override the font string. This means that you can set a blanket font for the whole deck, then adjust sizes from there. This is useful with layouts and `extends` too.
|
210
|
+
|
211
|
+
### Width and Height
|
212
|
+
|
213
|
+
By default, Pango text boxes will scale the text box to whatever you need, hence the `:native` default. However, for most of the other customizations to work (e.g. center-aligned) you'll need to specify the width. If both the width and the height are specified and the text overflows, then the `ellipsize` option is consulted to figure out what to do with the overflow. Also, the `valign` will only work if `height` is also set to something other than `:native`.
|
214
|
+
|
215
|
+
###Hints
|
216
|
+
|
217
|
+
Laying out text by typing in numbers can be confusing. What Squib calls "hints" is merely a rectangle around the text box. Hints can be turned on globally in the config file, using the `set` method, or in an individual text method. These are there merely for prototyping and are not intended for production. Additionally, these are not to be conflated with "rendering hints" that Pango and Cairo mention in their documentation.
|
218
|
+
|
219
|
+
###Extents
|
220
|
+
|
221
|
+
Sometimes you want size things based on the size of your rendered text. For example, drawing a rectangle around card's title such that the rectangle perfectly fits. Squib returns the final rendered size of the text so you can work with it afterward. It's an array of hashes that correspond to each card. The output looks like this:
|
222
|
+
|
223
|
+
```ruby
|
224
|
+
Squib::Deck.new(cards: 2) do
|
225
|
+
extents = text(str: ['Hello', 'World!'])
|
226
|
+
p extents
|
227
|
+
end
|
228
|
+
```
|
229
|
+
Will output:
|
230
|
+
```
|
231
|
+
[{:width=>109, :height=>55}, {:width=>142, :height=>55}] # Hello was 109 pixels wide, World 142 pixels
|
232
|
+
```
|
233
|
+
|
234
|
+
###Embedding Images
|
235
|
+
|
236
|
+
Squib can embed icons into the flow of text. To do this, you need to define text keys for Squib to look for, and then the corresponding files. The object given to the block is a [TextEmbed](docs/Squib/TextEmbed), which supports PNG and SVG. Here's a minimal example:
|
237
|
+
|
238
|
+
```ruby
|
239
|
+
text(str: 'Gain 1 :health:') do |embed|
|
240
|
+
embed.svg key: ':health:', file: 'heart.svg'
|
241
|
+
end
|
242
|
+
```
|
243
|
+
|
244
|
+
###Markup
|
245
|
+
|
246
|
+
If you want to do specialized formatting within a given string, Squib has lots of options. By setting `markup: true`, you enable tons of text processing. This includes:
|
247
|
+
|
248
|
+
* Pango Markup. This is an HTML-like formatting language that specifies formatting inside your string. Pango Markup essentially supports any formatting option, but on a letter-by-letter basis. Such as: font options, letter spacing, gravity, color, etc. See the [Pango docs](https://developer.gnome.org/pango/stable/PangoMarkupFormat.html) for details.
|
249
|
+
* Quotes are converted to their curly counterparts where appropriate (i.e. “smart quotes” instead of "straight quotes").
|
250
|
+
* Apostraphes are converted to curly as well.
|
251
|
+
* LaTeX-style quotes are explicitly converted (<tt>``like this''</tt>)
|
252
|
+
* Em-dash and en-dash are converted with triple and double-dashes respectively (<tt>--</tt> is an en-dash, and <tt>---</tt> becomes an em-dash.)
|
253
|
+
* Ellipses can be specified with <tt>...</tt>. Note that this is entirely different from the `ellipsize` option (which determines what to do with overflowing text).
|
254
|
+
|
255
|
+
A few notes:
|
256
|
+
* Smart quoting assumes the UTF-8 character set.
|
257
|
+
* Pango markup uses an XML/HTML-ish processor. Some characters require HTML-entity escaping (e.g. `&` for `&')
|
258
|
+
|
259
|
+
### Text Sample
|
260
|
+
```yaml
|
261
|
+
lsquote: "\u2018" #note that Yaml wants double quotes here to use escape chars
|
262
|
+
rsquote: "\u2019"
|
263
|
+
ldquote: "\u201C"
|
264
|
+
rdquote: "\u201D"
|
265
|
+
em_dash: "\u2014"
|
266
|
+
en_dash: "\u2013"
|
267
|
+
ellipsis: "\u2026"
|
268
|
+
```
|
269
|
+
|
270
|
+
You can also disable the auto-quoting mechanism by setting `smart_quotes: false` in your config. Explicit replacements will still be performed.
|
271
|
+
|
272
|
+
### Text Samples
|
273
|
+
|
274
|
+
Examples of all of the above are crammed into the `text_options.rb` sample [found here](https://github.com/andymeneely/squib/tree/master/samples/text_options.rb).
|
275
|
+
|
276
|
+
{include:file:samples/text_options.rb}
|
277
|
+
|
278
|
+
The `embed_text.rb` sample has more examples of embedding text, which can be [found here](https://github.com/andymeneely/squib/tree/master/samples/embed_text.rb).
|
279
|
+
|
280
|
+
{include:file:samples/embed_text.rb}
|
281
|
+
|
282
|
+
The `config_text_markup.rb` sample demonstrates how quoting can be configured, [found here](https://github.com/andymeneely/squib/tree/master/samples/config_text_markup.rb)
|
283
|
+
|
284
|
+
{include:file:samples/config_text_markup.rb}
|
285
|
+
|
286
|
+
|
190
287
|
## Custom Layouts
|
191
288
|
|
192
289
|
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.
|
193
290
|
|
194
291
|
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.
|
195
292
|
|
196
|
-
|
293
|
+
Instead of this:
|
294
|
+
```ruby
|
295
|
+
# deck.rb
|
296
|
+
Squib::Deck.new(layout: 'custom-layout.yml') do
|
297
|
+
rect x: 75, y: 75, width: 675, height: 975
|
298
|
+
end
|
299
|
+
```
|
300
|
+
|
301
|
+
You can put your logic in the layout file and reference them:
|
302
|
+
```yaml
|
303
|
+
# custom-layout.yml
|
304
|
+
frame:
|
305
|
+
x: 75
|
306
|
+
y: 75
|
307
|
+
width: 975
|
308
|
+
height: 675
|
309
|
+
```
|
310
|
+
Then your script looks like this:
|
311
|
+
```ruby
|
312
|
+
# deck.rb
|
313
|
+
Squib::Deck.new(layout: 'custom-layout.yml') do
|
314
|
+
rect layout: 'frame'
|
315
|
+
end
|
316
|
+
```
|
317
|
+
The goal is to make your Ruby code more separate data from logic, which in turn makes your code more readable and maintainable. With `extends` (see below), layouts become even more powerful in keeping you from repeating yourself.
|
197
318
|
|
198
|
-
|
319
|
+
Note: YAML is very finnicky about not allowing tab characters. 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).
|
320
|
+
|
321
|
+
### Order of Precedence
|
322
|
+
|
323
|
+
Layouts will override Squib's system defaults, but are overriden by anything specified in the command itself. Thus, the order of precedence looks like this:
|
199
324
|
|
200
325
|
* Use what the command specified
|
201
326
|
* 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)
|
202
327
|
* If still anything was not yet specified, use what was given in Squib's defaults.
|
203
328
|
|
204
|
-
Layouts also allow merging, extending, and combining layouts. The sample demonstrates this, but they are also explained below. See the `layouts.rb` sample found [here](https://github.com/andymeneely/squib/tree/master/samples/)
|
205
|
-
|
206
|
-
{include:file:samples/layouts.rb}
|
207
|
-
|
208
329
|
### Special key: `extends`
|
209
330
|
|
210
|
-
Squib provides a way of reusing layouts with the special `extends` key. 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
|
331
|
+
Squib provides a way of reusing layouts with the special `extends` key. 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 place text next to an icon and be able to move them with each other. Like this:
|
211
332
|
|
212
333
|
```yaml
|
334
|
+
# If we change the xy of attack, we move defend too!
|
213
335
|
attack:
|
214
336
|
x: 100
|
215
337
|
y: 100
|
@@ -220,7 +342,7 @@ defend:
|
|
220
342
|
#defend now is {:x => 150, :y => 100}
|
221
343
|
```
|
222
344
|
|
223
|
-
|
345
|
+
If you want to extend multiple parents, it looks like this:
|
224
346
|
|
225
347
|
```yaml
|
226
348
|
socrates:
|
@@ -233,6 +355,7 @@ aristotle:
|
|
233
355
|
- plato
|
234
356
|
x: += 50
|
235
357
|
```
|
358
|
+
If multiple keys override the same keys in a parent, the later ("younger") child takes precedent.
|
236
359
|
|
237
360
|
Note that extends keys are similar to Yaml's ["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:
|
238
361
|
|
@@ -246,11 +369,11 @@ icon_left
|
|
246
369
|
# The layout for icon_left will have the width/height from icon!
|
247
370
|
```
|
248
371
|
|
249
|
-
If you use both `extends` and Yaml merge keys, the Yaml merge keys are processed first, then extends. For clarity, however, you're probably just better off using `extends`
|
372
|
+
If you use both `extends` and Yaml merge keys, the Yaml merge keys are processed first, then extends. For clarity, however, you're probably just better off using `extends` exclusively.
|
250
373
|
|
251
374
|
### Multiple layout files
|
252
375
|
|
253
|
-
Squib also supports the combination of multiple layout files.
|
376
|
+
Squib also supports the combination of multiple layout files. If you provide an `Array` of files then Squib will merge them sequentially. Colliding keys will be completely re-defined by the later file. Extends is processed after _each file_. Here's a complex example:
|
254
377
|
|
255
378
|
```yaml
|
256
379
|
# load order: a.yml, b.yml
|
@@ -271,24 +394,31 @@ parent_b:
|
|
271
394
|
# file b.yml #
|
272
395
|
##############
|
273
396
|
child_a:
|
274
|
-
extends: parent_a
|
275
|
-
x: += 3 # evaluates to 113
|
397
|
+
extends: parent_a # i.e. extends a layout in a separate file
|
398
|
+
x: += 3 # evaluates to 113 (i.e 110 + 3)
|
276
399
|
parent_b: # redefined
|
277
400
|
extends: grandparent
|
278
|
-
x: += 30 # evaluates to 130
|
401
|
+
x: += 30 # evaluates to 130 (i.e. 100 + 30)
|
279
402
|
child_b:
|
280
403
|
extends: parent_b
|
281
|
-
x: += 3 # evaluates to 133
|
404
|
+
x: += 3 # evaluates to 133 (i.e. 130 + 3)
|
282
405
|
```
|
283
406
|
|
284
|
-
This can
|
407
|
+
This can be helpful for:
|
285
408
|
* Creating a base layout for structure, and one for color (for easier color/black-and-white switching)
|
286
409
|
* Sharing base layouts with other designers
|
287
410
|
|
411
|
+
YAML merge keys are NOT supported across multiple files - use `extends` instead.
|
412
|
+
|
288
413
|
### Built-in Layout Files
|
289
414
|
|
290
415
|
If your layout file is not found in the current directory, Squib will search for its own set of layout files (here's the latest the development version [on GitHub](https://github.com/andymeneely/squib/tree/master/lib/squib/layouts). See the `layouts.rb` sample found [here](https://github.com/andymeneely/squib/tree/master/samples/) for some demonstrative examples.
|
291
416
|
|
417
|
+
### Layout Sample
|
418
|
+
This sample demonstrates many different ways of using and combining layouts. This is the `layouts.rb` sample found [here](https://github.com/andymeneely/squib/tree/master/samples/)
|
419
|
+
|
420
|
+
{include:file:samples/layouts.rb}
|
421
|
+
|
292
422
|
## Backends: Raster vs. Vector
|
293
423
|
Under the hood, Cairo has the ability to support a variety of surfaces to draw on, including both raster images stored in memory and vectors stored in SVG files. Thus, Squib supports the ability to handle both. They are options in the configuration file `backend: memory` or `backend: svg`.
|
294
424
|
|
@@ -312,7 +442,7 @@ Squib supports various configuration properties that can be specified in an exte
|
|
312
442
|
* `dpi` (Integer, default: 300). Used in calculations when units are used (e.g. for PDF rendering and unit conversion).
|
313
443
|
* `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.
|
314
444
|
* `custom_colors` (Hash of Colors, default: {}). Defines globally-available colors available to the deck that can be specified in commands.
|
315
|
-
* `antialias` (`fast, good, best, none`, default: best). Set the algorithm that Cairo will use for antialiasing. Using our benchmarks on large decks, `best` is only
|
445
|
+
* `antialias` (`fast, good, best, none, gray, subpixel`, default: best). Set the algorithm that Cairo will use for antialiasing. Using our benchmarks on large decks, `best` is only ~10% slower anyway. For more info see the [Cairo docs](http://www.cairographics.org/manual/cairo-cairo-t.html#cairo-antialias-t).
|
316
446
|
* `backend` (`svg` or `memory`, default: `memory`). Defines how Cairo will store the operations. Memory is recommended for higher quality rendering.
|
317
447
|
* `prefix` (default: `card_`). When using an SVG backend, cards are auto-saved with this prefix and `"%02d"` numbering format.
|
318
448
|
|
@@ -344,7 +474,7 @@ If you REALLY want to see tons of output, you can also set DEBUG, but that's not
|
|
344
474
|
|
345
475
|
Squib tries to keep you DRY (Don't Repeat Yourself) with the following features:
|
346
476
|
|
347
|
-
* 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.
|
477
|
+
* 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. Squib goes even further and has a special "extends" that works especially well for grouped-together styles.
|
348
478
|
* 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.
|
349
479
|
* Custom colors keep you from hardcoding magic color strings everywhere. Custom colors go into `config.yml` file.
|
350
480
|
* Plus, you know, Ruby.
|
@@ -373,17 +503,33 @@ When you run `squib new`, you are given a basic Rakefile. At this stage of Squib
|
|
373
503
|
|
374
504
|
* If you're in a subdirectory at the time, `rake` will simply traverse up and `cd` to the proper directory so you don't get rogue `_output` directories
|
375
505
|
* If you find yourself building multiple decks, you can make your own tasks for each one individually, or all (e.g. `rake marketing`)
|
376
|
-
* Don't need the `require squib` at the top of your code (although that breaks `ruby deck.rb`, so
|
506
|
+
* Don't need the `require squib` at the top of your code (although that breaks `ruby deck.rb`, so that's probably a bad idea)
|
377
507
|
|
378
|
-
|
508
|
+
## Using Google Sheets
|
379
509
|
|
380
|
-
|
510
|
+
We don't officially support Google Sheets ([yet](https://github.com/andymeneely/squib/issues/49)), but [this Gist](https://gist.github.com/pickfifteen/aeee73ec2ce162b0aee8) might be helpful in automatically exporting the CSV.
|
511
|
+
|
512
|
+
# Get Involved
|
513
|
+
|
514
|
+
Squib is an open source tool, and I welcome participation. Squib is currently in pre-release alpha, so the API is still maturing. I do change my mind about the names and meaning of things at this stage. I will document these changes as best as I can. I also highly recommend upgrading to new versions of Squib every chance you get (using Bundler).
|
515
|
+
|
516
|
+
Feel free to [file a bug or feature request](https://github.com/andymeneely/squib/issues). For bugs, a minimal code example along with your OS and Ruby details would be ideal.
|
517
|
+
|
518
|
+
## Testing Pre-Builds
|
519
|
+
|
520
|
+
If you want to test new features as I develop them, you can always point your Gemfile to the repository. Your Gemfile specification looks like this:
|
521
|
+
|
522
|
+
```
|
523
|
+
gem 'squib', :git => 'git://github.com/andymeneely/squib', :branch => "dev"
|
524
|
+
```
|
525
|
+
* The `dev` branch is where I am working on features in-process. I have not done much regression testing at this point, but would love testing feedback nonetheless.
|
526
|
+
* The `master` branch is where I consider features that are done and tested, but not released yet.
|
381
527
|
|
382
|
-
|
528
|
+
## Contributing
|
383
529
|
|
384
|
-
|
530
|
+
If you want your code integrated:
|
385
531
|
|
386
|
-
1. Fork
|
532
|
+
1. Fork the git repository ( https://github.com/[my-github-username]/squib/fork )
|
387
533
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
388
534
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
389
535
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
@@ -11,6 +11,7 @@ task default: [:install, :spec]
|
|
11
11
|
task :run,[:file] => :install do |t, args|
|
12
12
|
args.with_defaults(file: 'basic.rb')
|
13
13
|
Dir.chdir('samples') do
|
14
|
+
args[:file] << ".rb" unless args[:file].end_with? '.rb'
|
14
15
|
puts "Running samples/#{args[:file]}"
|
15
16
|
load args[:file]
|
16
17
|
end
|
data/lib/squib/api/shapes.rb
CHANGED
@@ -113,5 +113,30 @@ module Squib
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
+
# Draw a curve using the given coordinates
|
117
|
+
#
|
118
|
+
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
|
119
|
+
# @option opts x1 [Integer] (0) the x-coordinate of the first endpoint. Supports Unit Conversion, see {file:README.md#Units Units}.
|
120
|
+
# @option opts y1 [Integer] (0) the y-coordinate of the first endpoint. Supports Unit Conversion, see {file:README.md#Units Units}.
|
121
|
+
# @option opts x2 [Integer] (50) the x-coordinate of the second endpoint. Supports Unit Conversion, see {file:README.md#Units Units}.
|
122
|
+
# @option opts y2 [Integer] (50) the y-coordinate of the second endpoint. Supports Unit Conversion, see {file:README.md#Units Units}.
|
123
|
+
# @option opts cx1 [Integer] (0) the x-coordinate of the first control point. Supports Unit Conversion, see {file:README.md#Units Units}.
|
124
|
+
# @option opts cy1 [Integer] (0) the y-coordinate of the first control point. Supports Unit Conversion, see {file:README.md#Units Units}.
|
125
|
+
# @option opts cx2 [Integer] (50) the x-coordinate of the second control point. Supports Unit Conversion, see {file:README.md#Units Units}.
|
126
|
+
# @option opts cy2 [Integer] (50) the y-coordinate of the second control point. Supports Unit Conversion, see {file:README.md#Units Units}.
|
127
|
+
# @option opts stroke_color [String] (:black) the color with which to stroke the line. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}.
|
128
|
+
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke. Supports Unit Conversion, see {file:README.md#Units Units}.
|
129
|
+
# @return [nil] intended to be void
|
130
|
+
# @api public
|
131
|
+
def curve(opts = {})
|
132
|
+
opts = needs(opts, [:range, :x1, :y1, :cx1, :cy1, :x2, :y2, :cx2, :cy2,
|
133
|
+
:layout, :fill_color, :stroke_color, :stroke_width])
|
134
|
+
opts[:range].each do |i|
|
135
|
+
@cards[i].curve(opts[:x1][i], opts[:y1][i], opts[:cx1][i], opts[:cy1][i],
|
136
|
+
opts[:x2][i], opts[:y2][i], opts[:cx2][i], opts[:cy2][i],
|
137
|
+
opts[:fill_color][i], opts[:stroke_color][i], opts[:stroke_width][i])
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
116
141
|
end
|
117
142
|
end
|
data/lib/squib/api/text.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'squib/api/text_embed'
|
2
|
+
|
1
3
|
module Squib
|
2
4
|
class Deck
|
3
5
|
|
@@ -23,7 +25,7 @@ module Squib
|
|
23
25
|
# @option opts x [Integer] (0) the x-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
24
26
|
# @option opts y [Integer] (0) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
25
27
|
# @option opts color [String] (:black) the color the font will render to. Gradients supported. See {file:README.md#Specifying_Colors___Gradients Specifying Colors}
|
26
|
-
# @option opts markup: [Boolean] (false) Enable markup parsing of `str` using the HTML-like Pango Markup syntax, defined [here](http://ruby-gnome2.sourceforge.jp/hiki.cgi?pango-markup) and [here](https://developer.gnome.org/pango/stable/PangoMarkupFormat.html).
|
28
|
+
# @option opts markup: [Boolean] (false) Enable markup parsing of `str` using the HTML-like Pango Markup syntax, defined [here](http://ruby-gnome2.sourceforge.jp/hiki.cgi?pango-markup) and [here](https://developer.gnome.org/pango/stable/PangoMarkupFormat.html). Also does other replacements, such as smart quotes, curly apostraphes, en- and em-dashes, and explict ellipses (not to be confused with ellipsize option). See README for full explanation.
|
27
29
|
# @option opts width [Integer, :native] (:native) the width of the box the string will be placed in. Stretches to the content by default.. Supports Unit Conversion, see {file:README.md#Units Units}.
|
28
30
|
# @option opts height [Integer, :native] the height of the box the string will be placed in. Stretches to the content by default. Supports Unit Conversion, see {file:README.md#Units Units}.
|
29
31
|
# @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts}
|
@@ -40,10 +42,14 @@ module Squib
|
|
40
42
|
# @api public
|
41
43
|
def text(opts = {})
|
42
44
|
opts = needs(opts, [:range, :str, :font, :font_size, :x, :y, :width, :height, :color, :wrap,
|
43
|
-
:align, :justify, :spacing, :valign, :markup, :ellipsize, :hint, :layout,
|
45
|
+
:align, :justify, :spacing, :valign, :markup, :ellipsize, :hint, :layout,
|
46
|
+
:angle, :quotes])
|
47
|
+
embed = TextEmbed.new
|
48
|
+
yield(embed) if block_given? #store the opts for later use
|
44
49
|
extents = Array.new(@cards.size)
|
45
50
|
opts[:range].each do |i|
|
46
|
-
extents[i] = @cards[i].text(
|
51
|
+
extents[i] = @cards[i].text(embed, opts[:str][i],
|
52
|
+
opts[:font][i], opts[:font_size][i], opts[:color][i],
|
47
53
|
opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
|
48
54
|
opts[:markup][i], opts[:justify][i], opts[:wrap][i],
|
49
55
|
opts[:ellipsize][i], opts[:spacing][i], opts[:align][i],
|