squib 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/CHANGELOG.md +15 -8
- data/README.md +20 -11
- data/RELEASE TODO.md +13 -0
- data/lib/squib/api/data.rb +3 -2
- data/lib/squib/api/image.rb +11 -9
- data/lib/squib/api/shapes.rb +25 -25
- data/lib/squib/api/text.rb +4 -4
- data/lib/squib/api/units.rb +15 -1
- data/lib/squib/card.rb +3 -0
- data/lib/squib/constants.rb +34 -1
- data/lib/squib/deck.rb +5 -2
- data/lib/squib/graphics/image.rb +7 -1
- data/lib/squib/graphics/save_doc.rb +57 -0
- data/lib/squib/input_helpers.rb +36 -1
- data/lib/squib/version.rb +1 -1
- data/samples/load_images.rb +4 -2
- data/samples/saves.rb +32 -0
- data/samples/text_options.rb +0 -2
- data/samples/unicode.rb +27 -0
- data/samples/units.rb +21 -5
- data/spec/api/api_image_spec.rb +1 -1
- data/spec/data/layouts/empty-rule.yml +1 -0
- data/spec/data/layouts/empty.yml +1 -0
- data/spec/data/samples/load_images.rb.txt +8 -0
- data/spec/data/samples/saves.rb.txt +702 -0
- data/spec/data/samples/text_options.rb.txt +198 -168
- data/spec/data/samples/units.rb.txt +19 -1
- data/spec/deck_spec.rb +12 -0
- data/spec/graphics/graphics_images_spec.rb +14 -12
- data/spec/graphics/graphics_save_doc_spec.rb +2 -2
- data/spec/input_helpers_spec.rb +65 -1
- data/spec/samples/samples_regression_spec.rb +11 -9
- data/spec/spec_helper.rb +2 -0
- metadata +14 -5
- data/samples/save_pdf.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54d41c6aefc288c69ad7d481ffa6e5b7b26e2658
|
4
|
+
data.tar.gz: fd8a41e64858c0b9b9a6e924dd64ee5ab52b46fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30dcd2caaa2ec623d456184a81729aea87765f81d40c726524e2117942bf316165a0df920479faa425462501296a1b984d64ab9b03b10a04bebad4815e0dbc43
|
7
|
+
data.tar.gz: 77d4d1950264389af9396aa895863fc1ba0a4ba1617d4889e0aa1ce982e05d16cd7951ab6488dcf86e05ea7997edd9ab6cc6b2b80ca27be728c848a1a94f6791
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
# Squib CHANGELOG
|
2
2
|
|
3
|
+
## v0.1.0
|
4
|
+
* Added `save_sheet` command that saves a range into PNG sheets, complete with trim, gap, margin, columns, and sometimes automagically computed rows. See samples/saves.rb.
|
5
|
+
* Unit conversion! Now you can write "2in" and it will convert based on the current dpi. `save_pdf` not supported (yet).
|
6
|
+
* `png` now supports resizing, but warns you about it since it's non-ideal. Documented in yard, tested.
|
7
|
+
* Added sample `unicode.rb` to show lots of game-related unicode characters
|
8
|
+
* More obsessive automated testing and continuous integration work.
|
9
|
+
|
3
10
|
## v0.0.6
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
* Added a `csv` command that works just like `xslx`. Uses Ruby's CSV inside, with some extra checking and warnings.
|
12
|
+
* Custom layouts now support loading & merging multiple Yaml files! Updated README, docs, and sample to document it.
|
13
|
+
* Built-in layouts! Currently we support `hand.yml` and `playing-card.yml`. Documented in the `layouts.rb` sample.
|
14
|
+
* `text` now returns the ink extent rectangle of the rendered text. Updated docs and sample to document it.
|
15
|
+
* Samples now show that you can use text instead of symbols for things like `center`
|
16
|
+
* Improved logging, and documentation on increasing logger verboseness
|
17
|
+
* Better regression testing technique that tracks when a sample has changed.
|
18
|
+
* Bumped version of Cairo to ~> 1.14
|
12
19
|
|
13
20
|
## v0.0.5
|
14
21
|
* Image rotation for png and svg via `angle`
|
data/README.md
CHANGED
@@ -1,15 +1,15 @@
|
|
1
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.
|
2
|
+
Squib is a Ruby [DSL](http://en.wikipedia.org/wiki/Domain-specific_language) for prototyping card and board games. Write a little bit of Ruby, define your deck's stats, and you can compile your game into a series of images ready for print-and-play or even print-on-demand. Squib is very data-driven and built on the principle of Don't Repeat Yourself. Think of it like [nanDeck](http://www.nand.it/nandeck/) done "the Ruby way". Squib supports:
|
3
3
|
|
4
4
|
* A concise set of rules for laying out your cards
|
5
5
|
* Loading PNGs and SVGs using [Cairo](http://cairographics.org/)
|
6
6
|
* Complex text rendering using [Pango](http://www.pango.org/)
|
7
7
|
* Reading `xlsx` and `csv` files
|
8
|
+
* Rendering to individual PNGs or PDF sheets
|
9
|
+
* Flexible, data-driven layouts in Yaml
|
8
10
|
* Basic shape drawing
|
9
|
-
* Rendering decks to PNGs and PDFs
|
10
|
-
* Data-driven layouts
|
11
11
|
* Unit conversion
|
12
|
-
*
|
12
|
+
* The full power of Ruby!
|
13
13
|
|
14
14
|
Check this out.
|
15
15
|
|
@@ -38,7 +38,7 @@ And then execute:
|
|
38
38
|
|
39
39
|
$ bundle
|
40
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
|
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 may require compiling C code to install. This is usually not painful at all, but can cause headaches on some setups. For Windows users, I *strongly* recommend using the *non-64 bit* RubyInstaller at http://rubyinstaller.org along with installing DevKit. For Mac, I recommend using [rvm](https://rvm.io).
|
42
42
|
|
43
43
|
Note: Squib requires Ruby 2.0 or later.
|
44
44
|
|
@@ -55,8 +55,7 @@ $ ruby deck.rb
|
|
55
55
|
The `squib new` command will generate files and folders like this:
|
56
56
|
|
57
57
|
```
|
58
|
-
_output
|
59
|
-
gitkeep.txt
|
58
|
+
_output/gitkeep.txt
|
60
59
|
.gitignore
|
61
60
|
ABOUT.md
|
62
61
|
config.yml
|
@@ -70,12 +69,20 @@ The central file here is `deck.rb`. Here's a [basic example](https://github.com/
|
|
70
69
|
|
71
70
|
{include:file:samples/basic.rb basic.rb}
|
72
71
|
|
72
|
+
About the other files:
|
73
|
+
* `Gemfile` is for adding in other gems if you are using `bundler`
|
74
|
+
* `config.yml` is a skeleton config file with various options commented out. See {file:README.md#Configuration_File Configuration File}.
|
75
|
+
* `layout.yml` is a skeleton layout file if you want to use it. See {file:README.md#Custom_Layouts Custom Layouts}.
|
76
|
+
* `_output` is the directory where your built files will go. Can easily be changed, of course.
|
77
|
+
* `.gitignore` and `gitkeep.txt` are for if you are using Git. See {file:README.md#Source_control Source control}. (Feel free to remove these if you are not using Git.)
|
78
|
+
* `ABOUT.md` and `PHP NOTES.md` are Markdown files for posting. Not used by Squib, but there by convention.
|
79
|
+
|
73
80
|
# Learning Squib
|
74
81
|
|
75
82
|
After going over this README, here are some other places to go learn Squib:
|
76
83
|
|
77
84
|
* 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.
|
85
|
+
* The `samples` directory in the [source repository](https://github.com/andymeneely/squib) has lots of examples.
|
79
86
|
* [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
87
|
|
81
88
|
## Viewing this README
|
@@ -137,12 +144,14 @@ Most public `Deck` methods allow a `range` to be specified as a first parameter.
|
|
137
144
|
|
138
145
|
{include:file:samples/ranges.rb}
|
139
146
|
|
140
|
-
##
|
147
|
+
## Units
|
141
148
|
|
142
|
-
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.
|
149
|
+
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. We provide some conversion methods, including looking for strings that end in "in" and "cm" and computing based on the current DPI. Example is in `samples/units.rb` found [here](https://github.com/andymeneely/squib/tree/master/samples/units.rb)
|
143
150
|
|
144
151
|
{include:file:samples/units.rb}
|
145
152
|
|
153
|
+
Note: we do not support unit conversion on `save_pdf` and `Squib::Deck.new()`, [yet](https://github.com/andymeneely/squib/issues/21)
|
154
|
+
|
146
155
|
## Specifying Colors
|
147
156
|
|
148
157
|
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)
|
@@ -286,7 +295,7 @@ Squib tries to keep you DRY (Don't Repeat Yourself) with the following features:
|
|
286
295
|
|
287
296
|
You are using source control, right??
|
288
297
|
|
289
|
-
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
|
298
|
+
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 that change often probably should not get checked in unless absolutely necessary. I tend to keep big raster graphics files (e.g. from Gimp) in cloud storage or elsewhere.
|
290
299
|
|
291
300
|
## SublimeText
|
292
301
|
|
data/RELEASE TODO.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Be sure to remember to do the following for releases. (Copy into a GitHub issue)
|
2
|
+
|
3
|
+
- [ ] CHANGELOG is written for all new changes
|
4
|
+
- [ ] README is updated
|
5
|
+
- [ ] Samples are updated
|
6
|
+
- [ ] Check that sample regression tests are all enabled
|
7
|
+
- [ ] Bump version.rb
|
8
|
+
- [ ] Do a full rake locally
|
9
|
+
- [ ] Travis is passing on dev branch
|
10
|
+
- [ ] `gem push pkg/squib-x.y.z.gem`
|
11
|
+
- [ ] `rake doc`
|
12
|
+
- [ ] Push `rake doc` to website
|
13
|
+
- [ ] Bump version.rb to the next alpha
|
data/lib/squib/api/data.rb
CHANGED
@@ -54,11 +54,11 @@ module Squib
|
|
54
54
|
# data = csv file: 'data.csv'
|
55
55
|
# => {'h1' => [1,3], 'h2' => [2,4]}
|
56
56
|
#
|
57
|
-
# Parsing uses Ruby's CSV, options
|
57
|
+
# Parsing uses Ruby's CSV, with options `{headers: true, converters: :numeric}`
|
58
58
|
# http://www.ruby-doc.org/stdlib-2.0/libdoc/csv/rdoc/CSV.html
|
59
59
|
#
|
60
60
|
# @option opts file [String] the CSV-formatted file to open. Opens relative to the current directory.
|
61
|
-
# @return [Hash] a hash of arrays based on columns in the
|
61
|
+
# @return [Hash] a hash of arrays based on columns in the table
|
62
62
|
# @api public
|
63
63
|
def csv(opts = {})
|
64
64
|
opts = Squib::SYSTEM_DEFAULTS.merge(opts)
|
@@ -90,6 +90,7 @@ module Squib
|
|
90
90
|
Squib.xlsx(opts)
|
91
91
|
end
|
92
92
|
|
93
|
+
# Convenience call on deck goes to the module function
|
93
94
|
def csv(opts = {})
|
94
95
|
Squib.csv(opts)
|
95
96
|
end
|
data/lib/squib/api/image.rb
CHANGED
@@ -4,14 +4,15 @@ module Squib
|
|
4
4
|
# Renders a png file at the given location.
|
5
5
|
#
|
6
6
|
# See {file:samples/image.rb samples/image.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
|
7
|
-
# Note: scaling not currently supported for PNGs.
|
8
7
|
# @example
|
9
8
|
# png file: 'img.png', x: 50, y: 50
|
10
9
|
#
|
11
10
|
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
|
12
11
|
# @option opts file [String] ((empty)) file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See {file:README.md#Specifying_Files Specifying Files}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
13
|
-
# @option opts x [Integer] (0) the x-coordinate to place. Supports Arrays, see {file:README#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
14
|
-
# @option opts y [Integer] (0) the y-coordinate to place. Supports Arrays, see {file:README#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
12
|
+
# @option opts x [Integer] (0) the x-coordinate to place. Supports Arrays, see {file:README#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
|
13
|
+
# @option opts y [Integer] (0) the y-coordinate to place. Supports Arrays, see {file:README#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
|
14
|
+
# @option opts width [Integer] (:native) the pixel width that the image should scale to. Scaling PNGs is not recommended for professional-looking cards. When set to `:native`, uses the DPI and units of the loaded SVG document. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
|
15
|
+
# @option opts height [Integer] (:native) the pixel width that the image should scale to. Scaling PNGs is not recommended for professional-looking cards. When set to `:native`, uses the DPI and units of the loaded SVG document. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
|
15
16
|
# @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}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
16
17
|
# @option opts alpha [Decimal] (1.0) the alpha-transparency percentage used to blend this image. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
17
18
|
# @option opts blend [:none, :multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hsl_hue, :hsl_saturation, :hsl_color, :hsl_luminosity] (:none) the composite blend operator used when applying this image. See Blend Modes at http://cairographics.org/operators. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
@@ -19,11 +20,12 @@ module Squib
|
|
19
20
|
# @return [nil] Returns nil
|
20
21
|
# @api public
|
21
22
|
def png(opts = {})
|
22
|
-
opts = needs(opts, [:range, :files, :x, :y, :alpha, :layout, :blend, :angle])
|
23
|
+
opts = needs(opts, [:range, :files, :x, :y, :width, :height, :alpha, :layout, :blend, :angle])
|
23
24
|
Dir.chdir(@img_dir) do
|
24
25
|
@progress_bar.start('Loading PNG(s)', opts[:range].size) do |bar|
|
25
26
|
opts[:range].each do |i|
|
26
|
-
@cards[i].png(opts[:file][i],
|
27
|
+
@cards[i].png(opts[:file][i],
|
28
|
+
opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
|
27
29
|
opts[:alpha][i], opts[:blend][i], opts[:angle][i])
|
28
30
|
bar.increment
|
29
31
|
end
|
@@ -41,10 +43,10 @@ module Squib
|
|
41
43
|
# @option opts file [String] ('') file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See {file:README.md#Specifying_Files Specifying Files}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
42
44
|
# @option opts id [String] (nil) if set, then only render the SVG element with the given id. Prefix '#' is optional. Note: the x-y coordinates are still relative to the SVG document's page. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
43
45
|
# @option opts force_id [Boolean] (false) if set, then this svg will not be rendered at all if the id is empty or nil. If not set, the entire SVG is rendered. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
44
|
-
# @option opts x [Integer] (0) the x-coordinate to place. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
45
|
-
# @option opts y [Integer] (0) the y-coordinate to place. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
46
|
-
# @option opts width [Integer] (:native) the pixel width that the image should scale to. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
47
|
-
# @option opts height [Integer] (:native) the pixel width that the image should scale to. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
46
|
+
# @option opts x [Integer] (0) the x-coordinate to place. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
|
47
|
+
# @option opts y [Integer] (0) the y-coordinate to place. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
|
48
|
+
# @option opts width [Integer] (:native) the pixel width that the image should scale to. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
|
49
|
+
# @option opts height [Integer] (:native) the pixel width that the image should scale to. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}. Supports Unit Conversion, see {file:README.md#Units Units}.
|
48
50
|
# @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}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
49
51
|
# @option opts alpha [Decimal] (1.0) the alpha-transparency percentage used to blend this image. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
50
52
|
# @option opts blend [:none, :multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hsl_hue, :hsl_saturation, :hsl_color, :hsl_luminosity] (:none) the composite blend operator used when applying this image. See Blend Modes at http://cairographics.org/operators. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
data/lib/squib/api/shapes.rb
CHANGED
@@ -9,16 +9,16 @@ module Squib
|
|
9
9
|
# Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
10
10
|
#
|
11
11
|
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
|
12
|
-
# @option opts x [Integer] (0) the x-coordinate to place
|
13
|
-
# @option opts y [Integer] (0) the y-coordinate to place
|
14
|
-
# @option opts width [Integer] the width of the rectangle.
|
15
|
-
# @option opts height [Integer] the height of the rectangle.
|
16
|
-
# @option opts x_radius [Integer] (0) the radius of the rounded corner horiztonally. Zero is a non-rounded corner.
|
17
|
-
# @option opts y_radius [Integer] (0) the radius of the rounded corner vertically. Zero is a non-rounded corner.
|
18
|
-
# @option opts radius [Integer] (nil) when set, overrides both x_radius and y_radius
|
12
|
+
# @option opts x [Integer] (0) the x-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
13
|
+
# @option opts y [Integer] (0) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
14
|
+
# @option opts width [Integer] the width of the rectangle. Supports Unit Conversion, see {file:README.md#Units Units}.
|
15
|
+
# @option opts height [Integer] the height of the rectangle. Supports Unit Conversion, see {file:README.md#Units Units}.
|
16
|
+
# @option opts x_radius [Integer] (0) the radius of the rounded corner horiztonally. Zero is a non-rounded corner. Supports Unit Conversion, see {file:README.md#Units Units}.
|
17
|
+
# @option opts y_radius [Integer] (0) the radius of the rounded corner vertically. Zero is a non-rounded corner. Supports Unit Conversion, see {file:README.md#Units Units}.
|
18
|
+
# @option opts radius [Integer] (nil) when set, overrides both x_radius and y_radius. Supports Unit Conversion, see {file:README.md#Units Units}.
|
19
19
|
# @option opts fill_color [String] ('#0000') the color with which to fill the rectangle
|
20
20
|
# @option opts stroke_color [String] (:black) the color with which to stroke the outside of the rectangle
|
21
|
-
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke
|
21
|
+
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke. Supports Unit Conversion, see {file:README.md#Units Units}.
|
22
22
|
# @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}
|
23
23
|
# @return [nil] intended to be void
|
24
24
|
# @api public
|
@@ -41,16 +41,16 @@ module Squib
|
|
41
41
|
# Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
42
42
|
#
|
43
43
|
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
|
44
|
-
# @option opts x [Integer] (0) the x-coordinate to place
|
45
|
-
# @option opts y [Integer] (0) the y-coordinate to place
|
46
|
-
# @option opts radius [Integer] (100) radius of the circle
|
44
|
+
# @option opts x [Integer] (0) the x-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
45
|
+
# @option opts y [Integer] (0) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
46
|
+
# @option opts radius [Integer] (100) radius of the circle. Supports Unit Conversion, see {file:README.md#Units Units}.
|
47
47
|
# @option opts fill_color [String] ('#0000') the color with which to fill the rectangle
|
48
48
|
# @option opts stroke_color [String] (:black) the color with which to stroke the outside of the rectangle
|
49
|
-
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke
|
49
|
+
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke. Supports Unit Conversion, see {file:README.md#Units Units}.
|
50
50
|
# @return [nil] intended to be void
|
51
51
|
# @api public
|
52
52
|
def circle(opts = {})
|
53
|
-
opts = {radius: 100}.merge(opts)
|
53
|
+
opts = {radius: 100}.merge(opts) # overriding the non-system default
|
54
54
|
opts = needs(opts, [:range, :x, :y, :circle_radius, :layout,
|
55
55
|
:fill_color, :stroke_color, :stroke_width])
|
56
56
|
opts[:range].each do |i|
|
@@ -67,15 +67,15 @@ module Squib
|
|
67
67
|
# Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
|
68
68
|
#
|
69
69
|
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
|
70
|
-
# @option opts x1 [Integer] (0) the x-coordinate to place
|
71
|
-
# @option opts y1 [Integer] (0) the y-coordinate to place
|
72
|
-
# @option opts x2 [Integer] (50) the x-coordinate to place
|
73
|
-
# @option opts y2 [Integer] (50) the y-coordinate to place
|
74
|
-
# @option opts x3 [Integer] (0) the x-coordinate to place
|
75
|
-
# @option opts y3 [Integer] (50) the y-coordinate to place
|
70
|
+
# @option opts x1 [Integer] (0) the x-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
71
|
+
# @option opts y1 [Integer] (0) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
72
|
+
# @option opts x2 [Integer] (50) the x-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
73
|
+
# @option opts y2 [Integer] (50) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
74
|
+
# @option opts x3 [Integer] (0) the x-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
75
|
+
# @option opts y3 [Integer] (50) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
76
76
|
# @option opts fill_color [String] ('#0000') the color with which to fill the triangle
|
77
77
|
# @option opts stroke_color [String] (:black) the color with which to stroke the outside of the triangle
|
78
|
-
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke
|
78
|
+
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke. Supports Unit Conversion, see {file:README.md#Units Units}.
|
79
79
|
# @return [nil] intended to be void
|
80
80
|
# @api public
|
81
81
|
def triangle(opts = {})
|
@@ -96,12 +96,12 @@ module Squib
|
|
96
96
|
# triangle :x1 => 0, :y1 => 0, :x2 => 50, :y2 => 50
|
97
97
|
#
|
98
98
|
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
|
99
|
-
# @option opts x1 [Integer] (0) the x-coordinate to place
|
100
|
-
# @option opts y1 [Integer] (0) the y-coordinate to place
|
101
|
-
# @option opts x2 [Integer] (50) the x-coordinate to place
|
102
|
-
# @option opts y2 [Integer] (50) the y-coordinate to place
|
99
|
+
# @option opts x1 [Integer] (0) the x-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
100
|
+
# @option opts y1 [Integer] (0) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
101
|
+
# @option opts x2 [Integer] (50) the x-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
102
|
+
# @option opts y2 [Integer] (50) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
103
103
|
# @option opts stroke_color [String] (:black) the color with which to stroke the line
|
104
|
-
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke
|
104
|
+
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke. Supports Unit Conversion, see {file:README.md#Units Units}.
|
105
105
|
# @return [nil] intended to be void
|
106
106
|
# @api public
|
107
107
|
def line(opts = {})
|
data/lib/squib/api/text.rb
CHANGED
@@ -20,12 +20,12 @@ module Squib
|
|
20
20
|
# This [description](http://www.pygtk.org/pygtk2reference/class-pangofontdescription.html) is also quite good.
|
21
21
|
# See the {file:samples/text-options.rb samples/text.rb} as well.
|
22
22
|
# @option opts font_size [Integer] (nil) an override of font string description, for scaling the font according to the size of the string
|
23
|
-
# @option opts x [Integer] (0) the x-coordinate to place
|
24
|
-
# @option opts y [Integer] (0) the y-coordinate to place
|
23
|
+
# @option opts x [Integer] (0) the x-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
24
|
+
# @option opts y [Integer] (0) the y-coordinate to place. Supports Unit Conversion, see {file:README.md#Units Units}.
|
25
25
|
# @option opts color [String] (:black) the color the font will render to. See {file:README.md#Specifying_Colors Specifying Colors}
|
26
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).
|
27
|
-
# @option opts width [Integer, :native] (:native) the width of the box the string will be placed in. Stretches to the content by default.
|
28
|
-
# @option opts height [Integer, :native] the height of the box the string will be placed in. Stretches to the content by default.
|
27
|
+
# @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
|
+
# @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
29
|
# @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}
|
30
30
|
# @option opts wrap [:none, :word, :char, :word_char, true, false] (:word_char) When height is set, determines the behavior of how the string wraps. The `:word_char` option will break at words, but then fall back to characters when the word cannot fit. #
|
31
31
|
# Options are `:none, :word, :char, :word_char`. Also: `true` is the same as `:word_char`, `false` is the same as `:none`. Default `:word_char`
|
data/lib/squib/api/units.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'squib/constants'
|
2
|
+
|
1
3
|
module Squib
|
2
4
|
class Deck
|
3
5
|
|
@@ -10,7 +12,19 @@ module Squib
|
|
10
12
|
# @return [Decimal] the number of pixels, according to the deck's DPI
|
11
13
|
# @api public
|
12
14
|
def inches(n)
|
13
|
-
@dpi * n
|
15
|
+
@dpi * n.to_f
|
16
|
+
end
|
17
|
+
|
18
|
+
# Given cm, returns the number of pixels according to the deck's DPI.
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
# cm(1) # 750 (for default Deck::dpi of 300)
|
22
|
+
#
|
23
|
+
# @param n [Decimal], the number of centimeters
|
24
|
+
# @return [Decimal] the number of pixels, according to the deck's DPI
|
25
|
+
# @api public
|
26
|
+
def cm(n)
|
27
|
+
@dpi * Squib::INCHES_IN_CM * n.to_f
|
14
28
|
end
|
15
29
|
|
16
30
|
end
|
data/lib/squib/card.rb
CHANGED
data/lib/squib/constants.rb
CHANGED
@@ -8,6 +8,7 @@ module Squib
|
|
8
8
|
:angle => 0,
|
9
9
|
:blend => :none,
|
10
10
|
:color => :black,
|
11
|
+
:columns => 1,
|
11
12
|
:default_font => 'Arial 36',
|
12
13
|
:dir => '_output',
|
13
14
|
:ellipsize => :end,
|
@@ -27,6 +28,7 @@ module Squib
|
|
27
28
|
:progress_bar => false,
|
28
29
|
:range => :all,
|
29
30
|
:rotate => false,
|
31
|
+
:rows => :infinite,
|
30
32
|
:sheet => 0,
|
31
33
|
:spacing => 0,
|
32
34
|
:str => '',
|
@@ -62,7 +64,7 @@ module Squib
|
|
62
64
|
# These are parameters that are intended to be "expanded" across
|
63
65
|
# range if they are singletons.
|
64
66
|
#
|
65
|
-
# For example
|
67
|
+
# For example: using a different font for each card, using one `text` command
|
66
68
|
#
|
67
69
|
# key: the internal name of the param (e.g. :files)
|
68
70
|
# value: the user-facing API key (e.g. file: 'abc.png')
|
@@ -106,4 +108,35 @@ module Squib
|
|
106
108
|
:y3 => :y3,
|
107
109
|
:y_radius => :y_radius,
|
108
110
|
}
|
111
|
+
|
112
|
+
# These parameters are considered for unit conversion
|
113
|
+
#
|
114
|
+
# For example
|
115
|
+
# text str: 'Hello, World', x: '1in'
|
116
|
+
#
|
117
|
+
# key: the internal name of the param (e.g. :circle_radius)
|
118
|
+
# value: the user-facing API key (e.g. radius: '1in')
|
119
|
+
UNIT_CONVERSION_PARAMS = {
|
120
|
+
:circle_radius => :radius,
|
121
|
+
:height => :height,
|
122
|
+
:rect_radius => :radius,
|
123
|
+
:spacing => :spacing,
|
124
|
+
:stroke_width => :stroke_width,
|
125
|
+
:width => :width,
|
126
|
+
:x => :x,
|
127
|
+
:x1 => :x1,
|
128
|
+
:x2 => :x2,
|
129
|
+
:x3 => :x3,
|
130
|
+
:x_radius => :x_radius,
|
131
|
+
:y => :y,
|
132
|
+
:y1 => :y1,
|
133
|
+
:y2 => :y2,
|
134
|
+
:y3 => :y3,
|
135
|
+
:y_radius => :y_radius,
|
136
|
+
}
|
137
|
+
|
138
|
+
# Used for inch-cm conversion
|
139
|
+
# :nodoc:
|
140
|
+
# @api private
|
141
|
+
INCHES_IN_CM = 0.393700787
|
109
142
|
end
|
data/lib/squib/deck.rb
CHANGED
@@ -115,7 +115,7 @@ module Squib
|
|
115
115
|
thefile = file
|
116
116
|
thefile = "#{File.dirname(__FILE__)}/layouts/#{file}" unless File.exists?(file)
|
117
117
|
if File.exists? thefile
|
118
|
-
yml = @layout.merge(YAML.load_file(thefile))
|
118
|
+
yml = @layout.merge(YAML.load_file(thefile) || {}) #load_file returns false on empty file
|
119
119
|
yml.each do |key, value|
|
120
120
|
@layout[key] = recurse_extends(yml, key, {})
|
121
121
|
end
|
@@ -157,7 +157,7 @@ module Squib
|
|
157
157
|
# :nodoc:
|
158
158
|
# @api private
|
159
159
|
def has_extends?(yml, key)
|
160
|
-
yml[key].key?('extends')
|
160
|
+
!!yml[key] && yml[key].key?('extends')
|
161
161
|
end
|
162
162
|
|
163
163
|
# Safeguard against malformed circular extends
|
@@ -169,6 +169,9 @@ module Squib
|
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
172
|
+
# Use Logger to show more detail on the run
|
173
|
+
# :nodoc:
|
174
|
+
# @api private
|
172
175
|
def show_info(config, layout)
|
173
176
|
Squib::logger.info "Squib v#{Squib::VERSION}"
|
174
177
|
Squib::logger.info " building #{@cards.size} #{@width}x#{@height} cards"
|