squib 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +162 -133
  3. data/Gemfile +4 -4
  4. data/README.md +630 -550
  5. data/RELEASE TODO.md +18 -18
  6. data/Rakefile +99 -99
  7. data/lib/squib.rb +32 -32
  8. data/lib/squib/api/background.rb +20 -19
  9. data/lib/squib/api/data.rb +100 -99
  10. data/lib/squib/api/image.rb +90 -76
  11. data/lib/squib/api/save.rb +149 -103
  12. data/lib/squib/api/settings.rb +35 -37
  13. data/lib/squib/api/shapes.rb +230 -228
  14. data/lib/squib/api/text.rb +65 -66
  15. data/lib/squib/api/text_embed.rb +96 -66
  16. data/lib/squib/args/arg_loader.rb +138 -0
  17. data/lib/squib/args/box.rb +55 -0
  18. data/lib/squib/args/card_range.rb +32 -0
  19. data/lib/squib/args/color_validator.rb +12 -0
  20. data/lib/squib/args/coords.rb +33 -0
  21. data/lib/squib/args/dir_validator.rb +16 -0
  22. data/lib/squib/args/draw.rb +92 -0
  23. data/lib/squib/args/embed_adjust.rb +25 -0
  24. data/lib/squib/args/embed_key.rb +17 -0
  25. data/lib/squib/args/hand_special.rb +37 -0
  26. data/lib/squib/args/input_file.rb +37 -0
  27. data/lib/squib/args/paint.rb +44 -0
  28. data/lib/squib/args/paragraph.rb +115 -0
  29. data/lib/squib/args/save_batch.rb +60 -0
  30. data/lib/squib/args/scale_box.rb +53 -0
  31. data/lib/squib/args/sheet.rb +72 -0
  32. data/lib/squib/args/showcase_special.rb +38 -0
  33. data/lib/squib/args/svg_special.rb +37 -0
  34. data/lib/squib/args/transform.rb +25 -0
  35. data/lib/squib/args/typographer.rb +117 -117
  36. data/lib/squib/card.rb +67 -67
  37. data/lib/squib/conf.rb +117 -111
  38. data/lib/squib/constants.rb +178 -178
  39. data/lib/squib/deck.rb +113 -111
  40. data/lib/squib/graphics/cairo_context_wrapper.rb +99 -53
  41. data/lib/squib/graphics/gradient_regex.rb +46 -46
  42. data/lib/squib/graphics/hand.rb +42 -43
  43. data/lib/squib/graphics/image.rb +76 -73
  44. data/lib/squib/graphics/save_doc.rb +103 -137
  45. data/lib/squib/graphics/save_images.rb +33 -33
  46. data/lib/squib/graphics/shapes.rb +119 -152
  47. data/lib/squib/graphics/showcase.rb +85 -88
  48. data/lib/squib/graphics/text.rb +176 -216
  49. data/lib/squib/layout_parser.rb +91 -89
  50. data/lib/squib/layouts/economy.yml +85 -0
  51. data/lib/squib/layouts/fantasy.yml +101 -0
  52. data/lib/squib/layouts/hand.yml +62 -46
  53. data/lib/squib/layouts/playing-card.yml +35 -18
  54. data/lib/squib/project_template/config.yml +45 -40
  55. data/lib/squib/version.rb +10 -10
  56. data/samples/color_shortcuts.rb +6 -0
  57. data/samples/csv_import.rb +18 -18
  58. data/samples/custom-config.yml +5 -5
  59. data/samples/custom_config.rb +18 -18
  60. data/samples/draw_shapes.rb +45 -35
  61. data/samples/embed_text.rb +88 -90
  62. data/samples/hand.rb +24 -24
  63. data/samples/layouts.rb +62 -61
  64. data/samples/layouts_builtin.rb +51 -0
  65. data/samples/load_images.rb +78 -64
  66. data/samples/ranges.rb +64 -53
  67. data/samples/sample.csv +2 -2
  68. data/samples/text_options.rb +102 -94
  69. data/spec/api/api_data_spec.rb +57 -50
  70. data/spec/api/api_settings_spec.rb +37 -17
  71. data/spec/args/box_spec.rb +127 -0
  72. data/spec/args/draw_spec.rb +95 -0
  73. data/spec/args/embed_key_spec.rb +13 -0
  74. data/spec/args/input_file_spec.rb +21 -0
  75. data/spec/args/paint_spec.rb +22 -0
  76. data/spec/args/paragraph_spec.rb +153 -0
  77. data/spec/args/range_spec.rb +36 -0
  78. data/spec/args/save_batch_spec.rb +51 -0
  79. data/spec/args/scale_box_spec.rb +71 -0
  80. data/spec/args/sheet_spec.rb +58 -0
  81. data/spec/args/showcase_special_spec.rb +15 -0
  82. data/spec/data/samples/autoscale_font.rb.txt +84 -87
  83. data/spec/data/samples/basic.rb.txt +209 -203
  84. data/spec/data/samples/cairo_access.rb.txt +2 -2
  85. data/spec/data/samples/config_text_markup.rb.txt +72 -75
  86. data/spec/data/samples/csv_import.rb.txt +76 -80
  87. data/spec/data/samples/custom_config.rb.txt +48 -49
  88. data/spec/data/samples/draw_shapes.rb.txt +100 -42
  89. data/spec/data/samples/embed_text.rb.txt +283 -295
  90. data/spec/data/samples/excel.rb.txt +162 -171
  91. data/spec/data/samples/gradients.rb.txt +79 -67
  92. data/spec/data/samples/hand.rb.txt +538 -514
  93. data/spec/data/samples/hello_world.rb.txt +36 -38
  94. data/spec/data/samples/load_images.rb.txt +41 -5
  95. data/spec/data/samples/portrait-landscape.rb.txt +49 -51
  96. data/spec/data/samples/ranges.rb.txt +460 -429
  97. data/spec/data/samples/saves.rb.txt +801 -785
  98. data/spec/data/samples/showcase.rb.txt +5910 -5906
  99. data/spec/data/samples/text_options.rb.txt +1125 -981
  100. data/spec/data/samples/tgc_proofs.rb.txt +81 -79
  101. data/spec/data/samples/units.rb.txt +18 -12
  102. data/spec/data/xlsx/with_macros.xlsm +0 -0
  103. data/spec/graphics/cairo_context_wrapper_spec.rb +84 -75
  104. data/spec/graphics/graphics_images_spec.rb +94 -85
  105. data/spec/graphics/graphics_save_doc_spec.rb +67 -65
  106. data/spec/samples/expected/hand.png +0 -0
  107. data/spec/samples/expected/hand_pretty.png +0 -0
  108. data/spec/samples/expected/layout_00.png +0 -0
  109. data/spec/samples/expected/load_images_00.png +0 -0
  110. data/spec/samples/expected/ranges_00.png +0 -0
  111. data/spec/samples/expected/shape_00.png +0 -0
  112. data/spec/samples/expected/showcase.png +0 -0
  113. data/spec/samples/expected/showcase2.png +0 -0
  114. data/spec/samples/expected/showcase_individual_00.png +0 -0
  115. data/spec/samples/expected/showcase_individual_01.png +0 -0
  116. data/spec/samples/expected/showcase_individual_02.png +0 -0
  117. data/spec/samples/expected/showcase_individual_03.png +0 -0
  118. data/spec/samples/expected/text_00.png +0 -0
  119. data/spec/samples/expected/text_01.png +0 -0
  120. data/spec/samples/expected/text_02.png +0 -0
  121. data/spec/samples/samples_regression_spec.rb +82 -82
  122. data/spec/spec_helper.rb +3 -2
  123. data/squib.gemspec +48 -48
  124. data/squib.sublime-project +42 -36
  125. metadata +61 -33
  126. data/lib/squib/input_helpers.rb +0 -238
  127. data/spec/api/api_image_spec.rb +0 -38
  128. data/spec/api/api_text_spec.rb +0 -37
  129. data/spec/graphics/graphics_shapes_spec.rb +0 -85
  130. data/spec/graphics/graphics_text_spec.rb +0 -164
  131. data/spec/input_helpers_spec.rb +0 -238
  132. data/spec/samples/expected/embed_multi_00.png +0 -0
  133. data/spec/samples/expected/embed_multi_01.png +0 -0
  134. data/spec/samples/expected/embed_multi_02.png +0 -0
  135. data/spec/samples/expected/ranges_01.png +0 -0
  136. data/spec/samples/expected/ranges_02.png +0 -0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Meneely
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-27 00:00:00.000000000 Z
11
+ date: 2015-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cairo
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 1.14.0
19
+ version: 1.14.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 1.14.0
26
+ version: 1.14.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pango
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 2.2.0
33
+ version: 3.0.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 2.2.0
40
+ version: 3.0.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: roo
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 2.0.0
47
+ version: 2.1.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 2.0.0
54
+ version: 2.1.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rsvg2
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 2.2.0
61
+ version: 3.0.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: 2.2.0
68
+ version: 3.0.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mercenary
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - ~>
130
130
  - !ruby/object:Gem::Version
131
- version: '3.2'
131
+ version: '3.3'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - ~>
137
137
  - !ruby/object:Gem::Version
138
- version: '3.2'
138
+ version: '3.3'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: redcarpet
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -232,6 +232,7 @@ extra_rdoc_files:
232
232
  - samples/basic.rb
233
233
  - samples/cairo_access.rb
234
234
  - samples/colors.rb
235
+ - samples/color_shortcuts.rb
235
236
  - samples/config_text_markup.rb
236
237
  - samples/csv_import.rb
237
238
  - samples/custom_config.rb
@@ -242,6 +243,7 @@ extra_rdoc_files:
242
243
  - samples/hand.rb
243
244
  - samples/hello_world.rb
244
245
  - samples/layouts.rb
246
+ - samples/layouts_builtin.rb
245
247
  - samples/load_images.rb
246
248
  - samples/portrait-landscape.rb
247
249
  - samples/ranges.rb
@@ -285,6 +287,25 @@ files:
285
287
  - lib/squib/api/text.rb
286
288
  - lib/squib/api/text_embed.rb
287
289
  - lib/squib/api/units.rb
290
+ - lib/squib/args/arg_loader.rb
291
+ - lib/squib/args/box.rb
292
+ - lib/squib/args/card_range.rb
293
+ - lib/squib/args/color_validator.rb
294
+ - lib/squib/args/coords.rb
295
+ - lib/squib/args/dir_validator.rb
296
+ - lib/squib/args/draw.rb
297
+ - lib/squib/args/embed_adjust.rb
298
+ - lib/squib/args/embed_key.rb
299
+ - lib/squib/args/hand_special.rb
300
+ - lib/squib/args/input_file.rb
301
+ - lib/squib/args/paint.rb
302
+ - lib/squib/args/paragraph.rb
303
+ - lib/squib/args/save_batch.rb
304
+ - lib/squib/args/scale_box.rb
305
+ - lib/squib/args/sheet.rb
306
+ - lib/squib/args/showcase_special.rb
307
+ - lib/squib/args/svg_special.rb
308
+ - lib/squib/args/transform.rb
288
309
  - lib/squib/args/typographer.rb
289
310
  - lib/squib/args/unit_conversion.rb
290
311
  - lib/squib/card.rb
@@ -302,8 +323,9 @@ files:
302
323
  - lib/squib/graphics/shapes.rb
303
324
  - lib/squib/graphics/showcase.rb
304
325
  - lib/squib/graphics/text.rb
305
- - lib/squib/input_helpers.rb
306
326
  - lib/squib/layout_parser.rb
327
+ - lib/squib/layouts/economy.yml
328
+ - lib/squib/layouts/fantasy.yml
307
329
  - lib/squib/layouts/hand.yml
308
330
  - lib/squib/layouts/playing-card.yml
309
331
  - lib/squib/progress.rb
@@ -324,6 +346,7 @@ files:
324
346
  - samples/ball.png
325
347
  - samples/basic.rb
326
348
  - samples/cairo_access.rb
349
+ - samples/color_shortcuts.rb
327
350
  - samples/colors.rb
328
351
  - samples/config_disable_quotes.yml
329
352
  - samples/config_text_markup.rb
@@ -344,6 +367,7 @@ files:
344
367
  - samples/hand.rb
345
368
  - samples/hello_world.rb
346
369
  - samples/layouts.rb
370
+ - samples/layouts_builtin.rb
347
371
  - samples/load_images.rb
348
372
  - samples/offset.svg
349
373
  - samples/pokercard.png
@@ -360,9 +384,18 @@ files:
360
384
  - samples/unicode.rb
361
385
  - samples/units.rb
362
386
  - spec/api/api_data_spec.rb
363
- - spec/api/api_image_spec.rb
364
387
  - spec/api/api_settings_spec.rb
365
- - spec/api/api_text_spec.rb
388
+ - spec/args/box_spec.rb
389
+ - spec/args/draw_spec.rb
390
+ - spec/args/embed_key_spec.rb
391
+ - spec/args/input_file_spec.rb
392
+ - spec/args/paint_spec.rb
393
+ - spec/args/paragraph_spec.rb
394
+ - spec/args/range_spec.rb
395
+ - spec/args/save_batch_spec.rb
396
+ - spec/args/scale_box_spec.rb
397
+ - spec/args/sheet_spec.rb
398
+ - spec/args/showcase_special_spec.rb
366
399
  - spec/args/typographer_spec.rb
367
400
  - spec/args/unit_conversion_spec.rb
368
401
  - spec/commands/new_spec.rb
@@ -412,13 +445,11 @@ files:
412
445
  - spec/data/samples/units.rb.txt
413
446
  - spec/data/xlsx/basic.xlsx
414
447
  - spec/data/xlsx/formulas.xlsx
448
+ - spec/data/xlsx/with_macros.xlsm
415
449
  - spec/deck_spec.rb
416
450
  - spec/graphics/cairo_context_wrapper_spec.rb
417
451
  - spec/graphics/graphics_images_spec.rb
418
452
  - spec/graphics/graphics_save_doc_spec.rb
419
- - spec/graphics/graphics_shapes_spec.rb
420
- - spec/graphics/graphics_text_spec.rb
421
- - spec/input_helpers_spec.rb
422
453
  - spec/layout_parser_spec.rb
423
454
  - spec/logger_spec.rb
424
455
  - spec/samples/_diffs/gitkeep.txt
@@ -441,9 +472,6 @@ files:
441
472
  - spec/samples/expected/config_text_00.png
442
473
  - spec/samples/expected/custom-config_00.png
443
474
  - spec/samples/expected/embed_00.png
444
- - spec/samples/expected/embed_multi_00.png
445
- - spec/samples/expected/embed_multi_01.png
446
- - spec/samples/expected/embed_multi_02.png
447
475
  - spec/samples/expected/embed_multisheet_00.png
448
476
  - spec/samples/expected/gitkeep.txt
449
477
  - spec/samples/expected/gradient_00.png
@@ -457,8 +485,6 @@ files:
457
485
  - spec/samples/expected/load_images_00.png
458
486
  - spec/samples/expected/portrait_00.png
459
487
  - spec/samples/expected/ranges_00.png
460
- - spec/samples/expected/ranges_01.png
461
- - spec/samples/expected/ranges_02.png
462
488
  - spec/samples/expected/sample_csv_00.png
463
489
  - spec/samples/expected/sample_csv_01.png
464
490
  - spec/samples/expected/sample_excel_00.png
@@ -515,9 +541,18 @@ specification_version: 2
515
541
  summary: A Ruby DSL for prototyping card games
516
542
  test_files:
517
543
  - spec/api/api_data_spec.rb
518
- - spec/api/api_image_spec.rb
519
544
  - spec/api/api_settings_spec.rb
520
- - spec/api/api_text_spec.rb
545
+ - spec/args/box_spec.rb
546
+ - spec/args/draw_spec.rb
547
+ - spec/args/embed_key_spec.rb
548
+ - spec/args/input_file_spec.rb
549
+ - spec/args/paint_spec.rb
550
+ - spec/args/paragraph_spec.rb
551
+ - spec/args/range_spec.rb
552
+ - spec/args/save_batch_spec.rb
553
+ - spec/args/scale_box_spec.rb
554
+ - spec/args/sheet_spec.rb
555
+ - spec/args/showcase_special_spec.rb
521
556
  - spec/args/typographer_spec.rb
522
557
  - spec/args/unit_conversion_spec.rb
523
558
  - spec/commands/new_spec.rb
@@ -567,13 +602,11 @@ test_files:
567
602
  - spec/data/samples/units.rb.txt
568
603
  - spec/data/xlsx/basic.xlsx
569
604
  - spec/data/xlsx/formulas.xlsx
605
+ - spec/data/xlsx/with_macros.xlsm
570
606
  - spec/deck_spec.rb
571
607
  - spec/graphics/cairo_context_wrapper_spec.rb
572
608
  - spec/graphics/graphics_images_spec.rb
573
609
  - spec/graphics/graphics_save_doc_spec.rb
574
- - spec/graphics/graphics_shapes_spec.rb
575
- - spec/graphics/graphics_text_spec.rb
576
- - spec/input_helpers_spec.rb
577
610
  - spec/layout_parser_spec.rb
578
611
  - spec/logger_spec.rb
579
612
  - spec/samples/_diffs/gitkeep.txt
@@ -596,9 +629,6 @@ test_files:
596
629
  - spec/samples/expected/config_text_00.png
597
630
  - spec/samples/expected/custom-config_00.png
598
631
  - spec/samples/expected/embed_00.png
599
- - spec/samples/expected/embed_multi_00.png
600
- - spec/samples/expected/embed_multi_01.png
601
- - spec/samples/expected/embed_multi_02.png
602
632
  - spec/samples/expected/embed_multisheet_00.png
603
633
  - spec/samples/expected/gitkeep.txt
604
634
  - spec/samples/expected/gradient_00.png
@@ -612,8 +642,6 @@ test_files:
612
642
  - spec/samples/expected/load_images_00.png
613
643
  - spec/samples/expected/portrait_00.png
614
644
  - spec/samples/expected/ranges_00.png
615
- - spec/samples/expected/ranges_01.png
616
- - spec/samples/expected/ranges_02.png
617
645
  - spec/samples/expected/sample_csv_00.png
618
646
  - spec/samples/expected/sample_csv_01.png
619
647
  - spec/samples/expected/sample_excel_00.png
@@ -1,238 +0,0 @@
1
- require 'squib/constants'
2
- require 'squib/args/unit_conversion'
3
-
4
- module Squib
5
- # :nodoc:
6
- # @api private
7
- module InputHelpers
8
-
9
- # :nodoc:
10
- # @api private
11
- def needs(opts, params)
12
- Squib.logger.debug {"Method #{caller(1,1)} was given the following opts: #{opts}"}
13
- opts = layoutify(opts) if params.include? :layout
14
- opts = Squib::SYSTEM_DEFAULTS.merge(opts)
15
- opts = expand_singletons(opts, params)
16
- opts = rangeify(opts) if params.include? :range
17
- opts = fileify(opts) if params.include? :file
18
- opts = fileify(opts, false) if params.include? :file_to_save
19
- opts = colorify(opts, true) if params.include? :nillable_color
20
- opts = dirify(opts, :dir, true) if params.include? :creatable_dir
21
- opts = dirify(opts, :img_dir, false) if params.include? :img_dir
22
- opts = fileify(opts, false) if params.include? :files
23
- opts = colorify(opts) if params.include? :color
24
- opts = colorify(opts, false, :fill_color) if params.include? :fill_color
25
- opts = colorify(opts, false, :stroke_color) if params.include? :stroke_color
26
- opts = fontify(opts) if params.include? :font
27
- opts = radiusify(opts) if params.include? :rect_radius
28
- opts = svgidify(opts) if params.include? :svgid
29
- opts = formatify(opts) if params.include? :formats
30
- opts = rotateify(opts) if params.include? :rotate
31
- opts = rowify(opts) if params.include? :rows
32
- opts = faceify(opts) if params.include? :face
33
- opts = convert_units(opts, params)
34
- opts
35
- end
36
- module_function :needs
37
-
38
- # :nodoc:
39
- # @api private
40
- def expand_singletons(opts, needed_params)
41
- Squib::EXPANDING_PARAMS.each_pair do |param_name, api_param|
42
- if needed_params.include? param_name
43
- unless opts[api_param].respond_to?(:each)
44
- opts[api_param] = [opts[api_param]] * @cards.size
45
- end
46
- end
47
- end
48
- Squib.logger.debug {"After expand_singletons: #{opts}"}
49
- opts
50
- end
51
- module_function :expand_singletons
52
-
53
- # Layouts have to come before, so we repeat expand_singletons here
54
- # :nodoc:
55
- # @api private
56
- def layoutify(opts)
57
- unless opts[:layout].respond_to?(:each)
58
- opts[:layout] = [opts[:layout]] * @cards.size
59
- end
60
- opts[:layout].each_with_index do |layout, i|
61
- unless layout.nil?
62
- entry = @layout[layout.to_s]
63
- unless entry.nil?
64
- entry.each do |key, value|
65
- opts[key.to_sym] = [] if opts[key.to_sym].nil?
66
- opts[key.to_sym][i] ||= entry[key] #don't override if it's already there
67
- end
68
- else
69
- Squib.logger.warn ("Layout entry '#{layout}' does not exist." )
70
- end
71
- end
72
- end
73
- Squib.logger.debug {"After layoutify: #{opts}"}
74
- opts
75
- end
76
- module_function :layoutify
77
-
78
- # :nodoc:
79
- # @api private
80
- def formatify(opts)
81
- opts[:format] = [opts[:format]].flatten
82
- opts
83
- end
84
- module_function :formatify
85
-
86
- # :nodoc:
87
- # @api private
88
- def rangeify (opts)
89
- range = opts[:range]
90
- raise 'Range cannot be nil' if range.nil?
91
- range = 0..(@cards.size-1) if range == :all
92
- range = range..range if range.is_a? Integer
93
- if range.max > (@cards.size-1)
94
- raise ArgumentError.new("#{range} is outside of deck range of 0..#{@cards.size-1}")
95
- end
96
- opts[:range] = range
97
- Squib.logger.debug {"After rangeify: #{opts}"}
98
- opts
99
- end
100
- module_function :rangeify
101
-
102
- # :nodoc:
103
- # @api private
104
- def fileify(opts, file_must_exist=true)
105
- [opts[:file]].flatten.each do |file|
106
- if file_must_exist and !File.exists?(file)
107
- raise "File #{File.expand_path(file)} does not exist!"
108
- end
109
- end
110
- opts
111
- end
112
- module_function :fileify
113
-
114
- # :nodoc:
115
- # @api private
116
- def dirify(opts, key, allow_create=false)
117
- return opts if Dir.exists?(opts[key])
118
- if allow_create
119
- Squib.logger.warn("Dir '#{opts[key]}' does not exist, creating it.")
120
- Dir.mkdir opts[key]
121
- return opts
122
- else
123
- raise "'#{opts[key]}' does not exist!"
124
- end
125
- end
126
- module_function :dirify
127
-
128
- # :nodoc:
129
- # @api private
130
- def colorify(opts, nillable=false, key=:color)
131
- opts[key].each_with_index do |color, i|
132
- unless nillable && color.nil?
133
- if custom_colors.key? color.to_s
134
- color = custom_colors[color.to_s]
135
- end
136
- opts[key][i] = color
137
- end
138
- end
139
- Squib.logger.debug {"After colorify: #{opts}"}
140
- opts
141
- end
142
- module_function :colorify
143
-
144
- # :nodoc:
145
- # @api private
146
- def fontify (opts)
147
- opts[:font].each_with_index do |font, i|
148
- opts[:font][i] = @font if font==:use_set
149
- opts[:font][i] = Squib::SYSTEM_DEFAULTS[:default_font] if font == :default
150
- end
151
- Squib.logger.debug {"After fontify: #{opts}"}
152
- opts
153
- end
154
- module_function :fontify
155
-
156
- # :nodoc:
157
- # @api private
158
- def radiusify(opts)
159
- opts[:radius].each_with_index do |radius, i|
160
- unless radius.nil?
161
- opts[:x_radius][i] = radius
162
- opts[:y_radius][i] = radius
163
- end
164
- end
165
- Squib.logger.debug {"After radiusify: #{opts}"}
166
- opts
167
- end
168
- module_function :radiusify
169
-
170
- # :nodoc:
171
- # @api private
172
- def svgidify(opts)
173
- opts[:id].each_with_index do |id, i|
174
- unless id.nil?
175
- opts[:id][i] = '#' << id unless id.start_with? '#'
176
- end
177
- end
178
- Squib.logger.debug {"After svgidify: #{opts}"}
179
- opts
180
- end
181
- module_function :svgidify
182
-
183
- # :nodoc:
184
- # @api private
185
- def rotateify(opts)
186
- case opts[:rotate]
187
- when true, :clockwise
188
- opts[:angle] = 0.5 * Math::PI
189
- when :counterclockwise
190
- opts[:angle] = 1.5 * Math::PI
191
- end
192
- Squib.logger.debug {"After rotateify: #{opts}"}
193
- opts
194
- end
195
- module_function :rotateify
196
-
197
- # Convert units
198
- # :nodoc:
199
- # @api private
200
- def convert_units(opts, needed_params)
201
- UNIT_CONVERSION_PARAMS.each_pair do |param_name, api_param|
202
- if needed_params.include? param_name
203
- if EXPANDING_PARAMS.include? param_name
204
- opts[api_param].each_with_index do |arg, i|
205
- opts[api_param][i] = Args::UnitConversion.parse(arg, @dpi)
206
- end
207
- else #not an expanding param
208
- opts[api_param] = Args::UnitConversion.parse(opts[api_param], @dpi)
209
- end
210
- end
211
- end
212
- Squib.logger.debug {"After convert_units: #{opts}"}
213
- return opts
214
- end
215
- module_function :convert_units
216
-
217
- # Handles expanding rows. If the "rows" does not respond to to_i (e.g. :infinite),
218
- # then compute what we need based on number of cards and number of columns.
219
- # :nodoc:
220
- # @api private
221
- def rowify(opts)
222
- unless opts[:rows].respond_to? :to_i
223
- raise "Columns must be an integer" unless opts[:columns].respond_to? :to_i
224
- opts[:rows] = (@cards.size / opts[:columns].to_i).ceil
225
- end
226
- opts
227
- end
228
-
229
- # Used for showcase - face right if it's :right
230
- # :nodoc:
231
- # @api private
232
- def faceify(opts)
233
- opts[:face] = (opts[:face].to_s.downcase == 'right')
234
- opts
235
- end
236
-
237
- end
238
- end