squib 0.0.1 → 0.0.2
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 +29 -26
- data/.travis.yml +6 -4
- data/.yardopts +6 -0
- data/API.md +59 -0
- data/Gemfile +2 -2
- data/LICENSE.txt +22 -22
- data/README.md +92 -55
- data/Rakefile +11 -6
- data/bin/squib +19 -2
- data/lib/squib/api/background.rb +16 -11
- data/lib/squib/api/data.rb +52 -29
- data/lib/squib/api/image.rb +48 -10
- data/lib/squib/api/save.rb +36 -15
- data/lib/squib/api/settings.rb +35 -0
- data/lib/squib/api/shapes.rb +106 -12
- data/lib/squib/api/text.rb +45 -25
- data/lib/squib/api/units.rb +17 -0
- data/lib/squib/card.rb +36 -27
- data/lib/squib/commands/new.rb +40 -0
- data/lib/squib/constants.rb +40 -0
- data/lib/squib/deck.rb +113 -48
- data/lib/squib/graphics/background.rb +12 -10
- data/lib/squib/graphics/image.rb +28 -12
- data/lib/squib/graphics/save_doc.rb +50 -21
- data/lib/squib/graphics/save_images.rb +10 -8
- data/lib/squib/graphics/shapes.rb +55 -11
- data/lib/squib/graphics/text.rb +107 -27
- data/lib/squib/input_helpers.rb +140 -0
- data/lib/squib/project_template/.gitignore +3 -0
- data/lib/squib/project_template/ABOUT.md +19 -0
- data/lib/squib/project_template/Gemfile +3 -0
- data/lib/squib/project_template/PNP NOTES.md +4 -0
- data/lib/squib/project_template/_output/gitkeep.txt +1 -0
- data/lib/squib/project_template/config.yml +2 -0
- data/lib/squib/project_template/deck.rb +6 -0
- data/lib/squib/project_template/layout.yml +0 -0
- data/lib/squib/version.rb +6 -3
- data/lib/squib.rb +19 -2
- data/samples/_output/gitkeep.txt +0 -0
- data/samples/basic.rb +20 -22
- data/samples/colors.rb +17 -0
- data/samples/custom-config.yml +1 -0
- data/samples/custom-layout.yml +34 -0
- data/samples/custom_config.rb +6 -0
- data/samples/draw_shapes.rb +19 -0
- data/samples/excel.rb +19 -16
- data/samples/hello_world.rb +7 -0
- data/samples/load_images.rb +19 -0
- data/samples/pokercard.png +0 -0
- data/samples/ranges.rb +47 -0
- data/samples/sample.xlsx +0 -0
- data/samples/save_pdf.rb +14 -0
- data/samples/spanner.svg +91 -0
- data/samples/text_options.rb +58 -0
- data/samples/tgc_proofs.rb +20 -0
- data/samples/units.rb +12 -0
- data/samples/use_layout.rb +29 -0
- data/spec/api/api_text_spec.rb +37 -0
- data/spec/commands/new_spec.rb +48 -0
- data/spec/deck_spec.rb +49 -48
- data/spec/samples_run_spec.rb +15 -0
- data/spec/spec_helper.rb +9 -0
- data/squib.gemspec +42 -27
- metadata +109 -11
- data/samples/_output/watch.html +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bdd8eafb413745ef16bdd12e11696a748ef60ec
|
4
|
+
data.tar.gz: 9fada45fed185c9b847f40b301d2e7283ad9b3ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9b3665709f6d61c13eea918bfd63ec55877baa21d8e4ae056773e12ac6da08729cf0c123af7fc17b32aca28ff81d4d4b99afac45c58f32ec949546ae8840496
|
7
|
+
data.tar.gz: ddde2eead6b96ce895d5c39af1072e1cc36f6590fc17565a4ff6b1e4a6c93001f737b5bc657e5f004360c938b48a00c0b2f6551981a200f25346afab86a38e39
|
data/.gitignore
CHANGED
@@ -1,26 +1,29 @@
|
|
1
|
-
.DS_Store
|
2
|
-
*.gem
|
3
|
-
*.rbc
|
4
|
-
.bundle
|
5
|
-
.config
|
6
|
-
.yardoc
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
test/
|
18
|
-
|
19
|
-
|
20
|
-
*.
|
21
|
-
*.
|
22
|
-
*.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
samples/
|
1
|
+
.DS_Store
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
.yardoc
|
7
|
+
.inch
|
8
|
+
Gemfile.lock
|
9
|
+
InstalledFiles
|
10
|
+
_yardoc
|
11
|
+
coverage
|
12
|
+
doc/
|
13
|
+
lib/bundler/man
|
14
|
+
pkg
|
15
|
+
rdoc
|
16
|
+
spec/reports
|
17
|
+
test/tmp
|
18
|
+
test/version_tmp
|
19
|
+
tmp
|
20
|
+
*.bundle
|
21
|
+
*.so
|
22
|
+
*.o
|
23
|
+
*.a
|
24
|
+
mkmf.log
|
25
|
+
_img
|
26
|
+
samples/_img
|
27
|
+
samples/_output/*.png
|
28
|
+
samples/_output/*.pdf
|
29
|
+
samples/_output/foo
|
data/.travis.yml
CHANGED
data/.yardopts
ADDED
data/API.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Squib API
|
2
|
+
|
3
|
+
The Squib DSL is based on a collection of methods provided to the `Squib::Deck` class. The general philosophy of Squib is to specify as little as possible with layers of defaults, highly flexible input, and good ol' Ruby duck-typing. Ruby does a lot to make Squib useful.
|
4
|
+
|
5
|
+
# Squib::Deck and Squib::Card
|
6
|
+
|
7
|
+
Squib essentially has two main classes: `Deck` and `Card`. `Deck` is the front-end, and `Card` is the back-end. The contract of `Deck` is to do the various manipulations of options and then delegate the operation to `Card` to do the low-level graphical operations.
|
8
|
+
|
9
|
+
For most users, I recommending solely using `Deck` methods. If you want to roll up your sleeves and get your hands messy, you can access the Cairo or Pango contexts the directly via the `Card` class. The API documentation doesn't really cover these, however, so you're on your own there.
|
10
|
+
|
11
|
+
# Specifying Parameters
|
12
|
+
|
13
|
+
Squib is all about sane defaults and shorthand specification. Arguments are almost always using hashes, which look a lot like [Ruby 2.0's named parameters](http://www.ruby-doc.org/core-2.0.0/doc/syntax/calling_methods_rdoc.html#label-Keyword+Arguments). This means you can specify your parameters in any order you please. All parameters are optional. For example `x` and `y` default to 0 (i.e. the upper-left corner of the card). Any parameter that is specified in the command overrides any Squib defaults, `config.yml` settings, or layout rules.
|
14
|
+
|
15
|
+
# Specifying Ranges
|
16
|
+
|
17
|
+
Most public `Deck` methods allow a `range` to be specified as a first parameter. This parameter is used to access an internal `Array` of `Squib::Cards`. This can be an actual Ruby range, or anything that implements `#each` (thus can be an `Enumerable`). Integers are also supported for changing one card only. Negatives work from the back of the deck. Here are some examples from `samples/ranges.rb` found [here](https://github.com/andymeneely/squib/tree/master/samples/ranges.rb)
|
18
|
+
|
19
|
+
{include:file:samples/ranges.rb}
|
20
|
+
|
21
|
+
Many more examples can be found in `ranges.rb` in the [samples](https://github.com/andymeneely/squib/tree/master/samples/) folder . In particular, take a look at some idioms that uses hashes to denote things like card "types", or future-proofing against creating and deleting cards with an ID column.
|
22
|
+
|
23
|
+
# Pixels and Other Units
|
24
|
+
|
25
|
+
By default, Squib thinks in pixels. This decision was made so that we can have pixel-perfect layouts without automatically scaling everything, even though working in units is sometimes easier. To convert, we provide the `Deck#inch` method, as shown in `samples/units.rb` found [here](https://github.com/andymeneely/squib/tree/master/samples/units.rb)
|
26
|
+
|
27
|
+
{include:file:samples/units.rb}
|
28
|
+
|
29
|
+
# Specifying Colors
|
30
|
+
|
31
|
+
Colors can be specified in a wide variety of ways, mostly in a hex-string. Take a look at the examples from `samples/colors.rb`, found [here](https://github.com/andymeneely/squib/tree/master/samples/colors.rb)
|
32
|
+
|
33
|
+
{include:file:samples/colors.rb}
|
34
|
+
|
35
|
+
Under the hood, Squib uses the `rcairo` [color parser](https://github.com/rcairo/rcairo/blob/master/lib/cairo/color.rb) to accept a variety of color specifications, along with over [300 pre-defined constants](https://github.com/rcairo/rcairo/blob/master/lib/cairo/colors.rb).
|
36
|
+
|
37
|
+
# Specifying Files
|
38
|
+
|
39
|
+
All files opened for reading or writing (e.g. for `png` and `xlsx`) are opened relative to the current directory. Files opened for writing (e.g. for `save_png`) will be overwritten without warning.
|
40
|
+
|
41
|
+
# Custom Layouts
|
42
|
+
|
43
|
+
Working with x-y coordinates all the time can be tiresome, and ideally everything in a game prototype should be data-driven and easily changed. For this, many Squib methods allow for a `layout` to be set. In essence, layouts are a way of setting default values for any argument given to the command.
|
44
|
+
|
45
|
+
To use a layout, set the `layout:` option on a `Deck.new` command to point to a YAML file. Any command that allows a `layout` option can be set with a Ruby symbol or String, and the command will then load the specified `x`, `y`, `width`, and `height`. The individual command can also override these options.
|
46
|
+
|
47
|
+
Note: YAML is very finnicky about having tabs in the file. Use two spaces for indentation instead.
|
48
|
+
|
49
|
+
Layouts will override Squib's defaults, but are overriden by anything specified in the command itself. Thus, the order of precedence looks like this:
|
50
|
+
|
51
|
+
* Use what the command specified
|
52
|
+
* If anything was not yet specified, use what was given in a layout (if a layout was specified in the command and the file was given to the Deck)
|
53
|
+
* If still anything was not yet specified, use what was given in Squib's defaults.
|
54
|
+
|
55
|
+
Layouts also allow for a special `extends` field that will copy all of the settings from another entry. Only a single level of extends are supported currently (contact the developer if you want multiple levels).
|
56
|
+
|
57
|
+
See the `use_layout` sample found [here](https://github.com/andymeneely/squib/tree/master/samples/)
|
58
|
+
|
59
|
+
{include:file:samples/use_layout.rb}
|
data/Gemfile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
gemspec
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
Copyright (c) 2014 Andy Meneely
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2014 Andy Meneely
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,55 +1,92 @@
|
|
1
|
-
[](https://rubygems.org/gems/squib)
|
2
|
-
[
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
1
|
+
# Squib [](https://rubygems.org/gems/squib) [](https://travis-ci.org/andymeneely/squib) [](https://gemnasium.com/andymeneely/squib) [](https://coveralls.io/r/andymeneely/squib) [](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 currently supports:
|
3
|
+
|
4
|
+
* Reading PNGs and SVGs using [Cairo](http://cairographics.org/)
|
5
|
+
* Complex text rendering using [Pango](http://www.pango.org/)
|
6
|
+
* Reading `.xlsx` files
|
7
|
+
* Basic shape drawing
|
8
|
+
* Rendering to PNGs and PDFs
|
9
|
+
* Unit conversion
|
10
|
+
* Specfiying your layouts in a YML file
|
11
|
+
* Plus the full power of Ruby!
|
12
|
+
|
13
|
+
Check this out.
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require 'squib'
|
17
|
+
|
18
|
+
Squib::Deck.new do
|
19
|
+
text str: 'Hello, World!'
|
20
|
+
save_png
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
That script just created a deck of with 1 image at 825x1125 with the string "Hello, World" in the upper-left corner.
|
25
|
+
|
26
|
+
## Installation
|
27
|
+
|
28
|
+
Install it yourself with:
|
29
|
+
|
30
|
+
$ gem install squib
|
31
|
+
|
32
|
+
If you're using Bundler, add this line to your application's Gemfile:
|
33
|
+
|
34
|
+
gem 'squib'
|
35
|
+
|
36
|
+
And then execute:
|
37
|
+
|
38
|
+
$ bundle
|
39
|
+
|
40
|
+
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).
|
41
|
+
|
42
|
+
Note: Squib requires Ruby 2.0 or later.
|
43
|
+
|
44
|
+
## Getting Started
|
45
|
+
|
46
|
+
After installing Squib, you can create a project and run your first build like this:
|
47
|
+
|
48
|
+
```sh
|
49
|
+
$ squib new my-cool-game
|
50
|
+
$ cd my-cool-game
|
51
|
+
$ ruby deck.rb
|
52
|
+
```
|
53
|
+
|
54
|
+
The `squib new` command will generate files and folders like this:
|
55
|
+
|
56
|
+
```
|
57
|
+
_output
|
58
|
+
gitkeep.txt
|
59
|
+
.gitignore
|
60
|
+
ABOUT.md
|
61
|
+
config.yml
|
62
|
+
deck.rb
|
63
|
+
Gemfile
|
64
|
+
layout.yml
|
65
|
+
PNP NOTES.md
|
66
|
+
```
|
67
|
+
|
68
|
+
The central file here is `deck.rb`. Here's a basic example of a deck to work from:
|
69
|
+
|
70
|
+
{include:file:samples/basic.rb basic.rb}
|
71
|
+
|
72
|
+
## Learning Squib
|
73
|
+
|
74
|
+
After going over this README, here are some other places to go learn Squib:
|
75
|
+
|
76
|
+
* The YARD-generated API documentation [for the latest Squib gem](http://rubydoc.info/gems/squib/) is a method-by-method reference. I recommend starting with the `API` file, and looking at the `Deck` class. If you are following Squib master, see [the latest version](http://rubydoc.info/github/andymeneely/squib/frames)
|
77
|
+
* The `samples` directory in the [source repository](https://github.com/andymeneely/squib) has lots of examples
|
78
|
+
* Junk Land (link TBD) is my own creation that's uses Squib for both black-and-white print-and-play and full color.
|
79
|
+
|
80
|
+
## Development
|
81
|
+
|
82
|
+
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).
|
83
|
+
|
84
|
+
## Contributing
|
85
|
+
|
86
|
+
Squib is an open source tool, and I would love participation. If you want your code integrated:
|
87
|
+
|
88
|
+
1. Fork it ( https://github.com/[my-github-username]/squib/fork )
|
89
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
90
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
91
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
92
|
+
5. Create a new Pull Request
|
data/Rakefile
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
-
require 'bundler/gem_tasks'
|
2
|
-
require 'rspec/core/rake_task'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
task :default => :spec
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'yard'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
task :default => [:install, :spec]
|
7
|
+
|
8
|
+
YARD::Rake::YardocTask.new(:doc) do |t|
|
9
|
+
t.files = ['lib/**/*.rb', 'samples/**/*.rb'] # optional
|
10
|
+
#t.options = ['--any', '--extra', '--opts'] # optional
|
11
|
+
end
|
data/bin/squib
CHANGED
@@ -1,2 +1,19 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'squib'
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'squib'
|
3
|
+
require 'mercenary'
|
4
|
+
|
5
|
+
Mercenary.program(:squib) do |p|
|
6
|
+
p.version Squib::VERSION
|
7
|
+
p.description "A Ruby DSL for prototyping card games"
|
8
|
+
p.syntax "squib <subcommand> [options]"
|
9
|
+
|
10
|
+
p.command(:new) do |c|
|
11
|
+
c.syntax "new PATH"
|
12
|
+
c.description "Creates a new Squib project scaffolding in PATH. Must be a new directory or already empty."
|
13
|
+
|
14
|
+
c.action do |args, options|
|
15
|
+
Squib::Commands::New.new.process(args)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/lib/squib/api/background.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
-
module Squib
|
2
|
-
class Deck
|
3
|
-
#
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
#
|
11
|
-
|
1
|
+
module Squib
|
2
|
+
class Deck
|
3
|
+
# Fills the background with the given color
|
4
|
+
# @example
|
5
|
+
# background color: :white
|
6
|
+
#
|
7
|
+
# @option range [Enumerable] (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
|
8
|
+
# @option color [String] (:black) the color the font will render to. See {file:API.md#label-Specifying+Colors Specifying Colors}
|
9
|
+
# @return [nil] nothing
|
10
|
+
# @api public
|
11
|
+
def background(opts = {})
|
12
|
+
opts = needs(opts,[:range, :color])
|
13
|
+
opts[:range].each { |i| @cards[i].background(opts[:color]) }
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
12
17
|
end
|
data/lib/squib/api/data.rb
CHANGED
@@ -1,29 +1,52 @@
|
|
1
|
-
require 'roo'
|
2
|
-
|
3
|
-
module Squib
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
1
|
+
require 'roo'
|
2
|
+
|
3
|
+
module Squib
|
4
|
+
|
5
|
+
# Pulls Excel data from `.xlsx` files into a column-based hash
|
6
|
+
#
|
7
|
+
# Pulls the data into a Hash of arrays based on the columns. First row is assumed to be the header row.
|
8
|
+
# See the example `samples/excel.rb` in the [source repository](https://github.com/andymeneely/squib/tree/master/samples)
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# # Excel file looks like this:
|
12
|
+
# # | h1 | h2 |
|
13
|
+
# # ------------
|
14
|
+
# # | 1 | 2 |
|
15
|
+
# # | 3 | 4 |
|
16
|
+
# data = xlsx file: 'data.xlsx', sheet: 0
|
17
|
+
# {'h1' => [1,3], 'h2' => [2,4]}
|
18
|
+
#
|
19
|
+
# @option opts file [String] the file to open. Must end in `.xlsx`. Opens relative to the current directory.
|
20
|
+
# @option opts sheet [Integer] (0) The zero-based index of the sheet from which to read.
|
21
|
+
# @return [Hash] a hash of arrays based on columns in the spreadsheet
|
22
|
+
# @api public
|
23
|
+
def xlsx(opts = {})
|
24
|
+
opts = Squib::SYSTEM_DEFAULTS.merge(opts)
|
25
|
+
opts = Squib::InputHelpers.fileify(opts)
|
26
|
+
s = Roo::Excelx.new(opts[:file])
|
27
|
+
s.default_sheet = s.sheets[opts[:sheet]]
|
28
|
+
data = {}
|
29
|
+
s.first_column.upto(s.last_column) do |col|
|
30
|
+
header = s.cell(s.first_row,col).to_s
|
31
|
+
data[header] = []
|
32
|
+
(s.first_row+1).upto(s.last_row) do |row|
|
33
|
+
cell = s.cell(row,col)
|
34
|
+
# Roo hack for avoiding unnecessary .0's on whole integers
|
35
|
+
cell = s.excelx_value(row,col) if s.excelx_type(row,col) == [:numeric_or_formula, "General"]
|
36
|
+
data[header] << cell
|
37
|
+
end#row
|
38
|
+
end#col
|
39
|
+
data
|
40
|
+
end#xlsx
|
41
|
+
module_function :xlsx
|
42
|
+
|
43
|
+
class Deck
|
44
|
+
|
45
|
+
# Convenience call for Squib.xlsx
|
46
|
+
def xlsx(opts = {})
|
47
|
+
Squib.xlsx(opts)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
data/lib/squib/api/image.rb
CHANGED
@@ -1,11 +1,49 @@
|
|
1
|
-
module Squib
|
2
|
-
class Deck
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
module Squib
|
2
|
+
class Deck
|
3
|
+
|
4
|
+
# Renders a png file at the given location.
|
5
|
+
#
|
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
|
+
# @example
|
9
|
+
# png file: 'img.png', x: 50, y: 50
|
10
|
+
#
|
11
|
+
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
|
12
|
+
# @option opts file [String, Array] ('') 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. See {file:API.md#Specifying+Files Specifying Files}
|
13
|
+
# @option opts x [Integer] (0) the x-coordinate to place
|
14
|
+
# @option opts y [Integer] (0) the y-coordinate to place
|
15
|
+
# @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:API.md#label-Custom+Layouts Custom Layouts}
|
16
|
+
# @option opts alpha [Decimal] (1.0) the alpha-transparency percentage used to blend this image
|
17
|
+
# @return [nil] Returns nil
|
18
|
+
# @api public
|
19
|
+
def png(opts = {})
|
20
|
+
opts = needs(opts, [:range, :files, :x, :y, :alpha, :layout])
|
21
|
+
opts[:range].each do |i|
|
22
|
+
@cards[i].png(opts[:file][i], opts[:x], opts[:y], opts[:alpha])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Renders an entire svg file at the given location. Uses the SVG-specified units and DPI to determine the pixel width and height.
|
27
|
+
#
|
28
|
+
# See {file:samples/load-images.rb samples/load-images.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
|
29
|
+
# @example
|
30
|
+
# svg 1..2, 'icon.svg', '#stone', x: 50, y:50
|
31
|
+
#
|
32
|
+
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
|
33
|
+
# @option opts file [String, Array] ('') 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. See {file:API.md#Specifying+Files Specifying Files}
|
34
|
+
# @option opts x [Integer] (0) the x-coordinate to place
|
35
|
+
# @option opts y [Integer] (0) the y-coordinate to place
|
36
|
+
# @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.
|
37
|
+
# @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.
|
38
|
+
# @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:API.md#label-Custom+Layouts Custom Layouts}
|
39
|
+
# @return [nil] Returns nil
|
40
|
+
# @api public
|
41
|
+
def svg(opts = {})
|
42
|
+
p = needs(opts,[:range, :files, :svgid, :x, :y, :width, :height, :layout])
|
43
|
+
p[:range].each do |i|
|
44
|
+
@cards[i].svg(p[:file][i], p[:id], p[:x], p[:y], p[:width], p[:height])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
11
49
|
end
|
data/lib/squib/api/save.rb
CHANGED
@@ -1,16 +1,37 @@
|
|
1
|
-
module Squib
|
2
|
-
class Deck
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
1
|
+
module Squib
|
2
|
+
class Deck
|
3
|
+
|
4
|
+
# Saves the given range of cards to either PNG or PDF
|
5
|
+
#
|
6
|
+
# @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
|
7
|
+
# @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist.
|
8
|
+
# @option opts [Symbol] format (:png) the format that this will be rendered too. Options `:pdf, :png`. Array of both is allowed: `[:pdf, :png]`
|
9
|
+
# @option opts [String] prefix (card_) the prefix of the file name to be printed
|
10
|
+
# @return self
|
11
|
+
# @api public
|
12
|
+
def save(opts = {})
|
13
|
+
opts = needs(opts, [:range, :creatable_dir, :formats, :prefix])
|
14
|
+
save_png(opts) if opts[:format].include? :png
|
15
|
+
save_pdf(opts) if opts[:format].include? :pdf
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
# Saves the given range of cards to a PNG
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# save range: 1..8, dir: '_pnp', prefix: 'bw_'
|
23
|
+
#
|
24
|
+
# @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
|
25
|
+
# @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist.
|
26
|
+
# @option opts [String] prefix (card_) the prefix of the file name to be printed.
|
27
|
+
# @return [nil] Returns nothing
|
28
|
+
# @api public
|
29
|
+
def save_png(opts = {})
|
30
|
+
opts = needs(opts,[:range, :creatable_dir, :prefix])
|
31
|
+
opts[:range].each do |i|
|
32
|
+
@cards[i].save_png(i, opts[:dir], opts[:prefix])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
16
37
|
end
|