squib 0.6.0 → 0.7.0

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 (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
@@ -0,0 +1,32 @@
1
+ module Squib
2
+ # @api private
3
+ module Args
4
+ class CardRange
5
+ include Enumerable
6
+
7
+ def initialize(input, deck_size: 1)
8
+ @range = validate(input, deck_size)
9
+ end
10
+
11
+ # Hook into enumerable by delegating to @range
12
+ def each(&block)
13
+ @range.each { |i| block.call(i) }
14
+ end
15
+
16
+ def size
17
+ @range.size
18
+ end
19
+
20
+ private
21
+ def validate(input, deck_size)
22
+ input ||= :all # default
23
+ input = 0..(deck_size - 1) if input == :all
24
+ input = (input.to_i)..(input.to_i) if input.respond_to? :to_i
25
+ raise ArgumentError.new("#{input} must be Enumerable (i.e. respond_to :each).") unless input.respond_to? :each
26
+ raise ArgumentError.new("#{input} is outside of deck range of 0..#{deck_size-1}") if input.max > (deck_size - 1)
27
+ input
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ module Squib
2
+ #@api private
3
+ module Args
4
+ module ColorValidator
5
+
6
+ def colorify(color, custom_colors = {})
7
+ custom_colors[color.to_s] || color.to_s
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,33 @@
1
+ require 'squib/args/arg_loader'
2
+
3
+ module Squib
4
+ # @api private
5
+ module Args
6
+
7
+ class Coords
8
+ include ArgLoader
9
+
10
+ def self.parameters
11
+ { x: 0, y: 0,
12
+ x1: 100, y1: 100,
13
+ x2: 150, y2: 150,
14
+ x3: 100, y3: 150,
15
+ cx1: 0 , cy1: 0,
16
+ cx2: 0 , cy2: 0,
17
+ inner_radius: 50, outer_radius: 100,
18
+ radius: 100,
19
+ n: 5, }
20
+ end
21
+
22
+ def self.expanding_parameters
23
+ parameters.keys # all of them
24
+ end
25
+
26
+ def self.params_with_units
27
+ parameters.keys # all of them
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,16 @@
1
+ module Squib
2
+ #@api private
3
+ module Args
4
+ module DirValidator
5
+
6
+ def ensure_dir_created(dir)
7
+ unless Dir.exists?(dir)
8
+ Squib.logger.warn "Dir '#{dir}' does not exist, creating it."
9
+ Dir.mkdir dir
10
+ end
11
+ return dir
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,92 @@
1
+ require 'cairo'
2
+ require 'squib/args/arg_loader'
3
+ require 'squib/args/color_validator'
4
+
5
+ module Squib
6
+ # @api private
7
+ module Args
8
+
9
+ class Draw
10
+ include ArgLoader
11
+ include ColorValidator
12
+
13
+ def initialize(custom_colors, dsl_method_defaults = {})
14
+ @custom_colors = custom_colors
15
+ @dsl_method_defaults = dsl_method_defaults
16
+ end
17
+
18
+ def self.parameters
19
+ { color: :black,
20
+ fill_color: '#0000',
21
+ stroke_color: :black,
22
+ stroke_width: 2.0,
23
+ stroke_strategy: :fill_first,
24
+ join: :miter,
25
+ cap: 'butt',
26
+ dash: ''
27
+ }
28
+ end
29
+
30
+ def self.expanding_parameters
31
+ parameters.keys # all of them are expandable
32
+ end
33
+
34
+ def self.params_with_units
35
+ [:stroke_width]
36
+ end
37
+
38
+ def validate_join(arg, _i)
39
+ case arg.to_s.strip.downcase
40
+ when 'miter'
41
+ Cairo::LINE_JOIN_MITER
42
+ when 'round'
43
+ Cairo::LINE_JOIN_ROUND
44
+ when 'bevel'
45
+ Cairo::LINE_JOIN_BEVEL
46
+ end
47
+ end
48
+
49
+ def validate_cap(arg, _i)
50
+ case arg.to_s.strip.downcase
51
+ when 'butt'
52
+ Cairo::LINE_CAP_BUTT
53
+ when 'round'
54
+ Cairo::LINE_CAP_ROUND
55
+ when 'square'
56
+ Cairo::LINE_CAP_SQUARE
57
+ end
58
+ end
59
+
60
+ def validate_dash(arg, _i)
61
+ arg.to_s.split.collect do |x|
62
+ convert_unit(x, @dpi).to_f
63
+ end
64
+ end
65
+
66
+ def validate_fill_color(arg, _i)
67
+ colorify(arg, @custom_colors)
68
+ end
69
+
70
+ def validate_stroke_color(arg, _i)
71
+ colorify(arg, @custom_colors)
72
+ end
73
+
74
+ def validate_color(arg, _i)
75
+ colorify(arg, @custom_colors)
76
+ end
77
+
78
+ def validate_stroke_strategy(arg, _i)
79
+ case arg.to_s.downcase.strip
80
+ when 'fill_first'
81
+ :fill_first
82
+ when 'stroke_first'
83
+ :stroke_first
84
+ else
85
+ raise "Only 'stroke_first' or 'fill_first' allowed"
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,25 @@
1
+ require 'squib/args/arg_loader'
2
+
3
+ module Squib
4
+ # @api private
5
+ module Args
6
+
7
+ class EmbedAdjust
8
+ include ArgLoader
9
+
10
+ def self.parameters
11
+ { dx: 0, dy: 0 }
12
+ end
13
+
14
+ def self.expanding_parameters
15
+ parameters.keys # all of them
16
+ end
17
+
18
+ def self.params_with_units
19
+ parameters.keys # all of them
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ require 'squib/args/arg_loader'
2
+
3
+ module Squib
4
+ # @api private
5
+ module Args
6
+
7
+ class EmbedKey
8
+
9
+ # Validate the embed lookup key
10
+ def validate_key(str)
11
+ str.to_s
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,37 @@
1
+ require 'cairo'
2
+
3
+ module Squib
4
+ # @api private
5
+ module Args
6
+
7
+ class HandSpecial
8
+ include ArgLoader
9
+
10
+ def initialize(card_height)
11
+ @card_height = card_height
12
+ end
13
+
14
+ def self.parameters
15
+ {
16
+ angle_range: (Math::PI / -4.0)..(Math::PI / 4),
17
+ radius: :auto
18
+ }
19
+ end
20
+
21
+ def self.expanding_parameters
22
+ [] # none of them
23
+ end
24
+
25
+ def self.params_with_units
26
+ [ :radius ]
27
+ end
28
+
29
+ def validate_radius(arg)
30
+ return 0.3 * @card_height if arg.to_s.downcase.strip == 'auto'
31
+ arg
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ require 'squib/args/arg_loader'
2
+
3
+ module Squib
4
+ # @api private
5
+ module Args
6
+
7
+ class InputFile
8
+ include ArgLoader
9
+
10
+ def initialize(dsl_method_default = {})
11
+ @dsl_method_default = dsl_method_default
12
+ end
13
+
14
+ def self.parameters
15
+ { file: nil,
16
+ sheet: 0,
17
+ }
18
+ end
19
+
20
+ def self.expanding_parameters
21
+ parameters.keys # all of them
22
+ end
23
+
24
+ def self.params_with_units
25
+ [] # none of them
26
+ end
27
+
28
+ def validate_file(arg, _i)
29
+ return nil if arg.nil?
30
+ raise "File #{File.expand_path(arg)} does not exist!" unless File.exists?(arg)
31
+ File.expand_path(arg)
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,44 @@
1
+ require 'cairo'
2
+ require 'squib/args/arg_loader'
3
+ require 'squib/args/color_validator'
4
+
5
+ module Squib
6
+ # @api private
7
+ module Args
8
+ class Paint
9
+ include ArgLoader
10
+ include ColorValidator
11
+
12
+ def self.parameters
13
+ { alpha: 1.0,
14
+ blend: :none,
15
+ mask: nil,
16
+ }
17
+ end
18
+
19
+
20
+ def self.expanding_parameters
21
+ parameters.keys # all of them are expandable
22
+ end
23
+
24
+ def self.params_with_units
25
+ []
26
+ end
27
+
28
+ def initialize(custom_colors)
29
+ @custom_colors = custom_colors
30
+ end
31
+
32
+ def validate_alpha(arg, _i)
33
+ raise 'alpha must respond to to_f' unless arg.respond_to? :to_f
34
+ arg.to_f
35
+ end
36
+
37
+ def validate_mask(arg, _i)
38
+ colorify(arg, @custom_colors)
39
+ end
40
+
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,115 @@
1
+ require 'squib/args/arg_loader'
2
+
3
+ module Squib
4
+ # @api private
5
+ module Args
6
+
7
+ class Paragraph
8
+ include ArgLoader
9
+
10
+
11
+ def self.parameters
12
+ { align: :left,
13
+ str: 'Hello, World!',
14
+ font: :use_set,
15
+ font_size: nil,
16
+ markup: false,
17
+ justify: false,
18
+ wrap: true,
19
+ ellipsize: :end,
20
+ spacing: nil,
21
+ valign: :top,
22
+ hint: :off
23
+ }
24
+ end
25
+
26
+ def self.expanding_parameters
27
+ parameters.keys # all of them
28
+ end
29
+
30
+ def self.params_with_units
31
+ [] # none of them
32
+ end
33
+
34
+ def initialize(deck_font)
35
+ @deck_font = deck_font
36
+ end
37
+
38
+ def validate_str(arg, _i)
39
+ arg.to_s
40
+ end
41
+
42
+ def validate_font(arg, _i)
43
+ arg = @deck_font if arg == :use_set
44
+ arg = Squib::SYSTEM_DEFAULTS[:default_font] if arg == :default
45
+ arg
46
+ end
47
+
48
+ def validate_align(arg, _i)
49
+ case arg.to_s.downcase.strip
50
+ when 'left'
51
+ Pango::ALIGN_LEFT
52
+ when 'right'
53
+ Pango::ALIGN_RIGHT
54
+ when 'center'
55
+ Pango::ALIGN_CENTER
56
+ else
57
+ raise ArgumentError, 'align must be one of: center, left, right'
58
+ end
59
+ end
60
+
61
+ def validate_wrap(arg, _i)
62
+ case arg.to_s.downcase.strip
63
+ when 'word'
64
+ Pango::Layout::WRAP_WORD
65
+ when 'char', 'false'
66
+ Pango::Layout::WRAP_CHAR
67
+ when 'word_char', 'true'
68
+ Pango::Layout::WRAP_WORD_CHAR
69
+ else
70
+ raise ArgumentError, 'wrap must be one of: word, char, word_char, true, or false'
71
+ end
72
+ end
73
+
74
+ def validate_ellipsize(arg, _i)
75
+ case arg.to_s.downcase.strip
76
+ when 'none', 'false'
77
+ Pango::Layout::ELLIPSIZE_NONE
78
+ when 'start'
79
+ Pango::Layout::ELLIPSIZE_START
80
+ when 'middle'
81
+ Pango::Layout::ELLIPSIZE_MIDDLE
82
+ when 'end', 'true'
83
+ Pango::Layout::ELLIPSIZE_END
84
+ else
85
+ raise ArgumentError, 'ellipsize must be one of: none, start, middle, end, true, or false'
86
+ end
87
+ end
88
+
89
+ def validate_justify(arg, _i)
90
+ case arg
91
+ when nil, true, false
92
+ arg
93
+ else
94
+ raise ArgumentError, 'justify must be one of: nil, true, or false'
95
+ end
96
+ end
97
+
98
+ def validate_spacing(arg, _i)
99
+ return nil if arg.nil?
100
+ raise ArgumentError, 'spacing must be a number or nil' unless arg.respond_to? :to_f
101
+ arg.to_f * Pango::SCALE
102
+ end
103
+
104
+ def validate_valign(arg, _i)
105
+ if %w(top middle bottom).include? arg.to_s.downcase
106
+ arg.to_s.downcase
107
+ else
108
+ raise ArgumentError, 'valign must be one of: top, middle, bottom'
109
+ end
110
+ end
111
+
112
+ end
113
+
114
+ end
115
+ end