squib 0.0.2 → 0.0.3
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 -29
- data/.travis.yml +6 -6
- data/.yardopts +7 -5
- data/Gemfile +2 -2
- data/LICENSE.txt +22 -22
- data/README.md +245 -92
- data/Rakefile +11 -11
- data/bin/squib +18 -18
- data/lib/squib.rb +31 -18
- data/lib/squib/api/background.rb +18 -16
- data/lib/squib/api/data.rb +52 -52
- data/lib/squib/api/image.rb +66 -48
- data/lib/squib/api/save.rb +43 -37
- data/lib/squib/api/settings.rb +38 -35
- data/lib/squib/api/shapes.rb +116 -106
- data/lib/squib/api/text.rb +50 -45
- data/lib/squib/api/units.rb +16 -16
- data/lib/squib/card.rb +42 -36
- data/lib/squib/commands/new.rb +43 -39
- data/lib/squib/constants.rb +104 -39
- data/lib/squib/deck.rb +116 -113
- data/lib/squib/graphics/background.rb +13 -12
- data/lib/squib/graphics/image.rb +47 -28
- data/lib/squib/graphics/save_doc.rb +54 -50
- data/lib/squib/graphics/save_images.rb +32 -10
- data/lib/squib/graphics/shapes.rb +59 -55
- data/lib/squib/graphics/text.rb +113 -107
- data/lib/squib/input_helpers.rb +193 -139
- data/lib/squib/progress.rb +38 -0
- data/lib/squib/project_template/.gitignore +4 -3
- data/lib/squib/project_template/ABOUT.md +19 -19
- data/lib/squib/project_template/Gemfile +2 -2
- data/lib/squib/project_template/PNP NOTES.md +3 -3
- data/lib/squib/project_template/config.yml +20 -2
- data/lib/squib/project_template/deck.rb +5 -5
- data/lib/squib/version.rb +6 -6
- data/samples/ball.png +0 -0
- data/samples/basic.rb +19 -19
- data/samples/colors.rb +15 -16
- data/samples/custom-config.yml +6 -1
- data/samples/custom-layout.yml +39 -34
- data/samples/custom_config.rb +18 -5
- data/samples/customconfig-imgdir/shiny-purse2.png +0 -0
- data/samples/customconfig-imgdir/spanner2.svg +91 -0
- data/samples/draw_shapes.rb +18 -18
- data/samples/excel.rb +19 -19
- data/samples/grit.png +0 -0
- data/samples/hello_world.rb +6 -6
- data/samples/load_images.rb +29 -19
- data/samples/offset.svg +71 -0
- data/samples/portrait-landscape.rb +23 -0
- data/samples/ranges.rb +55 -47
- data/samples/save_pdf.rb +14 -14
- data/samples/shiny-purse.png +0 -0
- data/samples/spanner.svg +91 -91
- data/samples/text_options.rb +60 -58
- data/samples/tgc_proofs.rb +19 -19
- data/samples/units.rb +12 -12
- data/samples/use_layout.rb +28 -28
- data/spec/api/api_text_spec.rb +42 -36
- data/spec/commands/new_spec.rb +47 -47
- data/spec/data/multi-extends-single-entry.yml +13 -0
- data/spec/data/multi-level-extends.yml +10 -0
- data/spec/data/no-extends.yml +5 -0
- data/spec/data/single-extends.yml +7 -0
- data/spec/data/single-level-multi-extends.yml +12 -0
- data/spec/deck_spec.rb +147 -49
- data/spec/input_helpers_spec.rb +117 -0
- data/spec/samples_run_spec.rb +19 -14
- data/spec/spec_helper.rb +3 -0
- data/squib.gemspec +46 -42
- metadata +78 -4
- data/API.md +0 -59
data/lib/squib/input_helpers.rb
CHANGED
@@ -1,140 +1,194 @@
|
|
1
|
-
require 'squib/constants'
|
2
|
-
|
3
|
-
module Squib
|
4
|
-
# :nodoc:
|
5
|
-
# @api private
|
6
|
-
module InputHelpers
|
7
|
-
|
8
|
-
# :nodoc:
|
9
|
-
# @api private
|
10
|
-
def needs(opts, params)
|
11
|
-
|
12
|
-
opts =
|
13
|
-
opts =
|
14
|
-
opts =
|
15
|
-
opts =
|
16
|
-
opts = fileify(opts
|
17
|
-
opts =
|
18
|
-
opts = colorify(opts, true) if params.include? :nillable_color
|
19
|
-
opts = dirify(opts) if params.include? :
|
20
|
-
opts = dirify(opts,
|
21
|
-
opts =
|
22
|
-
opts =
|
23
|
-
opts =
|
24
|
-
opts =
|
25
|
-
opts
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
#
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
if
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
#
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
#
|
111
|
-
|
112
|
-
|
113
|
-
opts
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
end
|
135
|
-
opts
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
1
|
+
require 'squib/constants'
|
2
|
+
|
3
|
+
module Squib
|
4
|
+
# :nodoc:
|
5
|
+
# @api private
|
6
|
+
module InputHelpers
|
7
|
+
|
8
|
+
# :nodoc:
|
9
|
+
# @api private
|
10
|
+
def needs(opts, params)
|
11
|
+
Squib.logger.debug {"Given opts: #{opts}"}
|
12
|
+
opts = layoutify(opts) if params.include? :layout
|
13
|
+
opts = Squib::SYSTEM_DEFAULTS.merge(opts)
|
14
|
+
opts = expand_singletons(opts, params)
|
15
|
+
opts = rangeify(opts) if params.include? :range
|
16
|
+
opts = fileify(opts) if params.include? :file
|
17
|
+
opts = fileify(opts, false) if params.include? :file_to_save
|
18
|
+
opts = colorify(opts, true) if params.include? :nillable_color
|
19
|
+
opts = dirify(opts, :dir, true) if params.include? :creatable_dir
|
20
|
+
opts = dirify(opts, :img_dir, false) if params.include? :img_dir
|
21
|
+
opts = fileify(opts, false) if params.include? :files
|
22
|
+
opts = colorify(opts) if params.include? :color
|
23
|
+
opts = colorify(opts, false, :fill_color) if params.include? :fill_color
|
24
|
+
opts = colorify(opts, false, :stroke_color) if params.include? :stroke_color
|
25
|
+
opts = fontify(opts) if params.include? :font
|
26
|
+
opts = radiusify(opts) if params.include? :rect_radius
|
27
|
+
opts = svgidify(opts) if params.include? :svgid
|
28
|
+
opts = formatify(opts) if params.include? :formats
|
29
|
+
opts = rotateify(opts) if params.include? :rotate
|
30
|
+
opts
|
31
|
+
end
|
32
|
+
module_function :needs
|
33
|
+
|
34
|
+
# :nodoc:
|
35
|
+
# @api private
|
36
|
+
def expand_singletons(opts, needed_params)
|
37
|
+
Squib::EXPANDING_PARAMS.each_pair do |param_name, api_param|
|
38
|
+
if needed_params.include? param_name
|
39
|
+
unless opts[api_param].respond_to?(:each)
|
40
|
+
opts[api_param] = [opts[api_param]] * @cards.size
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
Squib.logger.debug {"After expand_singletons: #{opts}"}
|
45
|
+
opts
|
46
|
+
end
|
47
|
+
module_function :expand_singletons
|
48
|
+
|
49
|
+
# Layouts have to come before, so we repeat expand_singletons here
|
50
|
+
# :nodoc:
|
51
|
+
# @api private
|
52
|
+
def layoutify(opts)
|
53
|
+
unless opts[:layout].respond_to?(:each)
|
54
|
+
opts[:layout] = [opts[:layout]] * @cards.size
|
55
|
+
end
|
56
|
+
opts[:layout].each_with_index do |layout, i|
|
57
|
+
unless layout.nil?
|
58
|
+
entry = @layout[layout.to_s]
|
59
|
+
unless entry.nil?
|
60
|
+
entry.each do |key, value|
|
61
|
+
opts[key.to_sym] = [] if opts[key.to_sym].nil?
|
62
|
+
opts[key.to_sym][i] ||= entry[key] #don't override if it's already there
|
63
|
+
end
|
64
|
+
else
|
65
|
+
Squib.logger.warn ("Layout entry '#{layout}' does not exist." )
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
Squib.logger.debug {"After layoutify: #{opts}"}
|
70
|
+
opts
|
71
|
+
end
|
72
|
+
module_function :layoutify
|
73
|
+
|
74
|
+
# :nodoc:
|
75
|
+
# @api private
|
76
|
+
def formatify(opts)
|
77
|
+
opts[:format] = [opts[:format]].flatten
|
78
|
+
opts
|
79
|
+
end
|
80
|
+
module_function :formatify
|
81
|
+
|
82
|
+
# :nodoc:
|
83
|
+
# @api private
|
84
|
+
def rangeify (opts)
|
85
|
+
range = opts[:range]
|
86
|
+
raise 'Range cannot be nil' if range.nil?
|
87
|
+
range = 0..(@cards.size-1) if range == :all
|
88
|
+
range = range..range if range.is_a? Integer
|
89
|
+
if range.max > (@cards.size-1)
|
90
|
+
raise ArgumentError.new("#{range} is outside of deck range of 0..#{@cards.size-1}")
|
91
|
+
end
|
92
|
+
opts[:range] = range
|
93
|
+
Squib.logger.debug {"After rangeify: #{opts}"}
|
94
|
+
opts
|
95
|
+
end
|
96
|
+
module_function :rangeify
|
97
|
+
|
98
|
+
# :nodoc:
|
99
|
+
# @api private
|
100
|
+
def fileify(opts, file_must_exist=true)
|
101
|
+
[opts[:file]].flatten.each do |file|
|
102
|
+
if file_must_exist and !File.exists?(file)
|
103
|
+
raise "File #{File.expand_path(file)} does not exist!"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
opts
|
107
|
+
end
|
108
|
+
module_function :fileify
|
109
|
+
|
110
|
+
# :nodoc:
|
111
|
+
# @api private
|
112
|
+
def dirify(opts, key, allow_create=false)
|
113
|
+
return opts if Dir.exists?(opts[key])
|
114
|
+
if allow_create
|
115
|
+
Squib.logger.warn {"Dir #{opts[key]} does not exist, creating it."}
|
116
|
+
Dir.mkdir opts[key]
|
117
|
+
return opts
|
118
|
+
else
|
119
|
+
raise "'#{opts[key]}' does not exist!"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
module_function :dirify
|
123
|
+
|
124
|
+
# :nodoc:
|
125
|
+
# @api private
|
126
|
+
def colorify(opts, nillable=false, key=:color)
|
127
|
+
opts[key].each_with_index do |color, i|
|
128
|
+
unless nillable && color.nil?
|
129
|
+
if @custom_colors.key? color.to_s
|
130
|
+
color = @custom_colors[color.to_s]
|
131
|
+
end
|
132
|
+
opts[key][i] = Cairo::Color.parse(color)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
Squib.logger.debug {"After colorify: #{opts}"}
|
136
|
+
opts
|
137
|
+
end
|
138
|
+
module_function :colorify
|
139
|
+
|
140
|
+
# :nodoc:
|
141
|
+
# @api private
|
142
|
+
def fontify (opts)
|
143
|
+
opts[:font].each_with_index do |font, i|
|
144
|
+
opts[:font][i] = @font if font==:use_set
|
145
|
+
opts[:font][i] = Squib::SYSTEM_DEFAULTS[:default_font] if font == :default
|
146
|
+
end
|
147
|
+
Squib.logger.debug {"After fontify: #{opts}"}
|
148
|
+
opts
|
149
|
+
end
|
150
|
+
module_function :fontify
|
151
|
+
|
152
|
+
# :nodoc:
|
153
|
+
# @api private
|
154
|
+
def radiusify(opts)
|
155
|
+
opts[:radius].each_with_index do |radius, i|
|
156
|
+
unless radius.nil?
|
157
|
+
opts[:x_radius][i] = radius
|
158
|
+
opts[:y_radius][i] = radius
|
159
|
+
end
|
160
|
+
end
|
161
|
+
Squib.logger.debug {"After radiusify: #{opts}"}
|
162
|
+
opts
|
163
|
+
end
|
164
|
+
module_function :radiusify
|
165
|
+
|
166
|
+
# :nodoc:
|
167
|
+
# @api private
|
168
|
+
def svgidify(opts)
|
169
|
+
opts[:id].each_with_index do |id, i|
|
170
|
+
unless id.nil?
|
171
|
+
opts[:id][i] = '#' << id unless id.start_with? '#'
|
172
|
+
end
|
173
|
+
end
|
174
|
+
Squib.logger.debug {"After svgidify: #{opts}"}
|
175
|
+
opts
|
176
|
+
end
|
177
|
+
module_function :svgidify
|
178
|
+
|
179
|
+
# :nodoc:
|
180
|
+
# @api private
|
181
|
+
def rotateify(opts)
|
182
|
+
case opts[:rotate]
|
183
|
+
when true, :clockwise
|
184
|
+
opts[:angle] = 0.5 * Math::PI
|
185
|
+
when :counterclockwise
|
186
|
+
opts[:angle] = 1.5 * Math::PI
|
187
|
+
end
|
188
|
+
Squib.logger.debug {"After rotateify: #{opts}"}
|
189
|
+
opts
|
190
|
+
end
|
191
|
+
module_function :svgidify
|
192
|
+
|
193
|
+
end
|
140
194
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'ruby-progressbar'
|
2
|
+
|
3
|
+
module Squib
|
4
|
+
|
5
|
+
# :nodoc:
|
6
|
+
# @api private
|
7
|
+
class DoNothing
|
8
|
+
def increment
|
9
|
+
end
|
10
|
+
|
11
|
+
def finish
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# A facade that handles (or doesn't) the progress bar on the console
|
16
|
+
#
|
17
|
+
# :nodoc:
|
18
|
+
# @api private
|
19
|
+
class Progress
|
20
|
+
attr_accessor :enabled
|
21
|
+
|
22
|
+
def initialize(enabled)
|
23
|
+
@enabled = enabled
|
24
|
+
end
|
25
|
+
|
26
|
+
def start(title="", total=100, &block)
|
27
|
+
if @enabled
|
28
|
+
@bar = ProgressBar.create(title: title, total: total, format: '%t <%B> %p%% %a')
|
29
|
+
yield(@bar)
|
30
|
+
@bar.finish
|
31
|
+
else
|
32
|
+
yield(Squib::DoNothing.new)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
-
_output/*.png
|
2
|
-
_output/*.pdf
|
3
|
-
|
1
|
+
_output/*.png
|
2
|
+
_output/*.pdf
|
3
|
+
~$*
|
4
|
+
.DS_Store
|
@@ -1,19 +1,19 @@
|
|
1
|
-
My Awesome Game
|
2
|
-
===============
|
3
|
-
|
4
|
-
Check out my awesome game!
|
5
|
-
|
6
|
-
|
7
|
-
Objective
|
8
|
-
---------
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
Gameplay
|
13
|
-
--------
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Ending the Game
|
18
|
-
---------------
|
19
|
-
|
1
|
+
My Awesome Game
|
2
|
+
===============
|
3
|
+
|
4
|
+
Check out my awesome game!
|
5
|
+
|
6
|
+
|
7
|
+
Objective
|
8
|
+
---------
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
Gameplay
|
13
|
+
--------
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
Ending the Game
|
18
|
+
---------------
|
19
|
+
|
@@ -1,3 +1,3 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
3
|
gem 'squib'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
Print and Play Notes
|
2
|
-
====================
|
3
|
-
|
1
|
+
Print and Play Notes
|
2
|
+
====================
|
3
|
+
|
4
4
|
Fill this out to give tips on how to play this with print and play.
|
@@ -1,2 +1,20 @@
|
|
1
|
-
# Settings in the config.yml are overriding Squib's defaults. Anything in the main script will override this.
|
2
|
-
|
1
|
+
# Settings in the config.yml are overriding Squib's defaults. Anything in the main script will override this.
|
2
|
+
|
3
|
+
# DPI is used in making PDFs and in unit conversions
|
4
|
+
# Default: 300
|
5
|
+
#dpi: 72
|
6
|
+
|
7
|
+
# Text hints are used to show the boundaries of text boxes.
|
8
|
+
# Can be enabled/disabled at the command-level, or set globally with `set`
|
9
|
+
#text_hint: '#F00'
|
10
|
+
|
11
|
+
# Show progress bars on the command line for potentially long-running operations
|
12
|
+
#progress_bars: true
|
13
|
+
|
14
|
+
#Enable some custom colors that can be used in any color
|
15
|
+
#custom_colors:
|
16
|
+
# foo: '#abc'
|
17
|
+
|
18
|
+
#For reading image file command (e.g. png and svg), read from this directory instead
|
19
|
+
#img_dir: img-color
|
20
|
+
#img_dir: img-bw
|