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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +29 -29
  3. data/.travis.yml +6 -6
  4. data/.yardopts +7 -5
  5. data/Gemfile +2 -2
  6. data/LICENSE.txt +22 -22
  7. data/README.md +245 -92
  8. data/Rakefile +11 -11
  9. data/bin/squib +18 -18
  10. data/lib/squib.rb +31 -18
  11. data/lib/squib/api/background.rb +18 -16
  12. data/lib/squib/api/data.rb +52 -52
  13. data/lib/squib/api/image.rb +66 -48
  14. data/lib/squib/api/save.rb +43 -37
  15. data/lib/squib/api/settings.rb +38 -35
  16. data/lib/squib/api/shapes.rb +116 -106
  17. data/lib/squib/api/text.rb +50 -45
  18. data/lib/squib/api/units.rb +16 -16
  19. data/lib/squib/card.rb +42 -36
  20. data/lib/squib/commands/new.rb +43 -39
  21. data/lib/squib/constants.rb +104 -39
  22. data/lib/squib/deck.rb +116 -113
  23. data/lib/squib/graphics/background.rb +13 -12
  24. data/lib/squib/graphics/image.rb +47 -28
  25. data/lib/squib/graphics/save_doc.rb +54 -50
  26. data/lib/squib/graphics/save_images.rb +32 -10
  27. data/lib/squib/graphics/shapes.rb +59 -55
  28. data/lib/squib/graphics/text.rb +113 -107
  29. data/lib/squib/input_helpers.rb +193 -139
  30. data/lib/squib/progress.rb +38 -0
  31. data/lib/squib/project_template/.gitignore +4 -3
  32. data/lib/squib/project_template/ABOUT.md +19 -19
  33. data/lib/squib/project_template/Gemfile +2 -2
  34. data/lib/squib/project_template/PNP NOTES.md +3 -3
  35. data/lib/squib/project_template/config.yml +20 -2
  36. data/lib/squib/project_template/deck.rb +5 -5
  37. data/lib/squib/version.rb +6 -6
  38. data/samples/ball.png +0 -0
  39. data/samples/basic.rb +19 -19
  40. data/samples/colors.rb +15 -16
  41. data/samples/custom-config.yml +6 -1
  42. data/samples/custom-layout.yml +39 -34
  43. data/samples/custom_config.rb +18 -5
  44. data/samples/customconfig-imgdir/shiny-purse2.png +0 -0
  45. data/samples/customconfig-imgdir/spanner2.svg +91 -0
  46. data/samples/draw_shapes.rb +18 -18
  47. data/samples/excel.rb +19 -19
  48. data/samples/grit.png +0 -0
  49. data/samples/hello_world.rb +6 -6
  50. data/samples/load_images.rb +29 -19
  51. data/samples/offset.svg +71 -0
  52. data/samples/portrait-landscape.rb +23 -0
  53. data/samples/ranges.rb +55 -47
  54. data/samples/save_pdf.rb +14 -14
  55. data/samples/shiny-purse.png +0 -0
  56. data/samples/spanner.svg +91 -91
  57. data/samples/text_options.rb +60 -58
  58. data/samples/tgc_proofs.rb +19 -19
  59. data/samples/units.rb +12 -12
  60. data/samples/use_layout.rb +28 -28
  61. data/spec/api/api_text_spec.rb +42 -36
  62. data/spec/commands/new_spec.rb +47 -47
  63. data/spec/data/multi-extends-single-entry.yml +13 -0
  64. data/spec/data/multi-level-extends.yml +10 -0
  65. data/spec/data/no-extends.yml +5 -0
  66. data/spec/data/single-extends.yml +7 -0
  67. data/spec/data/single-level-multi-extends.yml +12 -0
  68. data/spec/deck_spec.rb +147 -49
  69. data/spec/input_helpers_spec.rb +117 -0
  70. data/spec/samples_run_spec.rb +19 -14
  71. data/spec/spec_helper.rb +3 -0
  72. data/squib.gemspec +46 -42
  73. metadata +78 -4
  74. data/API.md +0 -59
@@ -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
- opts = layoutify(opts) if params.include? :layout
12
- opts = Squib::SYSTEM_DEFAULTS.merge(opts)
13
- opts = rangeify(opts) if params.include? :range
14
- opts = fileify(opts) if params.include? :file
15
- opts = fileify(opts, false, true) if params.include? :file_to_save
16
- opts = fileify(opts, true) if params.include? :files
17
- opts = colorify(opts) if params.include? :color
18
- opts = colorify(opts, true) if params.include? :nillable_color
19
- opts = dirify(opts) if params.include? :dir
20
- opts = dirify(opts, true) if params.include? :creatable_dir
21
- opts = fontify(opts) if params.include? :font
22
- opts = radiusify(opts) if params.include? :radius
23
- opts = svgidify(opts) if params.include? :svgid
24
- opts = formatify(opts) if params.include? :formats
25
- opts
26
- end
27
- module_function :needs
28
-
29
- # :nodoc:
30
- # @api private
31
- def layoutify(opts)
32
- unless opts[:layout].nil?
33
- entry = @layout[opts[:layout].to_s]
34
- unless entry.nil?
35
- entry.each do |key, value|
36
- opts[key.to_sym] ||= entry[key]
37
- end
38
- else
39
- logger.warn "Layout entry #{opts[:layout]} does not exist."
40
- end
41
- end
42
- opts
43
- end
44
- module_function :layoutify
45
-
46
- # :nodoc:
47
- # @api private
48
- def formatify(opts)
49
- opts[:format] = [opts[:format]].flatten
50
- opts
51
- end
52
- module_function :formatify
53
-
54
- # :nodoc:
55
- # @api private
56
- def rangeify (opts)
57
- range = opts[:range]
58
- raise 'Range cannot be nil' if range.nil?
59
- range = 0..(@cards.size-1) if range == :all
60
- range = range..range if range.is_a? Integer
61
- if range.max > (@cards.size-1)
62
- raise "#{range} is outside of deck range of 0..#{@cards.size-1}"
63
- end
64
- opts[:range] = range
65
- opts
66
- end
67
- module_function :rangeify
68
-
69
- # :nodoc:
70
- # @api private
71
- def fileify(opts, expand_singletons=false, allow_non_exist=false)
72
- opts[:file] = [opts[:file]] * @cards.size if expand_singletons
73
- files = [opts[:file]].flatten
74
- files.each do |file|
75
- unless File.exists?(file) || allow_non_exist
76
- raise "File #{File.expand_path(file)} does not exist!"
77
- end
78
- end
79
- opts
80
- end
81
- module_function :fileify
82
-
83
- # :nodoc:
84
- # @api private
85
- def dirify(opts, allow_create=false)
86
- return opts if Dir.exists?(opts[:dir])
87
- if allow_create
88
- Squib.logger.warn "Dir #{opts[:dir]} does not exist, creating it."
89
- Dir.mkdir opts[:dir]
90
- return opts
91
- else
92
- raise "#{opts[:dir]} does not exist!"
93
- end
94
- end
95
- module_function :dirify
96
-
97
- # :nodoc:
98
- # @api private
99
- def colorify(opts, nillable=false)
100
- if nillable # for optional color arguments like text hints
101
- opts[:color] = Cairo::Color.parse(opts[:color]) unless opts[:color].nil?
102
- else
103
- opts[:color] = Cairo::Color.parse(opts[:color])
104
- end
105
- opts
106
- end
107
- module_function :colorify
108
-
109
- # :nodoc:
110
- # @api private
111
- def fontify (opts)
112
- opts[:font] = @font if opts[:font]==:use_set
113
- opts[:font] = Squib::SYSTEM_DEFAULTS[:default_font] if opts[:font] == :default
114
- opts
115
- end
116
- module_function :fontify
117
-
118
- # :nodoc:
119
- # @api private
120
- def radiusify(opts)
121
- unless opts[:radius].nil?
122
- opts[:x_radius] = opts[:radius]
123
- opts[:y_radius] = opts[:radius]
124
- end
125
- opts
126
- end
127
- module_function :radiusify
128
-
129
- # :nodoc:
130
- # @api private
131
- def svgidify(opts)
132
- unless opts[:id].nil?
133
- opts[:id] = '#' << opts[:id] unless opts[:id].start_with? '#'
134
- end
135
- opts
136
- end
137
- module_function :svgidify
138
-
139
- 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
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
- #dpi: 72
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