squib 0.15.3 → 0.17.0
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 +35 -1
- data/Dockerfile +18 -16
- data/Guardfile +8 -0
- data/README.md +3 -9
- data/RELEASE TODO.md +4 -2
- data/Rakefile +3 -0
- data/lib/squib.rb +5 -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/drop_shadow.rb +39 -0
- 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 +142 -149
- data/lib/squib/args/showcase_special.rb +32 -32
- 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 +51 -0
- data/lib/squib/builtin/projects/advanced/config.yml +4 -3
- data/lib/squib/builtin/projects/basic/config.yml +4 -3
- data/lib/squib/conf.rb +5 -0
- 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 +48 -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 +8 -6
- data/lib/squib/graphics/save_images.rb +54 -15
- data/lib/squib/graphics/save_sprue.rb +14 -2
- 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 +16 -14
- data/lib/squib/system_fonts.rb +17 -0
- data/lib/squib/version.rb +2 -1
- data/samples/autoscale_font/_autoscale_font.rb +77 -8
- data/samples/colors/_switch_color.rb +2 -2
- data/samples/data/_excel.rb +1 -1
- data/samples/ranges/_ranges.rb +1 -1
- data/samples/saves/_save_filenames.rb +4 -0
- data/samples/saves/_save_pdf.rb +1 -1
- data/samples/saves/_saves.rb +12 -1
- data/samples/shadows/_shadow.rb +72 -0
- data/samples/shapes/_draw_shapes.rb +2 -2
- data/samples/sprues/_builtin_sprues.rb +1 -0
- data/samples/sprues/_fold_sheet.rb +4 -1
- data/samples/system_font_debug/_list_fonts.rb +14 -0
- 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 +48 -0
- data/samples/units/_units.rb +7 -0
- data/squib.gemspec +14 -8
- metadata +134 -39
- data/.travis.yml +0 -17
- data/appveyor.yml +0 -25
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ace89c0cb3dcfd2f4bd564de101d4fa8a822cbfe6dd544af928b238d56aff542
|
4
|
+
data.tar.gz: 5bd3b988b94d0805f6ab8269623fa7fdb544fad9833031497e3e2d3e3066c93b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c002e188b150a545503416ea38ba6df553a595d6f9b79edbe91f5e503c7c1878f3c0681bdd836a735f19d848b3220128d00f70e5eb2fd82c12429067cbb4a65
|
7
|
+
data.tar.gz: aa9da71e042edeeae3f073e6287ce3d6648be8b92caf503b3e69d9cb119975f77cd8049a9a0a89e4321090ac59953ef4ef46464a24510b8bad471da2af3913e3
|
@@ -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,7 +1,41 @@
|
|
1
1
|
# Squib CHANGELOG
|
2
2
|
Squib follows [semantic versioning](http://semver.org).
|
3
3
|
|
4
|
-
## v0.
|
4
|
+
## v0.17.0 / 2021-07-23
|
5
|
+
Features:
|
6
|
+
* Drop shadows! The `save_png` method now supports a bunch of `shadow_` arguments that will add a drop shadow just before rendering. This is intended for using in rulebooks or marketing. Try it out by adding `shadow_radius: 8` to your save_png (#306, #264)
|
7
|
+
* Added debug methods for checking font access. `Squib.system_fonts` and `Squib.print_system_fonts` (#334)
|
8
|
+
|
9
|
+
Bugs:
|
10
|
+
* The `rows` argument is always respected in `save_sheet` (#332).
|
11
|
+
|
12
|
+
Chores:
|
13
|
+
* Bump cairo to ~1.17
|
14
|
+
* Bump classy_hash to 1.0
|
15
|
+
|
16
|
+
## v0.16.0 / 2020-11-24
|
17
|
+
|
18
|
+
Features:
|
19
|
+
* 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.
|
20
|
+
* Shorthands for `x`, `y`, `width`, and `height`! The words `x: 'middle'` and `x: 'middle + 1in'` will get interpreted. See the docs for details.
|
21
|
+
* Autoscaling text! `ellipsize: :autoscale` will now downscale your `font_size` if the text ellipsized. Thanks @Qgel! (#288, #111).
|
22
|
+
* 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.
|
23
|
+
* `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`.
|
24
|
+
|
25
|
+
Compatibility:
|
26
|
+
* When saving PNGs with sprues, outputs start counting at zero - which is more consistent with the rest of Squib.
|
27
|
+
* Minimum Ruby is now 2.5. NOTE: Ruby 3.0 is coming Christmas 2020!! Check it out.
|
28
|
+
|
29
|
+
Bugs:
|
30
|
+
* Extra page/no page issue with sprues (#320)
|
31
|
+
* Fix Ruby 2.7+ deprecations with CSV arguments (#303)
|
32
|
+
|
33
|
+
Chores:
|
34
|
+
* Reorganized the code internally. (#298) Every DSL method now has its own file.
|
35
|
+
* Moved to Github Actions
|
36
|
+
* Bump pango et al
|
37
|
+
|
38
|
+
|
5
39
|
|
6
40
|
## v0.15.3 / 2019-10-17
|
7
41
|
|
data/Dockerfile
CHANGED
@@ -1,25 +1,27 @@
|
|
1
|
-
|
1
|
+
# This is the official Squib Docker image.
|
2
|
+
#
|
3
|
+
FROM ruby:2.7-slim
|
2
4
|
WORKDIR /usr/src/app
|
3
5
|
|
4
6
|
LABEL org.squib.url=http://squib.rocks \
|
5
7
|
org.squib.github=https://github.com/andymeneely/squib
|
6
8
|
|
7
|
-
RUN
|
9
|
+
RUN apt-get update && \
|
10
|
+
apt-get install -y \
|
11
|
+
libgirepository1.0-dev \
|
12
|
+
build-essential \
|
8
13
|
ruby-dev \
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
libffi-dev \
|
14
|
-
cairo
|
14
|
+
ruby \
|
15
|
+
ruby-gdk-pixbuf2 \
|
16
|
+
git \
|
17
|
+
fonts-open-sans
|
15
18
|
|
16
|
-
#
|
17
|
-
COPY . /app
|
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
|
18
25
|
|
19
|
-
|
26
|
+
# ENTRYPOINT [ "sh" ]
|
20
27
|
|
21
|
-
# RUN gem install \
|
22
|
-
# squib \
|
23
|
-
# -- --use-system-libraries
|
24
|
-
|
25
|
-
# NOTE: STILL UNDER DEVELOPMENT! Don't use this just yet.
|
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,6 @@ 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
|
-
|
104
|
-
Using SublimeText? I like you already. I've written up some Squib snippets to ease remembering Squib commands. It's called `Squib Snippets` on Package Control. Compatible with SublimeText 3. Source code is also [on Github](https://github.com/andymeneely/sublime-squib) (contributions welcome!). Check it out:
|
105
|
-
|
106
|
-

|
107
|
-
|
108
102
|
|
109
103
|
## Docker
|
110
104
|
|
data/RELEASE TODO.md
CHANGED
@@ -9,13 +9,15 @@ Be sure to remember to do the following for releases. (Copy into a GitHub issue)
|
|
9
9
|
- [ ] Bump docs/conf.py versions
|
10
10
|
- [ ] Do a full rake locally
|
11
11
|
- [ ] `rake sanity`, and check visually
|
12
|
-
- [ ]
|
12
|
+
- [ ] GitHub Actions is passing on dev branch
|
13
13
|
- [ ] Merge master branch
|
14
14
|
- [ ] Merge release branch
|
15
15
|
- [ ] Push master and release branches
|
16
16
|
- [ ] Create GitHub release tag
|
17
17
|
- [ ] `gem push pkg/squib-x.y.z.gem`
|
18
18
|
- [ ] Github milestone closed
|
19
|
-
- [ ] Activate version on squib.readthedocs.org
|
19
|
+
- [ ] Activate version on squib.readthedocs.org (Versions)
|
20
|
+
- [ ] Set default version on squib.readthedocs.org (Advanced Settings)
|
20
21
|
- [ ] Bump version.rb to the next alpha
|
22
|
+
- [ ] Check Docker build
|
21
23
|
- [ ] Publish on BoardGameGeek thread
|
data/Rakefile
CHANGED
data/lib/squib.rb
CHANGED
@@ -2,12 +2,16 @@ 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'
|
10
|
+
require_relative 'squib/system_fonts'
|
11
|
+
|
9
12
|
|
10
13
|
module Squib
|
14
|
+
using Rainbow # we can colorize strings now!
|
11
15
|
|
12
16
|
# Access the internal logger that Squib uses. By default, Squib configure the logger to the WARN level
|
13
17
|
# Use this to suppress or increase output levels.
|
@@ -22,7 +26,7 @@ module Squib
|
|
22
26
|
@logger = Logger.new($stdout)
|
23
27
|
@logger.level = Logger::WARN
|
24
28
|
@logger.formatter = proc do |severity, datetime, m_progname, msg|
|
25
|
-
"#{datetime} #{severity}
|
29
|
+
"[#{datetime.strftime('%F %H:%M:%S')} #{severity.red}] #{msg}\n"
|
26
30
|
end
|
27
31
|
end
|
28
32
|
@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
|