squib 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +14 -0
  3. data/.travis.yml +4 -0
  4. data/CHANGELOG.md +201 -175
  5. data/Gemfile +2 -4
  6. data/README.md +650 -645
  7. data/RELEASE TODO.md +18 -18
  8. data/Rakefile +106 -99
  9. data/appveyor.yml +29 -0
  10. data/lib/squib.rb +32 -32
  11. data/lib/squib/api/background.rb +20 -20
  12. data/lib/squib/api/data.rb +131 -131
  13. data/lib/squib/api/image.rb +108 -90
  14. data/lib/squib/api/save.rb +151 -149
  15. data/lib/squib/api/settings.rb +35 -35
  16. data/lib/squib/api/shapes.rb +255 -230
  17. data/lib/squib/api/text.rb +65 -65
  18. data/lib/squib/api/text_embed.rb +96 -96
  19. data/lib/squib/args/arg_loader.rb +138 -138
  20. data/lib/squib/args/box.rb +54 -54
  21. data/lib/squib/args/card_range.rb +32 -32
  22. data/lib/squib/args/color_validator.rb +11 -11
  23. data/lib/squib/args/coords.rb +32 -32
  24. data/lib/squib/args/dir_validator.rb +16 -16
  25. data/lib/squib/args/draw.rb +92 -92
  26. data/lib/squib/args/embed_adjust.rb +25 -25
  27. data/lib/squib/args/embed_key.rb +17 -17
  28. data/lib/squib/args/hand_special.rb +37 -37
  29. data/lib/squib/args/import.rb +39 -39
  30. data/lib/squib/args/input_file.rb +37 -37
  31. data/lib/squib/args/paint.rb +43 -43
  32. data/lib/squib/args/paragraph.rb +116 -115
  33. data/lib/squib/args/save_batch.rb +63 -60
  34. data/lib/squib/args/scale_box.rb +53 -53
  35. data/lib/squib/args/sheet.rb +72 -72
  36. data/lib/squib/args/showcase_special.rb +38 -38
  37. data/lib/squib/args/svg_special.rb +37 -37
  38. data/lib/squib/args/transform.rb +60 -24
  39. data/lib/squib/args/typographer.rb +117 -117
  40. data/lib/squib/card.rb +66 -67
  41. data/lib/squib/conf.rb +131 -117
  42. data/lib/squib/constants.rb +12 -178
  43. data/lib/squib/deck.rb +113 -113
  44. data/lib/squib/graphics/cairo_context_wrapper.rb +113 -99
  45. data/lib/squib/graphics/gradient_regex.rb +46 -46
  46. data/lib/squib/graphics/hand.rb +42 -42
  47. data/lib/squib/graphics/image.rb +103 -76
  48. data/lib/squib/graphics/save_doc.rb +103 -103
  49. data/lib/squib/graphics/save_images.rb +39 -33
  50. data/lib/squib/graphics/shapes.rb +135 -119
  51. data/lib/squib/graphics/showcase.rb +85 -85
  52. data/lib/squib/graphics/text.rb +176 -176
  53. data/lib/squib/layout_parser.rb +91 -91
  54. data/lib/squib/layouts/economy.yml +85 -85
  55. data/lib/squib/layouts/fantasy.yml +101 -101
  56. data/lib/squib/layouts/hand.yml +62 -62
  57. data/lib/squib/layouts/playing-card.yml +35 -35
  58. data/lib/squib/layouts/tuck_box.yml +45 -45
  59. data/lib/squib/project_template/IDEAS.md +22 -0
  60. data/lib/squib/project_template/PLAYTESTING.md +26 -0
  61. data/lib/squib/project_template/RULES.md +21 -0
  62. data/lib/squib/project_template/config.yml +49 -45
  63. data/lib/squib/sample_helpers.rb +34 -0
  64. data/lib/squib/version.rb +10 -10
  65. data/samples/autoscale_font/_autoscale_font.rb +29 -0
  66. data/samples/color_shortcuts.rb +6 -6
  67. data/samples/csv_import.rb +26 -26
  68. data/samples/custom-config.yml +5 -5
  69. data/samples/custom_config.rb +18 -18
  70. data/samples/draw_shapes.rb +48 -45
  71. data/samples/embed_text.rb +88 -88
  72. data/samples/excel.rb +55 -55
  73. data/samples/hand.rb +24 -24
  74. data/samples/images/_images.rb +104 -0
  75. data/samples/intro/01_hello.rb +9 -0
  76. data/samples/intro/02_options.rb +15 -0
  77. data/samples/intro/03_layout.rb +12 -0
  78. data/samples/intro/04_arrays.rb +16 -0
  79. data/samples/intro/05_excel.rb +15 -0
  80. data/samples/layouts.rb +62 -62
  81. data/samples/layouts_builtin.rb +51 -51
  82. data/samples/load_images.rb +99 -78
  83. data/samples/load_images_config.yml +1 -0
  84. data/samples/quantity_explosion.csv +2 -2
  85. data/samples/ranges.rb +64 -64
  86. data/samples/sample.csv +2 -2
  87. data/samples/saves.rb +9 -1
  88. data/samples/sprites.png +0 -0
  89. data/samples/text/_text.rb +46 -0
  90. data/samples/text_options.rb +102 -102
  91. data/spec/api/api_data_spec.rb +117 -117
  92. data/spec/api/api_settings_spec.rb +37 -37
  93. data/spec/args/box_spec.rb +127 -127
  94. data/spec/args/draw_spec.rb +101 -95
  95. data/spec/args/embed_key_spec.rb +13 -13
  96. data/spec/args/input_file_spec.rb +21 -21
  97. data/spec/args/paint_spec.rb +21 -21
  98. data/spec/args/paragraph_spec.rb +152 -152
  99. data/spec/args/range_spec.rb +40 -40
  100. data/spec/args/save_batch_spec.rb +51 -51
  101. data/spec/args/scale_box_spec.rb +71 -71
  102. data/spec/args/sheet_spec.rb +58 -58
  103. data/spec/args/showcase_special_spec.rb +15 -15
  104. data/spec/args/transform_spec.rb +25 -0
  105. data/spec/card_spec.rb +11 -0
  106. data/spec/conf_spec.rb +13 -3
  107. data/spec/data/conf/unrecognized.yml +4 -0
  108. data/spec/data/csv/qty.csv +2 -2
  109. data/spec/data/csv/qty_named.csv +2 -2
  110. data/spec/data/csv/with_spaces.csv +2 -2
  111. data/spec/data/samples/autoscale_font.rb.txt +84 -84
  112. data/spec/data/samples/basic.rb.txt +227 -209
  113. data/spec/data/samples/config_text_markup.rb.txt +72 -72
  114. data/spec/data/samples/csv_import.rb.txt +213 -213
  115. data/spec/data/samples/custom_config.rb.txt +57 -48
  116. data/spec/data/samples/draw_shapes.rb.txt +555 -3
  117. data/spec/data/samples/embed_text.rb.txt +283 -283
  118. data/spec/data/samples/excel.rb.txt +661 -661
  119. data/spec/data/samples/gradients.rb.txt +77 -79
  120. data/spec/data/samples/hand.rb.txt +538 -538
  121. data/spec/data/samples/hello_world.rb.txt +36 -36
  122. data/spec/data/samples/load_images.rb.txt +170 -0
  123. data/spec/data/samples/portrait-landscape.rb.txt +51 -49
  124. data/spec/data/samples/ranges.rb.txt +472 -460
  125. data/spec/data/samples/saves.rb.txt +810 -801
  126. data/spec/data/samples/showcase.rb.txt +5926 -5910
  127. data/spec/data/samples/text_options.rb.txt +1125 -1125
  128. data/spec/data/samples/tgc_proofs.rb.txt +95 -81
  129. data/spec/graphics/cairo_context_wrapper_spec.rb +104 -84
  130. data/spec/graphics/graphics_save_doc_spec.rb +67 -67
  131. data/spec/samples/diff-with-css.example.html +39 -0
  132. data/spec/samples/expected/load_images_00.png +0 -0
  133. data/spec/samples/expected/shape_00.png +0 -0
  134. data/spec/samples/run_samples_spec.rb +17 -0
  135. data/spec/samples/samples_regression_spec.rb +72 -82
  136. data/spec/spec_helper.rb +9 -1
  137. data/squib.gemspec +49 -48
  138. data/squib.sublime-project +42 -42
  139. metadata +94 -48
  140. data/spec/graphics/graphics_images_spec.rb +0 -94
@@ -1,91 +1,91 @@
1
- require 'yaml'
2
-
3
- module Squib
4
- # Internal class for handling layouts
5
- #@api private
6
- class LayoutParser
7
-
8
- # Load the layout file(s), if exists
9
- # @api private
10
- def self.load_layout(files)
11
- layout = {}
12
- Squib::logger.info { " using layout(s): #{files}" }
13
- Array(files).each do |file|
14
- thefile = file
15
- thefile = builtin(file) unless File.exists?(file)
16
- if File.exists? thefile
17
- yml = layout.merge(YAML.load_file(thefile) || {}) #load_file returns false on empty file
18
- yml.each do |key, value|
19
- layout[key] = recurse_extends(yml, key, {})
20
- end
21
- else
22
- Squib::logger.error { "Layout file not found: #{file}. Skipping..." }
23
- end
24
- end
25
- return layout
26
- end
27
-
28
- # Determine the file path of the built-in layout file
29
- def self.builtin(file)
30
- "#{File.dirname(__FILE__)}/layouts/#{file}"
31
- end
32
-
33
- # Process the extends recursively
34
- # :nodoc:
35
- # @api private
36
- def self.recurse_extends(yml, key, visited )
37
- assert_not_visited(key, visited)
38
- return yml[key] unless has_extends?(yml, key)
39
- return yml[key] unless parents_exist?(yml, key)
40
- visited[key] = key
41
- parent_keys = [yml[key]['extends']].flatten
42
- h = {}
43
- parent_keys.each do |parent_key|
44
- from_extends = yml[key].merge(recurse_extends(yml, parent_key, visited)) do |key, child_val, parent_val|
45
- if child_val.to_s.strip.start_with?('+=')
46
- parent_val + child_val.sub('+=','').strip.to_f
47
- elsif child_val.to_s.strip.start_with?('-=')
48
- parent_val - child_val.sub('-=','').strip.to_f
49
- else
50
- child_val #child overrides parent when merging, no +=
51
- end
52
- end
53
- h = h.merge(from_extends) do |key, older_sibling, younger_sibling|
54
- younger_sibling #when two siblings have the same entry, the "younger" (lower one) overrides
55
- end
56
- end
57
- return h
58
- end
59
-
60
- # Does this layout entry have an extends field?
61
- # i.e. is it a base-case or will it need recursion?
62
- # :nodoc:
63
- # @api private
64
- def self.has_extends?(yml, key)
65
- !!yml[key] && yml[key].key?('extends')
66
- end
67
-
68
- # Checks if we have any absentee parents
69
- # @api private
70
- def self.parents_exist?(yml, key)
71
- exists = true
72
- Array(yml[key]['extends']).each do |parent|
73
- unless yml.key?(parent)
74
- exists = false unless
75
- Squib.logger.error "Processing layout: '#{key}' attempts to extend a missing '#{yml[key]['extends']}'"
76
- end
77
- end
78
- return exists
79
- end
80
-
81
- # Safeguard against malformed circular extends
82
- # :nodoc:
83
- # @api private
84
- def self.assert_not_visited(key, visited)
85
- if visited.key? key
86
- raise "Invalid layout: circular extends with '#{key}'"
87
- end
88
- end
89
-
90
- end
91
- end
1
+ require 'yaml'
2
+
3
+ module Squib
4
+ # Internal class for handling layouts
5
+ #@api private
6
+ class LayoutParser
7
+
8
+ # Load the layout file(s), if exists
9
+ # @api private
10
+ def self.load_layout(files)
11
+ layout = {}
12
+ Squib::logger.info { " using layout(s): #{files}" }
13
+ Array(files).each do |file|
14
+ thefile = file
15
+ thefile = builtin(file) unless File.exists?(file)
16
+ if File.exists? thefile
17
+ yml = layout.merge(YAML.load_file(thefile) || {}) #load_file returns false on empty file
18
+ yml.each do |key, value|
19
+ layout[key] = recurse_extends(yml, key, {})
20
+ end
21
+ else
22
+ Squib::logger.error { "Layout file not found: #{file}. Skipping..." }
23
+ end
24
+ end
25
+ return layout
26
+ end
27
+
28
+ # Determine the file path of the built-in layout file
29
+ def self.builtin(file)
30
+ "#{File.dirname(__FILE__)}/layouts/#{file}"
31
+ end
32
+
33
+ # Process the extends recursively
34
+ # :nodoc:
35
+ # @api private
36
+ def self.recurse_extends(yml, key, visited )
37
+ assert_not_visited(key, visited)
38
+ return yml[key] unless has_extends?(yml, key)
39
+ return yml[key] unless parents_exist?(yml, key)
40
+ visited[key] = key
41
+ parent_keys = [yml[key]['extends']].flatten
42
+ h = {}
43
+ parent_keys.each do |parent_key|
44
+ from_extends = yml[key].merge(recurse_extends(yml, parent_key, visited)) do |key, child_val, parent_val|
45
+ if child_val.to_s.strip.start_with?('+=')
46
+ parent_val + child_val.sub('+=','').strip.to_f
47
+ elsif child_val.to_s.strip.start_with?('-=')
48
+ parent_val - child_val.sub('-=','').strip.to_f
49
+ else
50
+ child_val #child overrides parent when merging, no +=
51
+ end
52
+ end
53
+ h = h.merge(from_extends) do |key, older_sibling, younger_sibling|
54
+ younger_sibling #when two siblings have the same entry, the "younger" (lower one) overrides
55
+ end
56
+ end
57
+ return h
58
+ end
59
+
60
+ # Does this layout entry have an extends field?
61
+ # i.e. is it a base-case or will it need recursion?
62
+ # :nodoc:
63
+ # @api private
64
+ def self.has_extends?(yml, key)
65
+ !!yml[key] && yml[key].key?('extends')
66
+ end
67
+
68
+ # Checks if we have any absentee parents
69
+ # @api private
70
+ def self.parents_exist?(yml, key)
71
+ exists = true
72
+ Array(yml[key]['extends']).each do |parent|
73
+ unless yml.key?(parent)
74
+ exists = false unless
75
+ Squib.logger.error "Processing layout: '#{key}' attempts to extend a missing '#{yml[key]['extends']}'"
76
+ end
77
+ end
78
+ return exists
79
+ end
80
+
81
+ # Safeguard against malformed circular extends
82
+ # :nodoc:
83
+ # @api private
84
+ def self.assert_not_visited(key, visited)
85
+ if visited.key? key
86
+ raise "Invalid layout: circular extends with '#{key}'"
87
+ end
88
+ end
89
+
90
+ end
91
+ end
@@ -1,85 +1,85 @@
1
- #This layout inspired by popular fantasy games
2
- title:
3
- x: 90
4
- y: 90
5
- width: 635
6
- height: 50
7
- align: center
8
-
9
- art:
10
- x: 75
11
- y: 150
12
- width: 675
13
- height: 520
14
-
15
- description:
16
- x: 100
17
- y: 675
18
- width: 625
19
- height: 275
20
- valign: middle
21
- align: center
22
- font_size: 18
23
- desc: # alias
24
- extends: description
25
-
26
- type:
27
- x: 90
28
- y: 955
29
- width: 645
30
- height: 50
31
- align: center
32
-
33
- lower_right:
34
- x: 675
35
- y: 975
36
- width: 75
37
- height: 75
38
- font_size: 18
39
- valign: bottom
40
- align: right
41
- lr: #alias
42
- extends: lower_right
43
-
44
- lower_left:
45
- x: 75
46
- y: 975
47
- width: 75
48
- height: 75
49
- font_size: 18
50
- valign: bottom
51
- align: left
52
- ll: # alias
53
- extends: lower_left
54
-
55
- copyright:
56
- x: 75
57
- y: 1025
58
- width: 675
59
- height: 25
60
- font_size: 16
61
- align: center
62
- valign: bottom
63
- #aliases for copyright
64
- copy:
65
- extends: copyright
66
- credit:
67
- extends: copyright
68
- credits:
69
- extends: copyright
70
-
71
- # The "cut line", without rounded corners
72
- cut:
73
- x: 37.5
74
- y: 37.5
75
- width: 750
76
- height: 1050
77
-
78
- # The "safe zone" as defined by TheGameCrafter poker cards
79
- safe:
80
- x: 75
81
- y: 75
82
- width: 675
83
- height: 975
84
- radius: 16
85
- dash: 3 3
1
+ #This layout inspired by popular fantasy games
2
+ title:
3
+ x: 90
4
+ y: 90
5
+ width: 635
6
+ height: 50
7
+ align: center
8
+
9
+ art:
10
+ x: 75
11
+ y: 150
12
+ width: 675
13
+ height: 520
14
+
15
+ description:
16
+ x: 100
17
+ y: 675
18
+ width: 625
19
+ height: 275
20
+ valign: middle
21
+ align: center
22
+ font_size: 18
23
+ desc: # alias
24
+ extends: description
25
+
26
+ type:
27
+ x: 90
28
+ y: 955
29
+ width: 645
30
+ height: 50
31
+ align: center
32
+
33
+ lower_right:
34
+ x: 675
35
+ y: 975
36
+ width: 75
37
+ height: 75
38
+ font_size: 18
39
+ valign: bottom
40
+ align: right
41
+ lr: #alias
42
+ extends: lower_right
43
+
44
+ lower_left:
45
+ x: 75
46
+ y: 975
47
+ width: 75
48
+ height: 75
49
+ font_size: 18
50
+ valign: bottom
51
+ align: left
52
+ ll: # alias
53
+ extends: lower_left
54
+
55
+ copyright:
56
+ x: 75
57
+ y: 1025
58
+ width: 675
59
+ height: 25
60
+ font_size: 16
61
+ align: center
62
+ valign: bottom
63
+ #aliases for copyright
64
+ copy:
65
+ extends: copyright
66
+ credit:
67
+ extends: copyright
68
+ credits:
69
+ extends: copyright
70
+
71
+ # The "cut line", without rounded corners
72
+ cut:
73
+ x: 37.5
74
+ y: 37.5
75
+ width: 750
76
+ height: 1050
77
+
78
+ # The "safe zone" as defined by TheGameCrafter poker cards
79
+ safe:
80
+ x: 75
81
+ y: 75
82
+ width: 675
83
+ height: 975
84
+ radius: 16
85
+ dash: 3 3
@@ -1,101 +1,101 @@
1
- #This layout inspired by popular fantasy games
2
- title:
3
- x: 90
4
- y: 90
5
- width: 500
6
- height: 50
7
-
8
- upper_right:
9
- x: 595
10
- y: 90
11
- width: 135
12
- height: 50
13
- align: right
14
- ur: # alias
15
- extends: upper_right
16
-
17
- art:
18
- x: 75
19
- y: 150
20
- width: 675
21
- height: 520
22
-
23
- type:
24
- x: 90
25
- y: 675
26
- width: 500
27
- height: 50
28
-
29
- type_right:
30
- x: 595
31
- y: 675
32
- width: 135
33
- height: 50
34
- align: right
35
- tr: #alias
36
- extends: type_right
37
-
38
- description:
39
- x: 100
40
- y: 730
41
- width: 625
42
- height: 275
43
- valign: middle
44
- align: center
45
- font_size: 18
46
- desc: # alias
47
- extends: description
48
-
49
- lower_right:
50
- x: 675
51
- y: 975
52
- width: 75
53
- height: 75
54
- font_size: 18
55
- valign: bottom
56
- align: right
57
- lr: #alias
58
- extends: lower_right
59
-
60
- lower_left:
61
- x: 75
62
- y: 975
63
- width: 75
64
- height: 75
65
- font_size: 18
66
- valign: bottom
67
- align: left
68
- ll: # alias
69
- extends: lower_left
70
-
71
- copyright:
72
- x: 75
73
- y: 1025
74
- width: 675
75
- height: 25
76
- font_size: 16
77
- align: center
78
- valign: bottom
79
- #aliases for copyright
80
- copy:
81
- extends: copyright
82
- credit:
83
- extends: copyright
84
- credits:
85
- extends: copyright
86
-
87
- # The "cut line", without rounded corners
88
- cut:
89
- x: 37.5
90
- y: 37.5
91
- width: 750
92
- height: 1050
93
-
94
- # The "safe zone" as defined by TheGameCrafter poker cards
95
- safe:
96
- x: 75
97
- y: 75
98
- width: 675
99
- height: 975
100
- radius: 16
101
- dash: 3 3
1
+ #This layout inspired by popular fantasy games
2
+ title:
3
+ x: 90
4
+ y: 90
5
+ width: 500
6
+ height: 50
7
+
8
+ upper_right:
9
+ x: 595
10
+ y: 90
11
+ width: 135
12
+ height: 50
13
+ align: right
14
+ ur: # alias
15
+ extends: upper_right
16
+
17
+ art:
18
+ x: 75
19
+ y: 150
20
+ width: 675
21
+ height: 520
22
+
23
+ type:
24
+ x: 90
25
+ y: 675
26
+ width: 500
27
+ height: 50
28
+
29
+ type_right:
30
+ x: 595
31
+ y: 675
32
+ width: 135
33
+ height: 50
34
+ align: right
35
+ tr: #alias
36
+ extends: type_right
37
+
38
+ description:
39
+ x: 100
40
+ y: 730
41
+ width: 625
42
+ height: 275
43
+ valign: middle
44
+ align: center
45
+ font_size: 18
46
+ desc: # alias
47
+ extends: description
48
+
49
+ lower_right:
50
+ x: 675
51
+ y: 975
52
+ width: 75
53
+ height: 75
54
+ font_size: 18
55
+ valign: bottom
56
+ align: right
57
+ lr: #alias
58
+ extends: lower_right
59
+
60
+ lower_left:
61
+ x: 75
62
+ y: 975
63
+ width: 75
64
+ height: 75
65
+ font_size: 18
66
+ valign: bottom
67
+ align: left
68
+ ll: # alias
69
+ extends: lower_left
70
+
71
+ copyright:
72
+ x: 75
73
+ y: 1025
74
+ width: 675
75
+ height: 25
76
+ font_size: 16
77
+ align: center
78
+ valign: bottom
79
+ #aliases for copyright
80
+ copy:
81
+ extends: copyright
82
+ credit:
83
+ extends: copyright
84
+ credits:
85
+ extends: copyright
86
+
87
+ # The "cut line", without rounded corners
88
+ cut:
89
+ x: 37.5
90
+ y: 37.5
91
+ width: 750
92
+ height: 1050
93
+
94
+ # The "safe zone" as defined by TheGameCrafter poker cards
95
+ safe:
96
+ x: 75
97
+ y: 75
98
+ width: 675
99
+ height: 975
100
+ radius: 16
101
+ dash: 3 3