squib 0.0.3 → 0.0.4
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 -7
- data/CHANGELOG.md +19 -0
- data/Gemfile +2 -2
- data/LICENSE.txt +22 -22
- data/README.md +256 -244
- data/Rakefile +11 -11
- data/bin/squib +18 -18
- data/lib/squib.rb +31 -31
- data/lib/squib/api/background.rb +18 -18
- data/lib/squib/api/data.rb +52 -52
- data/lib/squib/api/image.rb +66 -66
- data/lib/squib/api/save.rb +43 -43
- data/lib/squib/api/settings.rb +37 -38
- data/lib/squib/api/shapes.rb +116 -116
- data/lib/squib/api/text.rb +53 -50
- data/lib/squib/api/units.rb +16 -16
- data/lib/squib/card.rb +41 -41
- data/lib/squib/commands/new.rb +43 -43
- data/lib/squib/constants.rb +108 -104
- data/lib/squib/deck.rb +170 -116
- data/lib/squib/graphics/background.rb +13 -13
- data/lib/squib/graphics/image.rb +47 -47
- data/lib/squib/graphics/save_doc.rb +54 -54
- data/lib/squib/graphics/save_images.rb +32 -32
- data/lib/squib/graphics/shapes.rb +59 -59
- data/lib/squib/graphics/text.rb +116 -113
- data/lib/squib/input_helpers.rb +193 -193
- data/lib/squib/progress.rb +37 -37
- data/lib/squib/project_template/.gitignore +4 -4
- 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 +19 -19
- data/lib/squib/project_template/deck.rb +5 -5
- data/lib/squib/version.rb +6 -6
- data/samples/autoscale_font.rb +27 -0
- data/samples/basic.rb +19 -19
- data/samples/colors.rb +15 -15
- data/samples/custom-config.yml +5 -5
- data/samples/custom-layout.yml +59 -39
- data/samples/custom_config.rb +18 -18
- data/samples/customconfig-imgdir/spanner2.svg +91 -91
- data/samples/draw_shapes.rb +18 -18
- data/samples/excel.rb +19 -19
- data/samples/hello_world.rb +6 -6
- data/samples/load_images.rb +29 -29
- data/samples/offset.svg +71 -71
- data/samples/portrait-landscape.rb +22 -22
- data/samples/ranges.rb +55 -55
- data/samples/save_pdf.rb +14 -14
- data/samples/spanner.svg +91 -91
- data/samples/text_options.rb +67 -60
- data/samples/tgc_proofs.rb +19 -19
- data/samples/units.rb +12 -12
- data/samples/use_layout.rb +33 -28
- data/spec/api/api_text_spec.rb +43 -43
- data/spec/commands/new_spec.rb +47 -47
- data/spec/data/easy-circular-extends.yml +6 -0
- data/spec/data/hard-circular-extends.yml +9 -0
- data/spec/data/multi-extends-single-entry.yml +14 -13
- data/spec/data/multi-level-extends.yml +9 -9
- data/spec/data/no-extends.yml +5 -5
- data/spec/data/pre-extends.yml +7 -0
- data/spec/data/self-circular-extends.yml +3 -0
- data/spec/data/single-extends.yml +7 -7
- data/spec/data/single-level-multi-extends.yml +11 -11
- data/spec/deck_spec.rb +188 -147
- data/spec/input_helpers_spec.rb +116 -116
- data/spec/samples_run_spec.rb +19 -19
- data/squib.gemspec +46 -46
- metadata +17 -7
data/lib/squib/input_helpers.rb
CHANGED
@@ -1,194 +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
|
-
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
|
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
|
194
194
|
end
|
data/lib/squib/progress.rb
CHANGED
@@ -1,38 +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
|
-
|
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
38
|
end
|