squib 0.14.3.pre1 → 0.16.0.pre.preview1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +22 -0
- data/CHANGELOG.md +58 -2
- data/Dockerfile +27 -0
- data/Guardfile +8 -0
- data/README.md +24 -6
- data/RELEASE TODO.md +1 -0
- data/Rakefile +3 -0
- data/lib/squib.rb +3 -1
- data/lib/squib/args/arg_loader.rb +109 -106
- data/lib/squib/args/box.rb +52 -48
- data/lib/squib/args/card_range.rb +26 -24
- data/lib/squib/args/color_validator.rb +4 -9
- data/lib/squib/args/coords.rb +39 -25
- data/lib/squib/args/csv_opts.rb +13 -16
- data/lib/squib/args/dir_validator.rb +7 -12
- data/lib/squib/args/draw.rb +69 -68
- data/lib/squib/args/embed_adjust.rb +12 -15
- data/lib/squib/args/embed_key.rb +6 -11
- data/lib/squib/args/hand_special.rb +25 -25
- data/lib/squib/args/import.rb +54 -27
- data/lib/squib/args/input_file.rb +22 -26
- data/lib/squib/args/paint.rb +30 -31
- data/lib/squib/args/paragraph.rb +95 -93
- data/lib/squib/args/save_batch.rb +50 -48
- data/lib/squib/args/scale_box.rb +43 -39
- data/lib/squib/args/sheet.rb +147 -149
- data/lib/squib/args/showcase_special.rb +32 -29
- data/lib/squib/args/sprue_file.rb +30 -30
- data/lib/squib/args/svg_special.rb +26 -26
- data/lib/squib/args/transform.rb +48 -54
- data/lib/squib/args/typographer.rb +88 -92
- data/lib/squib/args/unit_conversion.rb +6 -8
- data/lib/squib/args/xywh_shorthands.rb +56 -0
- data/lib/squib/builtin/projects/advanced/config.yml +3 -6
- data/lib/squib/builtin/projects/basic/config.yml +3 -6
- data/lib/squib/commands/make_sprue.rb +2 -0
- data/lib/squib/conf.rb +5 -5
- data/lib/squib/deck.rb +34 -12
- data/lib/squib/dsl/background.rb +35 -0
- data/lib/squib/dsl/circle.rb +39 -0
- data/lib/squib/dsl/csv.rb +42 -0
- data/lib/squib/dsl/curve.rb +35 -0
- data/lib/squib/dsl/cut_zone.rb +47 -0
- data/lib/squib/dsl/ellipse.rb +37 -0
- data/lib/squib/dsl/grid.rb +35 -0
- data/lib/squib/{api → dsl}/groups.rb +0 -0
- data/lib/squib/dsl/hand.rb +42 -0
- data/lib/squib/dsl/line.rb +35 -0
- data/lib/squib/dsl/png.rb +56 -0
- data/lib/squib/dsl/polygon.rb +36 -0
- data/lib/squib/dsl/rect.rb +37 -0
- data/lib/squib/dsl/safe_zone.rb +48 -0
- data/lib/squib/dsl/save.rb +21 -0
- data/lib/squib/dsl/save_pdf.rb +50 -0
- data/lib/squib/dsl/save_png.rb +47 -0
- data/lib/squib/dsl/save_sheet.rb +53 -0
- data/lib/squib/dsl/showcase.rb +43 -0
- data/lib/squib/dsl/star.rb +37 -0
- data/lib/squib/dsl/svg.rb +62 -0
- data/lib/squib/dsl/text.rb +54 -0
- data/lib/squib/dsl/text_embed.rb +78 -0
- data/lib/squib/dsl/triangle.rb +35 -0
- data/lib/squib/{api → dsl}/units.rb +10 -0
- data/lib/squib/dsl/xlsx.rb +40 -0
- data/lib/squib/dsl/yaml.rb +40 -0
- data/lib/squib/errors_warnings/warn_unexpected_params.rb +14 -0
- data/lib/squib/graphics/cairo_context_wrapper.rb +2 -2
- data/lib/squib/graphics/image.rb +0 -6
- data/lib/squib/graphics/save_images.rb +3 -3
- data/lib/squib/graphics/save_sprue.rb +39 -12
- data/lib/squib/graphics/showcase.rb +1 -1
- data/lib/squib/graphics/text.rb +37 -9
- data/lib/squib/import/csv_importer.rb +45 -0
- data/lib/squib/import/quantity_exploder.rb +18 -0
- data/lib/squib/import/xlsx_importer.rb +28 -0
- data/lib/squib/import/yaml_importer.rb +30 -0
- data/lib/squib/layout_parser.rb +24 -7
- data/lib/squib/sprues/crop_line.rb +6 -6
- data/lib/squib/sprues/crop_line_dash.rb +6 -6
- data/lib/squib/sprues/sprue.rb +19 -14
- data/lib/squib/sprues/sprue_schema.rb +4 -2
- data/lib/squib/version.rb +1 -1
- data/samples/autoscale_font/_autoscale_font.rb +77 -8
- data/samples/colors/_colors.rb +11 -5
- data/samples/colors/_switch_color.rb +33 -0
- data/samples/data/_excel.rb +1 -1
- data/samples/images/_more_load_images.rb +1 -1
- data/samples/ranges/_ranges.rb +1 -1
- data/samples/saves/_save_filenames.rb +28 -0
- data/samples/saves/_save_pdf.rb +1 -1
- data/samples/saves/_saves.rb +2 -1
- data/samples/shapes/_draw_shapes.rb +2 -2
- data/samples/sprues/_advanced_sprues.rb +4 -3
- data/samples/sprues/_builtin_sprues.rb +1 -0
- data/samples/sprues/_fold_sheet.rb +4 -1
- data/samples/text/_text.rb +6 -1
- data/samples/text/_text_options.rb +2 -1
- data/samples/units/_cells.rb +51 -0
- data/samples/units/_shorthands.rb +49 -0
- data/samples/units/_units.rb +7 -0
- data/squib.gemspec +19 -13
- metadata +151 -61
- data/.travis.yml +0 -19
- data/appveyor.yml +0 -24
- data/lib/squib/api/background.rb +0 -15
- data/lib/squib/api/data.rb +0 -137
- data/lib/squib/api/image.rb +0 -49
- data/lib/squib/api/save.rb +0 -83
- data/lib/squib/api/shapes.rb +0 -124
- data/lib/squib/api/text.rb +0 -25
- data/lib/squib/api/text_embed.rb +0 -71
- data/samples/bug256/_bug256.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24cc3f2b97503042d0ad1a0db003e8cb585e4853389c78b49c54c036f45bf4e2
|
4
|
+
data.tar.gz: aa49287f4fa01039f4ea8737e862d24637ba47142d84849e54335b44b00f4424
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 529665761713e33f8743356a90af15ab244e8e09ffbb4836d1aa3dd1e0398cba320ffb0e443aff355cc71604146f03865b413c3307a76d372860a07b35a8bb2b
|
7
|
+
data.tar.gz: 0fe62d7d34630c98c2750e5da46d4fd5633692f6f5cab22248b4650e6f8bfa2964ac0c107f5efd847c44342ad7b2ccf41634719b6c6cf84a55154ca1bcaba405
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Squib Unit Tests
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
strategy:
|
8
|
+
fail-fast: false
|
9
|
+
matrix:
|
10
|
+
os: [ubuntu, macos]
|
11
|
+
ruby: [2.5, 2.6, 2.7, head]
|
12
|
+
runs-on: ${{ matrix.os }}-latest
|
13
|
+
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v2
|
16
|
+
- uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: ${{ matrix.ruby }}
|
19
|
+
# bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
20
|
+
- run: ruby --version # explicitly show the ruby version
|
21
|
+
- run: bundle install
|
22
|
+
- run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -1,16 +1,72 @@
|
|
1
1
|
# Squib CHANGELOG
|
2
2
|
Squib follows [semantic versioning](http://semver.org).
|
3
3
|
|
4
|
-
## v0.
|
4
|
+
## v0.16.0 / Unreleased
|
5
|
+
|
6
|
+
Features:
|
7
|
+
* Special custom unit: cells. A "cell" defaults to 37.5px, or 1/8in, e.g. `x: '1 cell'` means `x: 37.5`. See the docs for details.
|
8
|
+
* Shorthands for `x`, `y`, `width`, and `height`! The words `x: 'middle'` and `x: 'middle + 1in'` will get interpreted. See the docs for details.
|
9
|
+
* Autoscaling text! `ellipsize: :autoscale` will now downscale your `font_size` if the text ellipsized. Thanks @Qgel! (#288, #111).
|
10
|
+
* Option checking!! Completely reworked the way we handle arguments in Squib internally (no external behavioral differences). Now, when you give an option to Squib that is not expected. Since every DSL method "knows" what options it takes, that also means we have EVERY option properly documented (missed a few...) AND we have an automated test that will tell us if we forget to document it.
|
11
|
+
* `save_png` and `save_sheet` now have a `suffix` option which defaults to `''`. So now you can customize the filenames with `prefix`, `count_format`, and `suffix`.
|
12
|
+
|
13
|
+
Compatibility:
|
14
|
+
* When saving PNGs with sprues, outputs start counting at zero - which is more consistent with the rest of Squib.
|
15
|
+
* Minimum Ruby is now 2.5. NOTE: Ruby 3.0 is coming Christmas 2020!! Check it out.
|
16
|
+
|
17
|
+
Bugs:
|
18
|
+
* Extra page/no page issue with sprues (#320)
|
19
|
+
* Fix Ruby 2.7+ deprecations with CSV arguments (#303)
|
20
|
+
|
21
|
+
Chores:
|
22
|
+
* Reorganized the code internally. (#298) Every DSL method now has its own file.
|
23
|
+
* Moved to Github Actions
|
24
|
+
* Bump pango et al
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
## v0.15.3 / 2019-10-17
|
29
|
+
|
30
|
+
Chores:
|
31
|
+
* Bump pango et al to `~> 3.4`, cairo to `~ 1.16`. Fixes Ruby 2.6 Windows install issues (#287)
|
32
|
+
|
33
|
+
## v0.15.2 / 2019-09-26
|
34
|
+
|
35
|
+
Chores:
|
36
|
+
* Bump nokogiri to 1.10.4
|
37
|
+
|
38
|
+
|
39
|
+
## v0.15.1 / 2019-08-27
|
40
|
+
|
41
|
+
Chores:
|
42
|
+
* Bumped Pango et al. to 3.3.7 (#286)
|
43
|
+
|
44
|
+
## v0.15.0 / 2019-08-06
|
5
45
|
|
6
46
|
Features:
|
7
47
|
* Added check for malformed PNG files (#250, #218)
|
48
|
+
* Sprues: you can now flip individual cards (#251)
|
49
|
+
|
50
|
+
Bugs
|
51
|
+
* `trim_radius` now defaults to 0 on `save_pdf`, not 38. (#270)
|
52
|
+
* `explode` on `xlsx` and `csv` now defaults to `qty`, not `Qty` (#262)
|
8
53
|
|
9
54
|
Docs:
|
10
55
|
* Documented the n-sided-ness of polygons and stars
|
11
56
|
* svg: document rasterization on mask (#192)
|
57
|
+
* Document how to run the code (#186)
|
58
|
+
* Document some ways of using `prefix` in `save_png` (#268)
|
59
|
+
* `showcase` option `trim_radius` defaults to 38, not 0
|
60
|
+
* Add sample for color switch in colors docs (#274)
|
61
|
+
|
62
|
+
Chores:
|
63
|
+
* Bumped deps: Pango et al. to 3.3.6, Cairo to 1.16.4, Nokogiri to 1.10.3, Highline to 2.0.2
|
64
|
+
|
65
|
+
Compatibility:
|
66
|
+
* A LOT more pre-defined colors built into Cairo. Some of the named colors got redefined with the upgrade to the latest Cairo. This means that named colors like `:gray` and `:green` may look slightly different.
|
67
|
+
* Dropped support for EOL'd Rubies. Minimum support is 2.4
|
12
68
|
|
13
|
-
Special thanks to @lcarlsen
|
69
|
+
Special thanks to @lcarlsen, @Karneades
|
14
70
|
|
15
71
|
## v0.14.2 / 2018-08-01
|
16
72
|
|
data/Dockerfile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# This is the official Squib Docker image.
|
2
|
+
#
|
3
|
+
FROM ruby:2.7-slim
|
4
|
+
WORKDIR /usr/src/app
|
5
|
+
|
6
|
+
LABEL org.squib.url=http://squib.rocks \
|
7
|
+
org.squib.github=https://github.com/andymeneely/squib
|
8
|
+
|
9
|
+
RUN apt-get update && \
|
10
|
+
apt-get install -y \
|
11
|
+
libgirepository1.0-dev \
|
12
|
+
build-essential \
|
13
|
+
ruby-dev \
|
14
|
+
ruby \
|
15
|
+
ruby-gdk-pixbuf2 \
|
16
|
+
git \
|
17
|
+
fonts-open-sans
|
18
|
+
|
19
|
+
# Build the current directory of Squib
|
20
|
+
COPY . /usr/src/app
|
21
|
+
RUN rm -f /usr/src/app/Gemfile.lock
|
22
|
+
RUN gem install bundler
|
23
|
+
RUN bundle install
|
24
|
+
RUN bundle exec rake install
|
25
|
+
|
26
|
+
# ENTRYPOINT [ "sh" ]
|
27
|
+
|
data/Guardfile
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Squib [](https://rubygems.org/gems/squib) [](https://travis-ci.org/andymeneely/squib) [](https://ci.appveyor.com/project/andymeneely/squib/branch/master) [](https://coveralls.io/r/andymeneely/squib) [](http://squib.readthedocs.io/en/latest/?badge=latest) [](https://rubygems.org/gems/squib) [](https://travis-ci.org/andymeneely/squib) [](https://ci.appveyor.com/project/andymeneely/squib/branch/master) [](https://coveralls.io/r/andymeneely/squib) [](http://squib.readthedocs.io/en/latest/?badge=latest) [](https://boardgamegeek.com/guild/2601)
|
2
2
|
|
3
3
|
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, then 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:
|
4
4
|
|
@@ -31,7 +31,7 @@ Wanna see more? Check out the website: http://andymeneely.github.io/squib/
|
|
31
31
|
|
32
32
|
## Installation
|
33
33
|
|
34
|
-
Squib requires Ruby 2.
|
34
|
+
Squib requires Ruby 2.5 or later.
|
35
35
|
|
36
36
|
Install it yourself with:
|
37
37
|
|
@@ -85,7 +85,7 @@ Go [read the docs!](http://squib.readthedocs.org/)
|
|
85
85
|
|
86
86
|
Also:
|
87
87
|
* The `samples` directory in the [source repository](https://github.com/andymeneely/squib) has lots of examples.
|
88
|
-
* [
|
88
|
+
* [Masters of the Heist](http://mastersoftheheist.com) is my own creation, and it was made with Squib. Go through the repository and watch how it evolved!
|
89
89
|
* [Junk Land](https://github.com/andymeneely/junk-land) is my own creation that's uses Squib for full-color rendering, and makes use of Ruby in a lot of interesting ways. The port is still in process.
|
90
90
|
* [Project Spider Monkey](https://github.com/andymeneely/project-spider-monkey) is another of my own creations. This one was started from scratch with Squib, but it's still in its early stages.
|
91
91
|
|
@@ -99,12 +99,30 @@ Squib tries to keep you DRY (Don't Repeat Yourself) with the following features:
|
|
99
99
|
* Custom colors keep you from hardcoding magic color strings everywhere. Custom colors go into `config.yml` file.
|
100
100
|
* Plus, you know, Ruby.
|
101
101
|
|
102
|
-
## SublimeText
|
103
102
|
|
104
|
-
|
103
|
+
## Docker
|
105
104
|
|
106
|
-
|
105
|
+
Want to run in a controlled environment? We've got a [Docker image on DockerHub](https://cloud.docker.com/u/andymeneely/repository/docker/andymeneely/squib)
|
107
106
|
|
107
|
+
Here's one way to run it. On the command line, go to the root of your repository. With these commands, we'll map the current directory to the `/usr/src/app` directory in the Docker image. When squib-in-docker read & writes files from there, it'll write it back out to your current directory.
|
108
|
+
|
109
|
+
Assuming you have a script called hello.rb:
|
110
|
+
|
111
|
+
On Windows:
|
112
|
+
|
113
|
+
```
|
114
|
+
docker run --rm -v "%cd%":/usr/src/app andymeneely/squib ruby hello.rb
|
115
|
+
```
|
116
|
+
|
117
|
+
On Macs:
|
118
|
+
|
119
|
+
```
|
120
|
+
docker run --rm -v "$PWD":/usr/src/app andymeneely/squib ruby hello.rb
|
121
|
+
```
|
122
|
+
|
123
|
+
This will create a folder called `_output` in your current directory and write the output of the script there.
|
124
|
+
|
125
|
+
We're still working on ways to customize your own Docker build (e.g. document building, custom fonts, etc.) with your own Dockerfile. Pull requests and ideas welcome!
|
108
126
|
|
109
127
|
|
110
128
|
# Get Help and Give Help
|
data/RELEASE TODO.md
CHANGED
@@ -15,6 +15,7 @@ Be sure to remember to do the following for releases. (Copy into a GitHub issue)
|
|
15
15
|
- [ ] Push master and release branches
|
16
16
|
- [ ] Create GitHub release tag
|
17
17
|
- [ ] `gem push pkg/squib-x.y.z.gem`
|
18
|
+
- [ ] `gem push --key github --host https://rubygems.pkg.github.com/andymeneely pkg/squib-x.y.z.gem`
|
18
19
|
- [ ] Github milestone closed
|
19
20
|
- [ ] Activate version on squib.readthedocs.org
|
20
21
|
- [ ] Bump version.rb to the next alpha
|
data/Rakefile
CHANGED
data/lib/squib.rb
CHANGED
@@ -2,12 +2,14 @@ require 'logger'
|
|
2
2
|
require 'cairo'
|
3
3
|
require 'pango'
|
4
4
|
require 'rsvg2'
|
5
|
+
require 'rainbow/refinement'
|
5
6
|
require_relative 'squib/version'
|
6
7
|
require_relative 'squib/commands/cli'
|
7
8
|
require_relative 'squib/deck'
|
8
9
|
require_relative 'squib/card'
|
9
10
|
|
10
11
|
module Squib
|
12
|
+
using Rainbow # we can colorize strings now!
|
11
13
|
|
12
14
|
# Access the internal logger that Squib uses. By default, Squib configure the logger to the WARN level
|
13
15
|
# Use this to suppress or increase output levels.
|
@@ -22,7 +24,7 @@ module Squib
|
|
22
24
|
@logger = Logger.new($stdout)
|
23
25
|
@logger.level = Logger::WARN
|
24
26
|
@logger.formatter = proc do |severity, datetime, m_progname, msg|
|
25
|
-
"#{datetime} #{severity}
|
27
|
+
"[#{datetime.strftime('%F %H:%M:%S')} #{severity.red}] #{msg}\n"
|
26
28
|
end
|
27
29
|
end
|
28
30
|
@logger
|
@@ -2,125 +2,128 @@ require_relative '../constants'
|
|
2
2
|
require_relative '../conf'
|
3
3
|
require 'ostruct'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
# Intended to be used a a mix-in,
|
6
|
+
# For example use see Box as an example
|
7
|
+
module Squib::Args::ArgLoader
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
# wrapper for compatibility
|
10
|
+
def extract!(args, deck)
|
11
|
+
@deck = deck
|
12
|
+
load!(args,
|
13
|
+
expand_by: deck.size,
|
14
|
+
layout: deck.layout,
|
15
|
+
dpi: deck.dpi,
|
16
|
+
cell_px: deck.cell_px)
|
17
|
+
end
|
12
18
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
# Main class invoked by the client (i.e. dsl/ methods)
|
20
|
+
def load!(args, expand_by: 1, layout: {}, dpi: 300, cell_px: 37.5)
|
21
|
+
@dpi = dpi
|
22
|
+
@cell_px = cell_px
|
23
|
+
args[:layout] = prep_layout_args(args[:layout], expand_by: expand_by)
|
24
|
+
expand_and_set_and_defaultify(args: args, by: expand_by, layout: layout)
|
25
|
+
validate
|
26
|
+
convert_units dpi: dpi, cell_px: cell_px
|
27
|
+
self
|
28
|
+
end
|
23
29
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
def expand_and_set_and_defaultify(args: {}, by: 1, layout: {})
|
31
|
+
attributes = self.class.parameters.keys
|
32
|
+
attributes.each do |p|
|
33
|
+
args[p] = defaultify(p, args, layout)
|
34
|
+
val = if expandable_singleton?(p, args[p])
|
35
|
+
[args[p]] * by
|
36
|
+
else
|
37
|
+
args[p] # not an expanding parameter
|
38
|
+
end
|
39
|
+
instance_variable_set "@#{p}", val
|
40
|
+
end
|
41
|
+
self.class.class_eval { attr_reader *(attributes) }
|
42
|
+
end
|
37
43
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
+
# Must be:
|
45
|
+
# (a) an expanding parameter, and
|
46
|
+
# (b) a singleton already (i.e. doesn't respond to :each)
|
47
|
+
def expandable_singleton?(p, arg)
|
48
|
+
self.class.expanding_parameters.include?(p) && !arg.respond_to?(:each)
|
49
|
+
end
|
44
50
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
end
|
62
|
-
if layout[layout_arg.to_s].key?(p.to_s)
|
63
|
-
layout[layout_arg.to_s][p.to_s] # param specified in layout
|
64
|
-
else
|
65
|
-
defaults[p] # layout specified, but not this param
|
66
|
-
end
|
67
|
-
end
|
51
|
+
# Incorporate defaults and layouts
|
52
|
+
# (1) Use whatever is specified if it is
|
53
|
+
# (2) Go over all layout specifications (if any) and look them up
|
54
|
+
# - Use layout when it's specified for that card
|
55
|
+
# - Use "default" if no layout was specified, or the layout itself did not specify
|
56
|
+
# Defaut can be overriden for a given dsl method (@dsl_method_defaults)
|
57
|
+
# (e.g stroke width is 0.0 for text, non-zero everywhere else)
|
58
|
+
#
|
59
|
+
def defaultify(p, args, layout)
|
60
|
+
return args[p] if args.key? p # arg was specified, no defaults used
|
61
|
+
defaults = self.class.parameters.merge(@dsl_method_defaults || {})
|
62
|
+
args[:layout].map do |layout_arg|
|
63
|
+
return defaults[p] if layout_arg.nil? # no layout specified, use default
|
64
|
+
unless layout.key? layout_arg.to_s # specified a layout, but it doesn't exist in layout. Oops!
|
65
|
+
Squib.logger.warn("Layout \"#{layout_arg.to_s}\" does not exist in layout file - using default instead")
|
66
|
+
return defaults[p]
|
68
67
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
unless layout_args.respond_to?(:each)
|
74
|
-
layout_args = [layout_args] * expand_by
|
75
|
-
end
|
76
|
-
layout_args || []
|
77
|
-
end
|
78
|
-
|
79
|
-
# For each parameter/attribute foo we try to invoke a validate_foo
|
80
|
-
def validate
|
81
|
-
self.class.parameters.each do |param, default|
|
82
|
-
method = "validate_#{param}"
|
83
|
-
if self.respond_to? method
|
84
|
-
attribute = "@#{param}"
|
85
|
-
val = instance_variable_get(attribute)
|
86
|
-
if val.respond_to? :each
|
87
|
-
new_val = val.map.with_index{ |v, i| send(method, v, i) }
|
88
|
-
instance_variable_set(attribute, new_val)
|
89
|
-
else
|
90
|
-
instance_variable_set(attribute, send(method, val))
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
68
|
+
if layout[layout_arg.to_s].key?(p.to_s)
|
69
|
+
layout[layout_arg.to_s][p.to_s] # param specified in layout
|
70
|
+
else
|
71
|
+
defaults[p] # layout specified, but not this param
|
94
72
|
end
|
73
|
+
end
|
74
|
+
end
|
95
75
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
105
|
-
card_arg
|
106
|
-
end
|
76
|
+
# Do singleton expansion on the layout argument as well
|
77
|
+
# Treated differently since layout is not always specified
|
78
|
+
def prep_layout_args(layout_args, expand_by: 1)
|
79
|
+
unless layout_args.respond_to?(:each)
|
80
|
+
layout_args = [layout_args] * expand_by
|
81
|
+
end
|
82
|
+
layout_args || []
|
83
|
+
end
|
107
84
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
85
|
+
# For each parameter/attribute foo we try to invoke a validate_foo
|
86
|
+
def validate
|
87
|
+
self.class.parameters.each do |param, default|
|
88
|
+
method = "validate_#{param}"
|
89
|
+
if self.respond_to? method
|
90
|
+
attribute = "@#{param}"
|
91
|
+
val = instance_variable_get(attribute)
|
92
|
+
if val.respond_to? :each
|
93
|
+
new_val = val.map.with_index{ |v, i| send(method, v, i) }
|
94
|
+
instance_variable_set(attribute, new_val)
|
95
|
+
else
|
96
|
+
instance_variable_set(attribute, send(method, val))
|
119
97
|
end
|
120
|
-
self
|
121
98
|
end
|
99
|
+
end
|
100
|
+
end
|
122
101
|
|
102
|
+
# Access an individual arg for a given card
|
103
|
+
# @return an OpenStruct that looks just like the mixed-in class
|
104
|
+
# @api private
|
105
|
+
def [](i)
|
106
|
+
card_arg = OpenStruct.new
|
107
|
+
self.class.expanding_parameters.each do |p|
|
108
|
+
p_val = instance_variable_get("@#{p}")
|
109
|
+
card_arg[p] = p_val[i]
|
123
110
|
end
|
111
|
+
card_arg
|
112
|
+
end
|
124
113
|
|
114
|
+
# Convert units
|
115
|
+
def convert_units(dpi: 300, cell_px: 37.5)
|
116
|
+
self.class.params_with_units.each do |p|
|
117
|
+
p_str = "@#{p}"
|
118
|
+
p_val = instance_variable_get(p_str)
|
119
|
+
if p_val.respond_to? :each
|
120
|
+
arr = p_val.map { |x| Squib::Args::UnitConversion.parse(x, dpi, cell_px) }
|
121
|
+
instance_variable_set p_str, arr
|
122
|
+
else
|
123
|
+
instance_variable_set p_str, Squib::Args::UnitConversion.parse(p_val, dpi, cell_px)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
self
|
125
127
|
end
|
128
|
+
|
126
129
|
end
|