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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e26629b35f921713b8003d6ece20b788c5789645
4
- data.tar.gz: 06b9837f88b86f6e4ddde9f9a2c603b6992a26e8
3
+ metadata.gz: 744aff036f28e351288af081a51ee69a10a02c38
4
+ data.tar.gz: 79d15605f836489bf85c3635b43c421bea4902fb
5
5
  SHA512:
6
- metadata.gz: c003650e034993f12f72a7a58dc781b8e64aea6989081d5cd09683cf49179adac35e7887bb4b3274c9829eb70f08c4912b615d5495fa18fd28cacf49cc319809
7
- data.tar.gz: 4d308545d618bb3f2d56481eade0d27e60985c169444007d255079b74344e38d050facab2aa905c4786a2b9950171e6ef95b83b512c502c89dc3e144aa558347
6
+ metadata.gz: c2f48683c4abfb922e6e8501d308363635acff8dc75e5612ed50b6ce0e19eae7d5063c86b448157808bc4344ddef585c6218570b5f7bf923526906c7158a15e1
7
+ data.tar.gz: 51180a1a1125f90a78a355d83426474c15b4bc2cb50c688600f44c8b312ff06fa5caffe5f7403028683e9daf9a7ebd7f883f863d8ab8b9b2e0f9b764fe9906d5
@@ -1,133 +1,162 @@
1
- # Squib CHANGELOG
2
- Squib follows [semantic versioning](http://semver.org).
3
-
4
- ## v0.6.0 / Unreleased
5
-
6
- Features:
7
- * Added `data` field to `svg` to allow for manipulating SVG XML data directly. Works nicely with my new `game_icons` [gem](https://github.com/andymeneely/game_icons) (#65)
8
- * Added `stroke_width` and `stroke_color` to the `text` method to outlines text. (#51)
9
- * Added `hand` method that draws cards around a circle. See hand.rb samples (#64)
10
- * Added an `ellipse` method to (you guessed it) draw ellipses. See the draw_shapes.rb sample (#66)
11
- * Added a `star` method to (you guessed it) draw stars. See the draw_shapes.rb sample (#72)
12
- * Added a `polygon` method to (you guessed it) draw polygons. See the draw_shapes.rb sample (#67)
13
- * Upgraded roo (Excel parsing) to 2.0.0. Nothing major for Squib users, just keeping up with the times.
14
-
15
- Bugs:
16
- * Text embed svg and png commands default to integer so the README example works (#73).
17
- * Fixed global text hinting (#63)
18
- * Fixed a broken promise about fill_color in `showcase` (#71)
19
-
20
- Compatbility:
21
- * rsvg2 and pango updated to v2.2.5. Squib follows 2.2.x of both of those. If you run `bundle` you will automatically be upgraded. They appear to be mostly bugfix releases.
22
- * dpi is currently removed from `config.yml` and is ONLY available in `Squib::Deck.new`. This may change in the future, however.
23
-
24
- Chores:
25
- * Massive internal redesigning of the way configuration options are parsed, stored, handled. No real changes are visible to the user, but this code will be more maintainable and open up the door for more flexible configuration options in the future.
26
- * Added `rake sanity` as a visual regression test to ensure the samples don't break
27
- * Lots of automated test refactoring
28
-
29
- Thanks to [pickfifteen](https://github.com/pickfifteen), and [Brian Cronin](http://www.boardgamegeek.com/user/MurphyIdiot) for the bug reports!
30
-
31
- ## v0.5.1 / 2015-04-13
32
-
33
- Bugs:
34
- * Fixed a PDF scaling issue, so now page width and height is properly calculated from DPI (#62)
35
-
36
- Thanks to [Brian Cronin](http://www.boardgamegeek.com/user/MurphyIdiot) for the bug report.
37
-
38
- ## v0.5.0 / 2015-04-13
39
- Features:
40
- * Embedding of SVGs and PNGs into text! See README, `text_options.rb`, and `embed_text.rb`, and API documentation. This was a finnicky feature, so feedback and bug reports are welcome. (#30)
41
- * Curves! We can now do Bezier curves. Documented, and added to the sample `draw_shapes.rb` (#37).
42
- * Smart Quotes! The `text` rule now has a `quotes: 'smart'` option where straight quotes get converted to curly quotes. Assumes UTF-8, or you can specify your own quote characters if you're not in UTF-8. (#50)
43
- * Font-level antialiasing is inherited from global antialiasing setting (workaround until we get a better solution for #59).
44
-
45
- Known issues
46
- * OSX Yosemite will show this warning: `<Error>: The function ‘CGFontGetGlyphPath’ is obsolete and will be removed in an upcoming update. Unfortunately, this application, or a library it uses, is using this obsolete function, and is thereby contributing to an overall degradation of system performance.` This warning will go away when the Ruby Cairo bindings upgrades from 1.14.1 to 1.14.2.
47
-
48
- Special thanks to [pickfifteen](https://github.com/pickfifteen) for testing, feedback, and pull requests!!
49
-
50
- ## v0.4.0 / 2015-04-28
51
-
52
- Features:
53
- * SVG backend support! You can now set the deck's back end to work with SVGs instead of images, making the resulting PDFs vectorized. (You can still save to PNGs too.) This was a big change for Squib, and it's got at least one known issue and probably a few more here and there. See discussion on the README for more details.
54
- * Added config option for antialiasing method. My benchmarks showed that 'best' is only 10% slower than 'fast' on extremely alias-intensive tasks, so 'best' is the Squib default now.
55
-
56
- Bugs:
57
- * Stray stroke on circles after text (#35)
58
- * Progress bar increment error (#34)
59
-
60
- Known issues
61
- * Masking SVGs onto an SVG backend will rasterize as an intermediate step. (#43)
62
- * Compatibility change: gradient coordinates for the `mask` option in `svg` and `png` commands are relative to the given x,y - NOT to card as it was before.
63
-
64
- ## v0.3.0 / 2015-02-02
65
-
66
- Features:
67
- * Masks! The `png` and `svg` commands can be used as if they are a mask, so you can color the icon with any color you like. Can be handy for switching to black-and-white, or for reusing the same image but different colors across cards.
68
- * Gradients! Can now specify linear or radial gradients anywhere you specify colors. See README and `samples/gradients.rb` for more details.
69
- * Number padding! `save_png` will now pad zeros on the filenames for friendlier sorting. You can also specify your own with `count_format` using the classical format string from Ruby's `Kernel::sprintf` (mostly just C-style format strings). Default: `'%02d'. The `prefix:` option is still there too.
70
- * Added unit conversion to `Squib::New` and `save_pdf`
71
- * Added arbitrary paper sizes to `save_pdf`
72
- * Added new sample table for color viewing constants in `samples/colors.rb`
73
-
74
- Special thanks to [Shalom Craimer](https://github.com/scraimer) for the idea and proof-of-concept on gradient and mask features!
75
-
76
- ## v0.2.0 / 2015-01-12
77
-
78
- Features:
79
- * Added `showcase` feature to create a fancy-looking 3D reflection to showcase your cards. Documented, tested, and added a sample for it.
80
- * Added a basic Rakefile, documented in README.
81
- * Some internal refactoring, better testing, and more documentation with layouts
82
-
83
- ## v0.1.0 / 2014-12-31
84
-
85
- Features:
86
- * Added `save_sheet` command that saves a range into PNG sheets, complete with trim, gap, margin, columns, and sometimes automagically computed rows. See samples/saves.rb.
87
- * Unit conversion! Now you can write "2in" and it will convert based on the current dpi. `save_pdf` not supported (yet).
88
- * `png` now supports resizing, but warns you about it since it's non-ideal. Documented in yard, tested.
89
- * Added sample `unicode.rb` to show lots of game-related unicode characters
90
-
91
- Chores:
92
- * More obsessive automated testing and continuous integration work.
93
-
94
- ## v0.0.6 / 2014-12-08
95
-
96
- Features:
97
- * Added a `csv` command that works just like `xslx`. Uses Ruby's CSV inside, with some extra checking and warnings.
98
- * Custom layouts now support loading & merging multiple Yaml files! Updated README, docs, and sample to document it.
99
- * Built-in layouts! Currently we support `hand.yml` and `playing-card.yml`. Documented in the `layouts.rb` sample.
100
- * `text` now returns the ink extent rectangle of the rendered text. Updated docs and sample to document it.
101
- * Samples now show that you can use text instead of symbols for things like `center`
102
-
103
- Chores:
104
- * Improved logging, and documentation on increasing logger verboseness
105
- * Better regression testing technique that tracks when a sample has changed.
106
- * Bumped version of Cairo to ~> 1.14
107
-
108
- ## v0.0.5 / 2014-11-03
109
- * Image rotation for png and svg via `angle`
110
- * New sample for demonstrating direct cairo access
111
- * README now includes a snazzy screencast of the Sublime snippets
112
- * Rotation of text works more conventionally now, and works with text hints
113
- * Better code styles thanks to RuboCop
114
- * Better unit testing, now with mocking!
115
- * Various version bumps: rspec, yard
116
-
117
- ## v0.0.4 / 2014-10-17
118
- * Added a font size override so you can vary the font size with the same style across strings more easily
119
- * Added text autoscale sample
120
- * Added `extends` to custom layouts, allowing ways to modify parent data instead of just overriding it.
121
- * Upgraded ruby-progressbar version
122
- * Added text rotation (thanks novalis!)
123
- * Fixed a mapping problem with triangles (thanks novalis!)
124
- * Fixed global hint togglability
125
-
126
- ## v0.0.3 / 2014-08-30
127
- * Redesigned the dynamic options system to make adding new commands much easier
128
- * Singleton expansion
129
- * Better documentation in README and throughout
130
- * Implemented Junk Land in this version
131
-
132
- ## v0.0.1-v0.0.2 / 2014-07-29
133
- * Primordial era - base functionality
1
+ # Squib CHANGELOG
2
+ Squib follows [semantic versioning](http://semver.org).
3
+
4
+ ## v0.7.0 / Unreleased
5
+
6
+ Features
7
+ * Added `cap` option to `line` and `curve` to define how ends of lines are drawn (#42)
8
+ * Added `join` option to all drawing operations (e.g. `rect`, `star`, even outlines for `text`) to define how corners are drawn. (#42)
9
+ * Added `dash` option to all drawing operations (e.g. `rect`, `star`, even outlines for `text`) so you can specify your own dash pattern. Just specify a string with space-separated numbers to specify the on-and-off alternating pattern (e.g. `dash: '2 2'` with a stroke width of `2` is evenly spaced dots). Supports unit conversion (e.g. `dash: '0.02in 0.02in'`) (#42)
10
+ * Added an idiom to the `ranges.rb` sample for drawing a different number of images based on the column in a table (e.g. 2 arrows to indicate 2 actions). Based on question #90. There are probably even cleaner, Ruby-ish ways to do this too - pull requests are welcome.
11
+ * The `text` method and several other methods will throw errors on invalid input. This means your scripts will be more likely to break if you provide bad input. Please report bugs if you thinkg this unfairly breaks your code.
12
+ * The `text` embedding icon now allows singleton expansion, which means that you can have icons have different sizes on different cards. The sample `embed_text.rb` demonstrates this. (#54)
13
+ * The `text` method will throw a warning when it needs to ellipsize text (i.e. too much text for a fixed-size text box). Can be turned off in `config.yml`. (#80)
14
+ * Upgraded roo (Excel parsing) to 2.1.0. Macro-enabled Excel files can be parsed now (i.e. `xlsm`), although I've only mildly tested this. (cddea47ba56add286639e493d5cc0146245eca68)
15
+ * New built-in layouts: `fantasy.yml` and `economy.yml`. Demonstrated in new sample `layouts_builtin.rb` (#97)
16
+ * Added `:scale` shortcut to `width` and `height` options for `png` and `svg`. Allows you to set the width and the image will scale while keeping its aspect ratio. (e.g. `svg width: 500, height: :scale`) (#91)
17
+ * Upgraded cairo dependency to 1.14.3, which silences some warnings on Macs and upgrades a lot of Windows dependencies.
18
+ * Upgraded pango, librsvg dependencies to 3.0.0, which focused mainly on upgrading Windows dependencies.
19
+
20
+ Compatibility:
21
+ * All drawn shapes (e.g. circle, triangle, star) will now draw their stroke on top of the fill. This was not consistent before, and now it is (because Squib is more DRY about it!). This means that your `stroke_width` might render wider than before. If you want the other behavior, specify `stroke_strategy: :stroke_first`. Also applies to `text` when `stroke_width` is specified.
22
+ * The `width` and `height` options for `text` have changed their defaults from `:native` to `:auto`. This is to differentiate them from `:native` widths that default elsewhere. Additionally, `width` and `height` for shapes now default to `:deck`, and get interpreted as the deck width and height. The `:native` options are interpreted for SVG and PNG images as their original values. The behavior is all the same, just with more specific names.
23
+ * Removed `img_dir` from the `set` method. You can still set `img_dir` in the configuration file (e.g. `config.yml`). Added a deprecation error.
24
+
25
+ Bugs:
26
+ * Fixed a `Cairo::WriteError` on `save_sheet` (#56, PR #96 thank you @meltheadorable!)
27
+ * Investigated a NoMemoryError on Macs. Solution: upgrade to Ruby 2.2. (#88)
28
+
29
+ Chores:
30
+ * Refactoring to make internal drawing code more DRY (#75, and much more). This is a big re-design that will help ease future features that involve manipulating arguments. Trust me. This was worth the wait and all the hard work.
31
+ * Better testing and general flexibility around the `range` option.
32
+
33
+ ## v0.6.0 / 2015-05-26
34
+
35
+ Features:
36
+ * Added `data` field to `svg` to allow for manipulating SVG XML data directly. Works nicely with my new `game_icons` [gem](https://github.com/andymeneely/game_icons) (#65)
37
+ * Added `stroke_width` and `stroke_color` to the `text` method to outlines text. (#51)
38
+ * Added `hand` method that draws cards around a circle. See hand.rb samples (#64)
39
+ * Added an `ellipse` method to (you guessed it) draw ellipses. See the draw_shapes.rb sample (#66)
40
+ * Added a `star` method to (you guessed it) draw stars. See the draw_shapes.rb sample (#72)
41
+ * Added a `polygon` method to (you guessed it) draw polygons. See the draw_shapes.rb sample (#67)
42
+ * Upgraded roo (Excel parsing) to 2.0.0. Nothing major for Squib users, just keeping up with the times.
43
+
44
+ Bugs:
45
+ * Text embed svg and png commands default to integer so the README example works (#73).
46
+ * Fixed global text hinting (#63)
47
+ * Fixed a broken promise about fill_color in `showcase` (#71)
48
+
49
+ Compatbility:
50
+ * rsvg2 and pango updated to v2.2.5. Squib follows 2.2.x of both of those. If you run `bundle` you will automatically be upgraded. They appear to be mostly bugfix releases.
51
+ * dpi is currently removed from `config.yml` and is ONLY available in `Squib::Deck.new`. This may change in the future, however.
52
+
53
+ Chores:
54
+ * Massive internal redesigning of the way configuration options are parsed, stored, handled. No real changes are visible to the user, but this code will be more maintainable and open up the door for more flexible configuration options in the future.
55
+ * Added `rake sanity` as a visual regression test to ensure the samples don't break
56
+ * Lots of automated test refactoring
57
+
58
+ Thanks to [pickfifteen](https://github.com/pickfifteen), and [Brian Cronin](http://www.boardgamegeek.com/user/MurphyIdiot) for the bug reports!
59
+
60
+ ## v0.5.1 / 2015-04-13
61
+
62
+ Bugs:
63
+ * Fixed a PDF scaling issue, so now page width and height is properly calculated from DPI (#62)
64
+
65
+ Thanks to [Brian Cronin](http://www.boardgamegeek.com/user/MurphyIdiot) for the bug report.
66
+
67
+ ## v0.5.0 / 2015-04-13
68
+ Features:
69
+ * Embedding of SVGs and PNGs into text! See README, `text_options.rb`, and `embed_text.rb`, and API documentation. This was a finnicky feature, so feedback and bug reports are welcome. (#30)
70
+ * Curves! We can now do Bezier curves. Documented, and added to the sample `draw_shapes.rb` (#37).
71
+ * Smart Quotes! The `text` rule now has a `quotes: 'smart'` option where straight quotes get converted to curly quotes. Assumes UTF-8, or you can specify your own quote characters if you're not in UTF-8. (#50)
72
+ * Font-level antialiasing is inherited from global antialiasing setting (workaround until we get a better solution for #59).
73
+
74
+ Known issues
75
+ * OSX Yosemite will show this warning: `<Error>: The function ‘CGFontGetGlyphPath’ is obsolete and will be removed in an upcoming update. Unfortunately, this application, or a library it uses, is using this obsolete function, and is thereby contributing to an overall degradation of system performance.` This warning will go away when the Ruby Cairo bindings upgrades from 1.14.1 to 1.14.2.
76
+
77
+ Special thanks to [pickfifteen](https://github.com/pickfifteen) for testing, feedback, and pull requests!!
78
+
79
+ ## v0.4.0 / 2015-04-28
80
+
81
+ Features:
82
+ * SVG backend support! You can now set the deck's back end to work with SVGs instead of images, making the resulting PDFs vectorized. (You can still save to PNGs too.) This was a big change for Squib, and it's got at least one known issue and probably a few more here and there. See discussion on the README for more details.
83
+ * Added config option for antialiasing method. My benchmarks showed that 'best' is only 10% slower than 'fast' on extremely alias-intensive tasks, so 'best' is the Squib default now.
84
+
85
+ Bugs:
86
+ * Stray stroke on circles after text (#35)
87
+ * Progress bar increment error (#34)
88
+
89
+ Known issues
90
+ * Masking SVGs onto an SVG backend will rasterize as an intermediate step. (#43)
91
+ * Compatibility change: gradient coordinates for the `mask` option in `svg` and `png` commands are relative to the given x,y - NOT to card as it was before.
92
+
93
+ ## v0.3.0 / 2015-02-02
94
+
95
+ Features:
96
+ * Masks! The `png` and `svg` commands can be used as if they are a mask, so you can color the icon with any color you like. Can be handy for switching to black-and-white, or for reusing the same image but different colors across cards.
97
+ * Gradients! Can now specify linear or radial gradients anywhere you specify colors. See README and `samples/gradients.rb` for more details.
98
+ * Number padding! `save_png` will now pad zeros on the filenames for friendlier sorting. You can also specify your own with `count_format` using the classical format string from Ruby's `Kernel::sprintf` (mostly just C-style format strings). Default: `'%02d'. The `prefix:` option is still there too.
99
+ * Added unit conversion to `Squib::New` and `save_pdf`
100
+ * Added arbitrary paper sizes to `save_pdf`
101
+ * Added new sample table for color viewing constants in `samples/colors.rb`
102
+
103
+ Special thanks to [Shalom Craimer](https://github.com/scraimer) for the idea and proof-of-concept on gradient and mask features!
104
+
105
+ ## v0.2.0 / 2015-01-12
106
+
107
+ Features:
108
+ * Added `showcase` feature to create a fancy-looking 3D reflection to showcase your cards. Documented, tested, and added a sample for it.
109
+ * Added a basic Rakefile, documented in README.
110
+ * Some internal refactoring, better testing, and more documentation with layouts
111
+
112
+ ## v0.1.0 / 2014-12-31
113
+
114
+ Features:
115
+ * Added `save_sheet` command that saves a range into PNG sheets, complete with trim, gap, margin, columns, and sometimes automagically computed rows. See samples/saves.rb.
116
+ * Unit conversion! Now you can write "2in" and it will convert based on the current dpi. `save_pdf` not supported (yet).
117
+ * `png` now supports resizing, but warns you about it since it's non-ideal. Documented in yard, tested.
118
+ * Added sample `unicode.rb` to show lots of game-related unicode characters
119
+
120
+ Chores:
121
+ * More obsessive automated testing and continuous integration work.
122
+
123
+ ## v0.0.6 / 2014-12-08
124
+
125
+ Features:
126
+ * Added a `csv` command that works just like `xslx`. Uses Ruby's CSV inside, with some extra checking and warnings.
127
+ * Custom layouts now support loading & merging multiple Yaml files! Updated README, docs, and sample to document it.
128
+ * Built-in layouts! Currently we support `hand.yml` and `playing-card.yml`. Documented in the `layouts.rb` sample.
129
+ * `text` now returns the ink extent rectangle of the rendered text. Updated docs and sample to document it.
130
+ * Samples now show that you can use text instead of symbols for things like `center`
131
+
132
+ Chores:
133
+ * Improved logging, and documentation on increasing logger verboseness
134
+ * Better regression testing technique that tracks when a sample has changed.
135
+ * Bumped version of Cairo to ~> 1.14
136
+
137
+ ## v0.0.5 / 2014-11-03
138
+ * Image rotation for png and svg via `angle`
139
+ * New sample for demonstrating direct cairo access
140
+ * README now includes a snazzy screencast of the Sublime snippets
141
+ * Rotation of text works more conventionally now, and works with text hints
142
+ * Better code styles thanks to RuboCop
143
+ * Better unit testing, now with mocking!
144
+ * Various version bumps: rspec, yard
145
+
146
+ ## v0.0.4 / 2014-10-17
147
+ * Added a font size override so you can vary the font size with the same style across strings more easily
148
+ * Added text autoscale sample
149
+ * Added `extends` to custom layouts, allowing ways to modify parent data instead of just overriding it.
150
+ * Upgraded ruby-progressbar version
151
+ * Added text rotation (thanks novalis!)
152
+ * Fixed a mapping problem with triangles (thanks novalis!)
153
+ * Fixed global hint togglability
154
+
155
+ ## v0.0.3 / 2014-08-30
156
+ * Redesigned the dynamic options system to make adding new commands much easier
157
+ * Singleton expansion
158
+ * Better documentation in README and throughout
159
+ * Implemented Junk Land in this version
160
+
161
+ ## v0.0.1-v0.0.2 / 2014-07-29
162
+ * Primordial era - base functionality
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
- gemspec
3
-
4
- gem 'yard', :git => 'git://github.com/lsegal/yard', :branch => "master"
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'yard', :git => 'git://github.com/lsegal/yard', :branch => "master"
data/README.md CHANGED
@@ -1,550 +1,630 @@
1
- # Squib [![Gem Version](https://badge.fury.io/rb/squib.svg)](https://rubygems.org/gems/squib) [![Build Status](https://secure.travis-ci.org/andymeneely/squib.svg?branch=master)](https://travis-ci.org/andymeneely/squib) [![Dependency Status](https://gemnasium.com/andymeneely/squib.svg)](https://gemnasium.com/andymeneely/squib) [![Coverage Status](https://img.shields.io/coveralls/andymeneely/squib.svg)](https://coveralls.io/r/andymeneely/squib) [![Inline docs](http://inch-ci.org/github/andymeneely/squib.png?branch=master)](http://inch-ci.org/github/andymeneely/squib)
2
- Squib is a Ruby [DSL](http://en.wikipedia.org/wiki/Domain-specific_language) for prototyping card and board games. Write a little bit of Ruby, define your deck's stats, then compile your game into a series of images ready for print-and-play or even print-on-demand. Squib is very data-driven and built on the principle of Don't Repeat Yourself. Think of it like [nanDeck](http://www.nand.it/nandeck/) done "the Ruby way". Squib supports:
3
-
4
- * A concise set of rules for laying out your cards
5
- * Loading PNGs and SVGs
6
- * Complex text rendering using [Pango](http://www.pango.org/)
7
- * Reading `xlsx` and `csv` files
8
- * Rendering to PNGs, PDFs, and SVGs (sheets or individual files)
9
- * Flexible, data-driven layouts in Yaml
10
- * Basic shape drawing, blending operators, gradients, etc.
11
- * Unit conversion
12
- * The full power of Ruby!
13
-
14
- Squib is based on the [Cairo](http://cairographics.org/) graphics rendering engine, the library of choice for WebKit, Gecko, Inkscape and many, many others.
15
-
16
- Check this out.
17
-
18
- ```ruby
19
- require 'squib'
20
-
21
- Squib::Deck.new(cards: 2) do
22
- text str: %w(Hello World!)
23
- save_png
24
- end
25
- ```
26
-
27
- We just created a 2-card deck with "Hello" on the first card, and "World" on the second, and saved them out to PNGs.
28
-
29
- ## Installation
30
-
31
- Install it yourself with:
32
-
33
- $ gem install squib
34
-
35
- If you're using Bundler, add this line to your application's Gemfile:
36
-
37
- gem 'squib'
38
-
39
- And then execute:
40
-
41
- $ bundle
42
-
43
- Note: Squib has some native dependencies, such as [Cairo](https://github.com/rcairo/rcairo), [Pango](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Pango%3A%3ALayout), and [Nokogiri](http://nokogiri.org/), which may require compiling C code to install. This is usually not painful at all, but can cause headaches on some setups.
44
- * Windows: I *strongly* recommend using the *non-64 bit* RubyInstaller at http://rubyinstaller.org along with installing DevKit.
45
- * Mac: I recommend using [rvm](https://rvm.io).
46
- * Cywgin is not 100% supported, but could potentially work with extra installation steps. See [this thread](http://boardgamegeek.com/article/18508113#18508113)
47
-
48
- Squib requires Ruby 2.0 or later.
49
-
50
- ## Getting Started
51
-
52
- After installing Squib, you can create a project and run your first build like this:
53
-
54
- ```sh
55
- $ squib new my-cool-game
56
- $ cd my-cool-game
57
- $ ruby deck.rb
58
- ```
59
-
60
- The `squib new` command will generate files and folders like this:
61
-
62
- ```
63
- _output/gitkeep.txt
64
- .gitignore
65
- ABOUT.md
66
- config.yml
67
- deck.rb
68
- Gemfile
69
- layout.yml
70
- PNP NOTES.md
71
- ```
72
-
73
- The central file here is `deck.rb`. Here's a [basic example](https://github.com/andymeneely/squib/tree/master/samples/basic.rb) of a deck to work from:
74
-
75
- {include:file:samples/basic.rb basic.rb}
76
-
77
- About the other files:
78
- * `Gemfile` is for adding in other gems if you are using `bundler`
79
- * `config.yml` is a skeleton config file with various options commented out. See {file:README.md#Configuration_File Configuration File}.
80
- * `layout.yml` is a skeleton layout file if you want to use it. See {file:README.md#Custom_Layouts Custom Layouts}.
81
- * `_output` is the directory where your built files will go. Can easily be changed, of course.
82
- * `.gitignore` and `gitkeep.txt` are for if you are using Git. See {file:README.md#Source_control Source control}. (Feel free to remove these if you are not using Git.)
83
- * `ABOUT.md` and `PHP NOTES.md` are Markdown files for posting. Not used by Squib, but there by convention.
84
- * `Rakefile` is a basic build file. Not required but handy - see {file:README.md#Rakefile Rakefile}
85
-
86
- # Learning Squib
87
-
88
- In addition to this README, be sure to also check out the following resources for more details:
89
-
90
- * The `samples` directory in the [source repository](https://github.com/andymeneely/squib) has lots of examples.
91
- * [Iconoclast](https://github.com/andymeneely/iconoclast) is a basic set collection game I'm developing from scratch with Squib. Be sure to read the [commit history](https://github.com/andymeneely/iconoclast/commits/master) to see how the game has developed from scratch.
92
- * [Junk Land](https://github.com/andymeneely/junk-land) is my own creation that's uses Squib for full-color rendering, and makes use of Ruby in a lot of interesting ways.
93
-
94
- ## Viewing this README
95
-
96
- The best place to read this documentation is on [our website](http://andymeneely.github.io/squib/doc). Be sure to check out the method-by-method documentation, particularly for the [Deck](Squib/Deck.html) class.
97
-
98
- If you want to view it offline, you can do the following
99
-
100
- ```sh
101
- $ gem install yard
102
- $ yard server --gems
103
- ```
104
- Then go to [http://localhost:8808/docs/squib/file/README.md](http://localhost:8808/docs/squib/file/README.md)
105
-
106
- If you're viewing this on Github, you might see some confusing tags like `{include:file:...}` - these are directives for YARD to show the embedded examples. Github doesn't render those and you might find them helpful.
107
-
108
- Also, RubyDoc.info linked from RubyGems appears to be perpetually broken and doesn't support `{include:file...}` directive properly, so the embedded samples will also not show up there, either.
109
-
110
- ## Squib Decks and Cards
111
-
112
- The Squib DSL is based on a collection of methods provided to the `Squib::Deck` class. The general philosophy of Squib is to specify as little as possible with layers of defaults, highly flexible input, and good ol' Ruby duck-typing. Ruby does a lot to make Squib useful.
113
-
114
- Squib essentially has two main classes: `Deck` and `Card`. `Deck` is the front-end, and `Card` is the back-end. The contract of `Deck` is to do the various manipulations of options and then delegate the operation to `Card` to do the low-level graphical operations.
115
-
116
- For most users, I recommending solely using `Deck` methods. If you want to roll up your sleeves and get your hands messy, you can access the Cairo or Pango contexts the directly via the `Card` class. The API documentation doesn't really cover these, however, so you're on your own there.
117
-
118
- ## Specifying Parameters
119
-
120
- Squib is all about sane defaults and shorthand specification. Arguments are almost always using hashes, which look a lot like [Ruby 2.0's named parameters](http://www.ruby-doc.org/core-2.0.0/doc/syntax/calling_methods_rdoc.html#label-Keyword+Arguments). This means you can specify your parameters in any order you please. All parameters are optional. For example `x` and `y` default to 0 (i.e. the upper-left corner of the card). Any parameter that is specified in the command overrides any Squib defaults, `config.yml` settings, or layout rules.
121
-
122
- Note: you MUST use named parameters rather than positional parameters. For example: `save :png` will lead to an error like this:
123
-
124
- C:/Ruby200/lib/ruby/gems/2.0.0/gems/squib-0.0.3/lib/squib/api/save.rb:12:in `save': wrong number of arguments (2 for 0..1) (ArgumentError)
125
- from deck.rb:22:in `block in <main>'
126
- from C:/Ruby200/lib/ruby/gems/2.0.0/gems/squib-0.0.3/lib/squib/deck.rb:60:in `instance_eval'
127
- from C:/Ruby200/lib/ruby/gems/2.0.0/gems/squib-0.0.3/lib/squib/deck.rb:60:in `initialize'
128
- from deck.rb:18:in `new'
129
- from deck.rb:18:in `<main>'
130
-
131
- Instead, you must name the parameters: `save format: :png`
132
-
133
- ## Arrays and Singleton Expansion
134
-
135
- Many inputs to Squib can accept `Arrays`, which correspond to the entire deck. In fact, under the hood, if Squib is _not_ given an array, it expands it out to an array before rendering. This allows for different styles to apply to different cards. This example comes from the [ranges.rb example](https://github.com/andymeneely/squib/tree/master/samples/ranges.rb)
136
-
137
- ```ruby
138
- # This renders three cards, with three strings that had three different colors at three different locations.
139
- text str: %w(red green blue),
140
- color: [:red, :green, :blue],
141
- x: [40, 80, 120],
142
- y: [700, 750, 800]
143
- ```
144
-
145
- Under the hood, Squib actually views every argument as applied each card individually. If a single argument is given to the command, it's considered a singleton that gets expanded into a deck-sized array. Supplying the array bypasses that expansion - which means that any array you supply instead of a singleton ought to be the same size as the deck and align the same way the indexes in the supplied `range` are. If you don't, Ruby will fill that up with nils and not apply the rule across those cards.
146
-
147
- ## Specifying Ranges
148
-
149
- Most public `Deck` methods allow a `range` to be specified as a first parameter. This parameter is used to access an internal `Array` of `Squib::Cards`. This can be an actual Ruby range, or anything that implements `#each` (thus can be an `Enumerable`). Integers are also supported for changing one card only. Negatives work from the back of the deck. Here are some examples from `samples/ranges.rb` found [here](https://github.com/andymeneely/squib/tree/master/samples/ranges.rb)
150
-
151
- {include:file:samples/ranges.rb}
152
-
153
- ## Units
154
-
155
- By default, Squib thinks in pixels. This decision was made so that we can have pixel-perfect layouts without automatically scaling everything, even though working in units is sometimes easier. We provide some conversion methods, including looking for strings that end in "in" and "cm" and computing based on the current DPI. The dpi is set on `Squib::Deck.new` (not `config.yml`). Example is in `samples/units.rb` found [here](https://github.com/andymeneely/squib/tree/master/samples/units.rb)
156
-
157
- {include:file:samples/units.rb}
158
-
159
- ## Specifying Colors & Gradients
160
-
161
- Colors can be specified in a wide variety of ways, mostly in a hex-string. Take a look at the examples from `samples/colors.rb`, found [here](https://github.com/andymeneely/squib/tree/master/samples/colors.rb)
162
-
163
- {include:file:samples/colors.rb}
164
-
165
- Under the hood, Squib uses the `rcairo` [color parser](https://github.com/rcairo/rcairo/blob/master/lib/cairo/color.rb) to accept a variety of color specifications, along with over [300 pre-defined constants](https://github.com/rcairo/rcairo/blob/master/lib/cairo/colors.rb). The above sample will generate a table of such constants.
166
-
167
- Additionally, in most places where colors are allowed, you may also supply a string that defines a gradient. Squib supports two flavors of gradients: linear and radial. Gradients are specified by supplying some xy coordinates, which are relative to the card (not the command). Each stop must be between 0.0 and 1.0, and you can supply as many as you like. Colors can be specified as above (in any of the hex notations or built-in constant). If you add two (or more) colors at the same stop, then the gradient keeps the colors in the in order specified and treats it like sharp transition.
168
-
169
- The format for gradient strings look like this:
170
-
171
- Linear:
172
- ```
173
- (x1,y1)(x2,y2) color1@stop1 color2@stop2
174
- ```
175
- The xy coordinates define the angle of the gradient.
176
-
177
- Radial:
178
- ```
179
- (x1,y1,radius1)(x2,y2,radius2) color1@stop1 color2@stop2
180
- ```
181
- The coordinates specify an inner circle first, then an outer circle.
182
-
183
- Check out the following sample from `samples/gradients.rb`, found [here](https://github.com/andymeneely/squib/tree/master/samples/colors.rb)
184
-
185
- {include:file:samples/gradients.rb}
186
-
187
- ## Specifying Files
188
-
189
- All files opened for reading or writing (e.g. for `png` and `xlsx`) are opened relative to the current directory. Files opened for writing (e.g. for `save_png`) will be overwritten without warning.
190
-
191
- If you find that you `cd` a lot while working on the command line, your `_output` folder might get generated in multiple places. An easy way to fix this is to use a `Rakefile`, [see below](#Rakefile)
192
-
193
- ## Working with Text
194
- The `text` method is a particularly powerful method with a ton of options. Be sure to check the [API docs](docs/Squib/Deck#text-instance_method) on an option-by-option discussion, but here are the highlights.
195
-
196
- **Fonts**. The font is specified in a given Pango "font string", which can involve a ton of options embedded there in the string. In addition to the typical bold and italic variations, you can also specify all-caps, the specific boldness weight (e.g. 900), or go with oblique. These options are only available if the underlying font supports them, however. Here's are some example Pango font strings:
197
-
198
- ```
199
- Sans 18
200
- Arial,Verdana weight=900 style=oblique 36
201
- Times New Roman,Sans 25
202
- ```
203
-
204
- Note: When the font has a space it, you'll need to put a backup to get Pango's parsing to work.
205
-
206
- It's also important to note that most of the font rendering is done by a combination of your installed fonts, your OS, and your graphics card. Thus, different systems will render text slightly differently.
207
-
208
- Furthermore, options like `font_size` allow you to override the font string. This means that you can set a blanket font for the whole deck, then adjust sizes from there. This is useful with layouts and `extends` too.
209
-
210
- ### Width and Height
211
-
212
- By default, Pango text boxes will scale the text box to whatever you need, hence the `:native` default. However, for most of the other customizations to work (e.g. center-aligned) you'll need to specify the width. If both the width and the height are specified and the text overflows, then the `ellipsize` option is consulted to figure out what to do with the overflow. Also, the `valign` will only work if `height` is also set to something other than `:native`.
213
-
214
- ###Hints
215
-
216
- Laying out text by typing in numbers can be confusing. What Squib calls "hints" is merely a rectangle around the text box. Hints can be turned on globally in the config file, using the `set` method, or in an individual text method. These are there merely for prototyping and are not intended for production. Additionally, these are not to be conflated with "rendering hints" that Pango and Cairo mention in their documentation.
217
-
218
- ###Extents
219
-
220
- Sometimes you want size things based on the size of your rendered text. For example, drawing a rectangle around card's title such that the rectangle perfectly fits. Squib returns the final rendered size of the text so you can work with it afterward. It's an array of hashes that correspond to each card. The output looks like this:
221
-
222
- ```ruby
223
- Squib::Deck.new(cards: 2) do
224
- extents = text(str: ['Hello', 'World!'])
225
- p extents
226
- end
227
- ```
228
- Will output:
229
- ```
230
- [{:width=>109, :height=>55}, {:width=>142, :height=>55}] # Hello was 109 pixels wide, World 142 pixels
231
- ```
232
-
233
- ###Embedding Images
234
-
235
- Squib can embed icons into the flow of text. To do this, you need to define text keys for Squib to look for, and then the corresponding files. The object given to the block is a [TextEmbed](docs/Squib/TextEmbed), which supports PNG and SVG. Here's a minimal example:
236
-
237
- ```ruby
238
- text(str: 'Gain 1 :health:') do |embed|
239
- embed.svg key: ':health:', file: 'heart.svg'
240
- end
241
- ```
242
-
243
- ###Markup
244
-
245
- If you want to do specialized formatting within a given string, Squib has lots of options. By setting `markup: true`, you enable tons of text processing. This includes:
246
-
247
- * Pango Markup. This is an HTML-like formatting language that specifies formatting inside your string. Pango Markup essentially supports any formatting option, but on a letter-by-letter basis. Such as: font options, letter spacing, gravity, color, etc. See the [Pango docs](https://developer.gnome.org/pango/stable/PangoMarkupFormat.html) for details.
248
- * Quotes are converted to their curly counterparts where appropriate (i.e. &ldquo;smart quotes&rdquo; instead of "straight quotes").
249
- * Apostraphes are converted to curly as well.
250
- * LaTeX-style quotes are explicitly converted (<tt>``like this''</tt>)
251
- * Em-dash and en-dash are converted with triple and double-dashes respectively (<tt>--</tt> is an en-dash, and <tt>---</tt> becomes an em-dash.)
252
- * Ellipses can be specified with <tt>...</tt>. Note that this is entirely different from the `ellipsize` option (which determines what to do with overflowing text).
253
-
254
- A few notes:
255
- * Smart quoting assumes the UTF-8 character set.
256
- * Pango markup uses an XML/HTML-ish processor. Some characters require HTML-entity escaping (e.g. `&amp;` for `&')
257
-
258
- ### Text Sample
259
- ```yaml
260
- lsquote: "\u2018" #note that Yaml wants double quotes here to use escape chars
261
- rsquote: "\u2019"
262
- ldquote: "\u201C"
263
- rdquote: "\u201D"
264
- em_dash: "\u2014"
265
- en_dash: "\u2013"
266
- ellipsis: "\u2026"
267
- ```
268
-
269
- You can also disable the auto-quoting mechanism by setting `smart_quotes: false` in your config. Explicit replacements will still be performed.
270
-
271
- ### Text Samples
272
-
273
- Examples of all of the above are crammed into the `text_options.rb` sample [found here](https://github.com/andymeneely/squib/tree/master/samples/text_options.rb).
274
-
275
- {include:file:samples/text_options.rb}
276
-
277
- The `embed_text.rb` sample has more examples of embedding text, which can be [found here](https://github.com/andymeneely/squib/tree/master/samples/embed_text.rb).
278
-
279
- {include:file:samples/embed_text.rb}
280
-
281
- The `config_text_markup.rb` sample demonstrates how quoting can be configured, [found here](https://github.com/andymeneely/squib/tree/master/samples/config_text_markup.rb)
282
-
283
- {include:file:samples/config_text_markup.rb}
284
-
285
-
286
- ## Custom Layouts
287
-
288
- Working with x-y coordinates all the time can be tiresome, and ideally everything in a game prototype should be data-driven and easily changed. For this, many Squib methods allow for a `layout` to be set. In essence, layouts are a way of setting default values for any argument given to the command.
289
-
290
- To use a layout, set the `layout:` option on a `Deck.new` command to point to a YAML file. Any command that allows a `layout` option can be set with a Ruby symbol or String, and the command will then load the specified `x`, `y`, `width`, and `height`. The individual command can also override these options.
291
-
292
- Instead of this:
293
- ```ruby
294
- # deck.rb
295
- Squib::Deck.new(layout: 'custom-layout.yml') do
296
- rect x: 75, y: 75, width: 675, height: 975
297
- end
298
- ```
299
-
300
- You can put your logic in the layout file and reference them:
301
- ```yaml
302
- # custom-layout.yml
303
- frame:
304
- x: 75
305
- y: 75
306
- width: 975
307
- height: 675
308
- ```
309
- Then your script looks like this:
310
- ```ruby
311
- # deck.rb
312
- Squib::Deck.new(layout: 'custom-layout.yml') do
313
- rect layout: 'frame'
314
- end
315
- ```
316
- The goal is to make your Ruby code more separate data from logic, which in turn makes your code more readable and maintainable. With `extends` (see below), layouts become even more powerful in keeping you from repeating yourself.
317
-
318
- Note: YAML is very finnicky about not allowing tab characters. Use two spaces for indentation instead. If you get a `Psych` syntax error, this is likely the culprit. Indendation is also strongly enforced in Yaml too. See the [Yaml docs](http://www.yaml.org/YAML_for_ruby.html).
319
-
320
- ### Order of Precedence
321
-
322
- Layouts will override Squib's system defaults, but are overriden by anything specified in the command itself. Thus, the order of precedence looks like this:
323
-
324
- * Use what the command specified
325
- * If anything was not yet specified, use what was given in a layout (if a layout was specified in the command and the file was given to the Deck)
326
- * If still anything was not yet specified, use what was given in Squib's defaults.
327
-
328
- ### Special key: `extends`
329
-
330
- Squib provides a way of reusing layouts with the special `extends` key. When defining an `extends` key, we can merge in another key and modify data coming in if we want to. This allows us to do things like place text next to an icon and be able to move them with each other. Like this:
331
-
332
- ```yaml
333
- # If we change the xy of attack, we move defend too!
334
- attack:
335
- x: 100
336
- y: 100
337
- radius: 100
338
- defend:
339
- extends: attack
340
- x: += 50
341
- #defend now is {:x => 150, :y => 100}
342
- ```
343
-
344
- If you want to extend multiple parents, it looks like this:
345
-
346
- ```yaml
347
- socrates:
348
- x: 100
349
- plato:
350
- y: 200
351
- aristotle:
352
- extends:
353
- - socrates
354
- - plato
355
- x: += 50
356
- ```
357
- If multiple keys override the same keys in a parent, the later ("younger") child takes precedent.
358
-
359
- Note that extends keys are similar to Yaml's ["merge keys"](http://www.yaml.org/YAML_for_ruby.html#merge_key). With merge keys, you can define base styles in one entry, then include those keys elsewhere. For example:
360
-
361
- ```yaml
362
- icon: &icon
363
- width: 50
364
- height: 50
365
- icon_left
366
- <<: *icon
367
- x: 100
368
- # The layout for icon_left will have the width/height from icon!
369
- ```
370
-
371
- If you use both `extends` and Yaml merge keys, the Yaml merge keys are processed first, then extends. For clarity, however, you're probably just better off using `extends` exclusively.
372
-
373
- ### Multiple layout files
374
-
375
- Squib also supports the combination of multiple layout files. If you provide an `Array` of files then Squib will merge them sequentially. Colliding keys will be completely re-defined by the later file. Extends is processed after _each file_. Here's a complex example:
376
-
377
- ```yaml
378
- # load order: a.yml, b.yml
379
-
380
- ##############
381
- # file a.yml #
382
- ##############
383
- grandparent:
384
- x: 100
385
- parent_a:
386
- extends: grandparent
387
- x: += 10 # evaluates to 110
388
- parent_b:
389
- extends: grandparent
390
- x: += 20 # evaluates to 120
391
-
392
- ##############
393
- # file b.yml #
394
- ##############
395
- child_a:
396
- extends: parent_a # i.e. extends a layout in a separate file
397
- x: += 3 # evaluates to 113 (i.e 110 + 3)
398
- parent_b: # redefined
399
- extends: grandparent
400
- x: += 30 # evaluates to 130 (i.e. 100 + 30)
401
- child_b:
402
- extends: parent_b
403
- x: += 3 # evaluates to 133 (i.e. 130 + 3)
404
- ```
405
-
406
- This can be helpful for:
407
- * Creating a base layout for structure, and one for color (for easier color/black-and-white switching)
408
- * Sharing base layouts with other designers
409
-
410
- YAML merge keys are NOT supported across multiple files - use `extends` instead.
411
-
412
- ### Built-in Layout Files
413
-
414
- If your layout file is not found in the current directory, Squib will search for its own set of layout files (here's the latest the development version [on GitHub](https://github.com/andymeneely/squib/tree/master/lib/squib/layouts). See the `layouts.rb` sample found [here](https://github.com/andymeneely/squib/tree/master/samples/) for some demonstrative examples.
415
-
416
- ### Layout Sample
417
- This sample demonstrates many different ways of using and combining layouts. This is the `layouts.rb` sample found [here](https://github.com/andymeneely/squib/tree/master/samples/)
418
-
419
- {include:file:samples/layouts.rb}
420
-
421
- ## Backends: Raster vs. Vector
422
- Under the hood, Cairo has the ability to support a variety of surfaces to draw on, including both raster images stored in memory and vectors stored in SVG files. Thus, Squib supports the ability to handle both. They are options in the configuration file `backend: memory` or `backend: svg`.
423
-
424
- If you save to a PDF then the backend will determine how your cards are saved too. For `memory`, the PDF will be filled with compressed raster images and be a larger file (yet it will still print at high quality... see discussion below). For SVG backends, PDFs will be smaller. If you have your deck backed by SVG, then the cards are auto-saved, so there is no `save_svg` in Squib. (Technically, the operations are stored and then flushed to the SVG file at the very end.)
425
-
426
- There are trade-offs that one should consider here.
427
-
428
- * _Print quality is **higher** for raster images_. This seems counterintuitive at first, but consider where Squib sits in your workflow. It's the final assembly line for your cards before they get printed. Cairo puts _a ton_ of work into rendering each pixel perfectly when it works with raster images. Printers, on the other hand, don't think in vectors and will render your paths in their own memory with their own embedded libraries without putting a lot of work into antialiasing and various other graphical esoterica. You may notice that print-on-demand companies such as The Game Crafter [only accept raster file types](https://www.thegamecrafter.com/help/supported-file-types), because they don't want their customers complaining about printers not rendering vectors with enough care.
429
- * _PDFs are **smaller** for SVG back ends_. If file size is a limitation for you, and it can be for some printers or internet forums, then an SVG back end for vectorized PDFs is the way to go.
430
- * _Squib is **greedy** with memory_. While I've tested Squib with big decks on older computers, the `memory` backend is quite greedy with RAM. If memory is at a premium for you, switching to SVG might help.
431
-
432
- Note: you can still load PNGs into an SVG-backed deck and load SVGs into a memory-backed deck. To me, the sweet spot is to keep all of my icons, text, and other stuff in vector form for infinite scaling and then render them all to pixels with Squib.
433
-
434
- Fortunately, switching backends in Squib should be as trivial as changing the setting in the config file. So go ahead and experiment with both and see what works for you. See below for how the configuration options work.
435
-
436
- ## Configuration File
437
-
438
- Squib supports various configuration properties that can be specified in an external file. The `config:` option in `Deck.new` can specify an optional configuration file in YML format. The properties there are intended to be immutable for the life of the Deck. The options include:
439
-
440
- * `progress_bars` (Boolean, default: false). When set to `true`, long-running operations will show a progress bar on the command line.
441
- * `hint` (ColorString, default: off). Text hints are used to show the boundaries of text boxes. Can be enabled/disabled for individual commands, or set globally with the `set` command. This setting is overriden by `set` and individual commands.
442
- * `custom_colors` (Hash of Colors, default: {}). Defines globally-available colors available to the deck that can be specified in commands.
443
- * `antialias` (`fast, good, best, none, gray, subpixel`, default: best). Set the algorithm that Cairo will use for antialiasing. Using our benchmarks on large decks, `best` is only ~10% slower anyway. For more info see the [Cairo docs](http://www.cairographics.org/manual/cairo-cairo-t.html#cairo-antialias-t).
444
- * `backend` (`svg` or `memory`, default: `memory`). Defines how Cairo will store the operations. Memory is recommended for higher quality rendering.
445
- * `prefix` (default: `card_`). When using an SVG backend, cards are auto-saved with this prefix and `"%02d"` numbering format.
446
-
447
- For debugging/sanity purposes, if you want to make sure your configuration options are parsed correclty, the above options are also available as methods within Squib::Deck, for example:
448
-
449
- ```ruby
450
- Squib::Deck.new do
451
- puts backend # prints 'memory' by default
452
- end
453
- ```
454
-
455
- The following sample demonstrates the config file, found [here](https://github.com/andymeneely/squib/tree/master/samples/)
456
-
457
- {include:file:samples/custom_config.rb}
458
-
459
- ## Importing from Excel and CSV
460
-
461
- Squib supports importing data from `xlsx` files and `csv` files. These methods are column-based, which means that they assume you have a header row in your table, and that header row will define the column. Squib will return a `Hash` of `Arrays` correspoding to each row. Warnings are thrown on things like duplicate columns. See the `excel.rb` and the `csv_import.rb` sample found [here](https://github.com/andymeneely/squib/tree/master/samples/).
462
-
463
- {include:file:samples/excel.rb}
464
-
465
- Of course, you can always import your game data other ways using just Ruby. There's nothing special about Squib's methods other than their convenience.
466
-
467
- ## Making Squib Verbose
468
-
469
- By default, Squib's logger is set to WARN, but more fine-grained logging is embedded in the code. To set the logger, just put this at the top of your script:
470
-
471
- ```ruby
472
- Squib::logger.level = Logger::INFO
473
- ```
474
-
475
- If you REALLY want to see tons of output, you can also set DEBUG, but that's not intended for general consumption.
476
-
477
- ## Staying DRY
478
-
479
- Squib tries to keep you DRY (Don't Repeat Yourself) with the following features:
480
-
481
- * Custom layouts allow you to specify various arguments in a separate file. This is great for x-y coordinates and alignment properties that would otherwise clutter up perfectly readable code. Squib goes even further and has a special "extends" that works especially well for grouped-together styles.
482
- * Flexible ranges and array handling: the `range` parameter in Squib is very flexible, meaning that one `text` command can specify different text in different fonts, styles, colors, etc. for each card. If you find yourself doing multiple `text` command for the same field across different ranges of cards, there's probably a better way to condense.
483
- * Custom colors keep you from hardcoding magic color strings everywhere. Custom colors go into `config.yml` file.
484
- * Plus, you know, Ruby.
485
-
486
- ## Source control
487
-
488
- You are using source control, right??
489
-
490
- By default, Squib assumes Git. But it's not dogmatic about it. Tracking your progress, backing up, sharing data, topic branches, release management, and reverting into history are just some of the many, many useful things you can do with source control. For me, I tend to ignore any auto-generated files in my output folder, but version control everything else. I also try to keep my graphics vector files, so the files stay small. Version control is intended for source code, so large binary files that change often probably should not get checked in unless absolutely necessary. I tend to keep big raster graphics files (e.g. from Gimp) in cloud storage or elsewhere.
491
-
492
- ## SublimeText
493
-
494
- Using SublimeText? I like you already. I've written up some Squib snippets to ease remembering Squib commands. It's called `Squib Snippets` on Package Control. Compatible with SublimeText 3. Source code is also [on Github](https://github.com/andymeneely/sublime-squib) (contributions welcome!). Check it out:
495
-
496
- ![Sublime Squib Snippets](https://raw.githubusercontent.com/andymeneely/squib/screencasts/sublime-squib-snippets.gif)
497
-
498
- ## Decks with multiple orientations or sizes
499
-
500
- If you want to make a deck that has some portrait and some landscape cards, I recommend you use multiple `Squib::Deck`s. The pixel size of a given card is designed to not change thorughout the life of a `Squib::Deck`. To work with landscape cards, there is a `rotate` option on `save_png` so you can render your print-on-demand PNGs in portrait but keep everything else oriented toward landscape. The following example demonstrates how to do this, found [here](https://github.com/andymeneely/squib/tree/master/samples/portrait-landscape.rb).
501
-
502
- {include:file:samples/portrait-landscape.rb}
503
-
504
- ## Rakefile
505
-
506
- When you run `squib new`, you are given a basic Rakefile. At this stage of Squib, it's basically just a shortcut for `ruby deck.rb`. But, even in this simple form this Rakefile has some advantages:
507
-
508
- * If you're in a subdirectory at the time, `rake` will simply traverse up and `cd` to the proper directory so you don't get rogue `_output` directories
509
- * If you find yourself building multiple decks, you can make your own tasks for each one individually, or all (e.g. `rake marketing`)
510
- * Don't need the `require squib` at the top of your code (although that breaks `ruby deck.rb`, so that's probably a bad idea)
511
-
512
- ## Using Google Sheets
513
-
514
- We don't officially support Google Sheets ([yet](https://github.com/andymeneely/squib/issues/49)), but [this Gist](https://gist.github.com/pickfifteen/aeee73ec2ce162b0aee8) might be helpful in automatically exporting the CSV.
515
-
516
- # Get Involved
517
-
518
- Squib is an open source tool, and I welcome participation. Squib is currently in pre-release alpha, so the API is still maturing. I do change my mind about the names and meaning of things at this stage. I will document these changes as best as I can. I also highly recommend upgrading to new versions of Squib every chance you get (using Bundler).
519
-
520
- Feel free to [file a bug or feature request](https://github.com/andymeneely/squib/issues). For bugs, a minimal code example along with your OS and Ruby details would be ideal.
521
-
522
- ## Testing Pre-Builds
523
-
524
- If you want to test new features as I develop them, you can always point your Gemfile to the repository. Your Gemfile specification looks like this:
525
-
526
- ```ruby
527
- gem 'squib', git: 'git://github.com/andymeneely/squib', branch: 'dev'
528
- ```
529
- * The `dev` branch is where I am working on features in-process. I have not done much regression testing at this point, but would love testing feedback nonetheless.
530
- * The `master` branch is where I consider features and bug that are done and tested, but not released yet.
531
-
532
- ## Contributing
533
-
534
- If you want your code integrated:
535
-
536
- 1. Fork the git repository ( https://github.com/[my-github-username]/squib/fork )
537
- 2. Create your feature branch (`git checkout -b my-new-feature`)
538
- 3. Commit your changes (`git commit -am 'Add some feature'`)
539
- 4. Push to the branch (`git push origin my-new-feature`)
540
- 5. Create a new Pull Request
541
-
542
- Be sure to run the unit tests and packaging with just `rake`. Also, you can check that the samples render properly with `rake sanity`.
543
-
544
- # What's up the with the name?
545
-
546
- Truthfully, I just thought it was a cool, simple word that was not used much in the Ruby community nor the board game community. But, now that I've committed to the name, I've realized that:
547
-
548
- * Squibs are small explosive devices, much like Squib "explodes" your rules into a playable game
549
- * Squibs are often used in heist movies, leading to a sudden plot twist that often resembles the twists of good tabletop game
550
- * Squibs are also part of the Harry Potter world - they are people who are non-magical but wizard-born. Squib is aware of wizarding magic and comes from that heritage, but it's not magical itself.
1
+ # Squib [![Gem Version](https://badge.fury.io/rb/squib.svg)](https://rubygems.org/gems/squib) [![Build Status](https://secure.travis-ci.org/andymeneely/squib.svg?branch=master)](https://travis-ci.org/andymeneely/squib) [![Dependency Status](https://gemnasium.com/andymeneely/squib.svg)](https://gemnasium.com/andymeneely/squib) [![Coverage Status](https://img.shields.io/coveralls/andymeneely/squib.svg)](https://coveralls.io/r/andymeneely/squib) [![Inline docs](http://inch-ci.org/github/andymeneely/squib.png?branch=master)](http://inch-ci.org/github/andymeneely/squib)
2
+ Squib is a Ruby [DSL](http://en.wikipedia.org/wiki/Domain-specific_language) for prototyping card and board games. Write a little bit of Ruby, define your deck's stats, then compile your game into a series of images ready for print-and-play or even print-on-demand. Squib is very data-driven and built on the principle of Don't Repeat Yourself. Think of it like [nanDeck](http://www.nand.it/nandeck/) done "the Ruby way". Squib supports:
3
+
4
+ * A concise set of rules for laying out your cards
5
+ * Loading PNGs and SVGs
6
+ * Complex text rendering using [Pango](http://www.pango.org/)
7
+ * Reading `xlsx` and `csv` files
8
+ * Rendering to PNGs, PDFs, and SVGs (sheets or individual files)
9
+ * Flexible, data-driven layouts in Yaml
10
+ * Basic shape drawing, blending operators, gradients, etc.
11
+ * Unit conversion
12
+ * The full power of Ruby!
13
+
14
+ Squib is based on the [Cairo](http://cairographics.org/) graphics rendering engine, the library of choice for WebKit, Gecko, Inkscape and many, many others.
15
+
16
+ Check this out.
17
+
18
+ ```ruby
19
+ require 'squib'
20
+
21
+ Squib::Deck.new(cards: 2) do
22
+ text str: %w(Hello World!)
23
+ save_png
24
+ end
25
+ ```
26
+
27
+ We just created a 2-card deck with "Hello" on the first card, and "World" on the second, and saved them out to PNGs.
28
+
29
+ ## Installation
30
+
31
+ Squib requires Ruby 2.0 or later.
32
+
33
+ Install it yourself with:
34
+
35
+ $ gem install squib
36
+
37
+ If you're using Bundler, add this line to your application's Gemfile:
38
+
39
+ gem 'squib'
40
+
41
+ And then execute:
42
+
43
+ $ bundle
44
+
45
+ Note: Squib has some native dependencies, such as [Cairo](https://github.com/rcairo/rcairo), [Pango](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Pango%3A%3ALayout), and [Nokogiri](http://nokogiri.org/), which may require compiling C code to install. This is usually not painful at all, and is automated through Bundler/RubyGems, but can cause headaches on some setups.
46
+ * Windows: I recommend using the *non-64 bit* RubyInstaller at http://rubyinstaller.org. Some installations will also need DevKit. Currently, Ruby 2.2 on Windows conflicts with one of Squib's dependencies called Nokogiri (read the WTF-y issue here: https://github.com/sparklemotion/nokogiri/issues/1256), so I recommend 2.1 or 2.0 for Windows users.
47
+ * Mac: I recommend using [rvm](https://rvm.io). Some users have reported that Ruby 2.1 will not work with Mac OSX 10.10.4 (#88) - Ruby 2.0 and 2.2 are confirmed to work however (this is an rcairo issue, not a Squib issue).
48
+ * Cywgin is not supported, but could theoretically work with extra installation steps. See [this thread](http://boardgamegeek.com/article/18508113#18508113). Contributions in this area are welcome.
49
+ * Linux. No known installation issues. Happy installing!
50
+
51
+ ## Getting Started
52
+
53
+ After installing Squib, you can create a project and run your first build like this:
54
+
55
+ ```sh
56
+ $ squib new my-cool-game
57
+ $ cd my-cool-game
58
+ $ ruby deck.rb
59
+ ```
60
+
61
+ The `squib new` command will generate files and folders like this:
62
+
63
+ ```
64
+ _output/gitkeep.txt
65
+ .gitignore
66
+ ABOUT.md
67
+ config.yml
68
+ deck.rb
69
+ Gemfile
70
+ layout.yml
71
+ PNP NOTES.md
72
+ ```
73
+
74
+ The central file here is `deck.rb`. Here's a [basic example](https://github.com/andymeneely/squib/tree/master/samples/basic.rb) of a deck to work from:
75
+
76
+ {include:file:samples/basic.rb basic.rb}
77
+
78
+ About the other files:
79
+ * `Gemfile` is for adding in other gems if you are using `bundler`
80
+ * `config.yml` is a skeleton config file with various options commented out. See {file:README.md#Configuration_File Configuration File}.
81
+ * `layout.yml` is a skeleton layout file if you want to use it. See {file:README.md#Custom_Layouts Custom Layouts}.
82
+ * `_output` is the directory where your built files will go. Can easily be changed, of course.
83
+ * `.gitignore` and `gitkeep.txt` are for if you are using Git. See {file:README.md#Source_control Source control}. (Feel free to remove these if you are not using Git.)
84
+ * `ABOUT.md` and `PHP NOTES.md` are Markdown files for posting. Not used by Squib, but there by convention.
85
+ * `Rakefile` is a basic build file. Not required but handy - see {file:README.md#Rakefile Rakefile}
86
+
87
+ # Learning Squib
88
+
89
+ In addition to this README, be sure to also check out the following resources for more details:
90
+
91
+ * The `samples` directory in the [source repository](https://github.com/andymeneely/squib) has lots of examples.
92
+ * [Iconoclast](https://github.com/andymeneely/iconoclast) is a basic set collection game I'm developing from scratch with Squib. Be sure to read the [commit history](https://github.com/andymeneely/iconoclast/commits/master) to see how the game has developed from scratch.
93
+ * [Junk Land](https://github.com/andymeneely/junk-land) is my own creation that's uses Squib for full-color rendering, and makes use of Ruby in a lot of interesting ways.
94
+
95
+ ## Viewing this README
96
+
97
+ The best place to read this documentation is on [our website](http://andymeneely.github.io/squib/doc). Be sure to check out the method-by-method documentation, particularly for the [Deck](Squib/Deck.html) class.
98
+
99
+ If you want to view it offline, you can do the following
100
+
101
+ ```sh
102
+ $ gem install yard
103
+ $ yard server --gems
104
+ ```
105
+ Then go to [http://localhost:8808/docs/squib/file/README.md](http://localhost:8808/docs/squib/file/README.md)
106
+
107
+ If you're viewing this on Github, you might see some confusing tags like `{include:file:...}` - these are directives for YARD to show the embedded examples. Github doesn't render those and you might find them helpful.
108
+
109
+ Also, RubyDoc.info linked from RubyGems appears to be perpetually broken and doesn't support `{include:file...}` directive properly, so the embedded samples will also not show up there, either.
110
+
111
+ ## Squib Decks and Cards
112
+
113
+ The Squib DSL is based on a collection of methods provided to the `Squib::Deck` class. The general philosophy of Squib is to specify as little as possible with layers of defaults, highly flexible input, and good ol' Ruby duck-typing. Ruby does a lot to make Squib useful.
114
+
115
+ Squib essentially has two main classes: `Deck` and `Card`. `Deck` is the front-end, and `Card` is the back-end. The contract of `Deck` is to do the various manipulations of options and then delegate the operation to `Card` to do the low-level graphical operations.
116
+
117
+ For most users, I recommending solely using `Deck` methods. If you want to roll up your sleeves and get your hands messy, you can access the Cairo or Pango contexts the directly via the `Card` class. The API documentation doesn't really cover these, however, so you're on your own there.
118
+
119
+ ## Specifying Parameters
120
+
121
+ Squib is all about sane defaults and shorthand specification. Arguments are almost always using hashes, which look a lot like [Ruby 2.0's named parameters](http://www.ruby-doc.org/core-2.0.0/doc/syntax/calling_methods_rdoc.html#label-Keyword+Arguments). This means you can specify your parameters in any order you please. All parameters are optional. For example `x` and `y` default to 0 (i.e. the upper-left corner of the card). Any parameter that is specified in the command overrides any Squib defaults, `config.yml` settings, or layout rules.
122
+
123
+ Note: you MUST use named parameters rather than positional parameters. For example: `save :png` will lead to an error like this:
124
+
125
+ C:/Ruby200/lib/ruby/gems/2.0.0/gems/squib-0.0.3/lib/squib/api/save.rb:12:in `save': wrong number of arguments (2 for 0..1) (ArgumentError)
126
+ from deck.rb:22:in `block in <main>'
127
+ from C:/Ruby200/lib/ruby/gems/2.0.0/gems/squib-0.0.3/lib/squib/deck.rb:60:in `instance_eval'
128
+ from C:/Ruby200/lib/ruby/gems/2.0.0/gems/squib-0.0.3/lib/squib/deck.rb:60:in `initialize'
129
+ from deck.rb:18:in `new'
130
+ from deck.rb:18:in `<main>'
131
+
132
+ Instead, you must name the parameters: `save format: :png`
133
+
134
+ ## Arrays and Singleton Expansion
135
+
136
+ Many inputs to Squib can accept `Arrays`, which correspond to the entire deck. In fact, under the hood, if Squib is _not_ given an array, it expands it out to an array before rendering. This allows for different styles to apply to different cards. This example comes from the [ranges.rb example](https://github.com/andymeneely/squib/tree/master/samples/ranges.rb)
137
+
138
+ ```ruby
139
+ # This renders three cards, with three strings that had three different colors at three different locations.
140
+ text str: %w(red green blue),
141
+ color: [:red, :green, :blue],
142
+ x: [40, 80, 120],
143
+ y: [700, 750, 800]
144
+ ```
145
+
146
+ Under the hood, Squib actually views every argument as applied each card individually. If a single argument is given to the command, it's considered a singleton that gets expanded into a deck-sized array. Supplying the array bypasses that expansion - which means that any array you supply instead of a singleton ought to be the same size as the deck and align the same way the indexes in the supplied `range` are. If you don't, Ruby will fill that up with nils and not apply the rule across those cards.
147
+
148
+ ## Specifying Ranges
149
+
150
+ Most public `Deck` methods allow a `range` to be specified as a first parameter. This parameter is used to access an internal `Array` of `Squib::Cards`. This can be an actual Ruby range, or anything that implements `#each` (thus can be an `Enumerable`). Integers are also supported for changing one card only. Negatives work from the back of the deck. Here are some examples from `samples/ranges.rb` found [here](https://github.com/andymeneely/squib/tree/master/samples/ranges.rb)
151
+
152
+ {include:file:samples/ranges.rb}
153
+
154
+ ## Units
155
+
156
+ By default, Squib thinks in pixels. This decision was made so that we can have pixel-perfect layouts without automatically scaling everything, even though working in units is sometimes easier. We provide some conversion methods, including looking for strings that end in "in" and "cm" and computing based on the current DPI. The dpi is set on `Squib::Deck.new` (not `config.yml`). Example is in `samples/units.rb` found [here](https://github.com/andymeneely/squib/tree/master/samples/units.rb)
157
+
158
+ {include:file:samples/units.rb}
159
+
160
+ ## Specifying Colors & Gradients
161
+
162
+ Colors can be specified in a wide variety of ways, mostly in a hex-string. Take a look at the examples from `samples/colors.rb`, found [here](https://github.com/andymeneely/squib/tree/master/samples/colors.rb)
163
+
164
+ {include:file:samples/colors.rb}
165
+
166
+ Under the hood, Squib uses the `rcairo` [color parser](https://github.com/rcairo/rcairo/blob/master/lib/cairo/color.rb) to accept a variety of color specifications, along with over [300 pre-defined constants](https://github.com/rcairo/rcairo/blob/master/lib/cairo/colors.rb). The above sample will generate a table of such constants.
167
+
168
+ Additionally, in most places where colors are allowed, you may also supply a string that defines a gradient. Squib supports two flavors of gradients: linear and radial. Gradients are specified by supplying some xy coordinates, which are relative to the card (not the command). Each stop must be between 0.0 and 1.0, and you can supply as many as you like. Colors can be specified as above (in any of the hex notations or built-in constant). If you add two (or more) colors at the same stop, then the gradient keeps the colors in the in order specified and treats it like sharp transition.
169
+
170
+ The format for gradient strings look like this:
171
+
172
+ Linear:
173
+ ```
174
+ (x1,y1)(x2,y2) color1@stop1 color2@stop2
175
+ ```
176
+ The xy coordinates define the angle of the gradient.
177
+
178
+ Radial:
179
+ ```
180
+ (x1,y1,radius1)(x2,y2,radius2) color1@stop1 color2@stop2
181
+ ```
182
+ The coordinates specify an inner circle first, then an outer circle.
183
+
184
+ Check out the following sample from `samples/gradients.rb`, found [here](https://github.com/andymeneely/squib/tree/master/samples/colors.rb)
185
+
186
+ {include:file:samples/gradients.rb}
187
+
188
+ ## Specifying Files
189
+
190
+ All files opened for reading or writing (e.g. for `png` and `xlsx`) are opened relative to the current directory. Files opened for writing (e.g. for `save_png`) will be overwritten without warning.
191
+
192
+ If you find that you `cd` a lot while working on the command line, your `_output` folder might get generated in multiple places. An easy way to fix this is to use a `Rakefile`, [see below](#Rakefile)
193
+
194
+ ## Working with Text
195
+ The `text` method is a particularly powerful method with a ton of options. Be sure to check the [API docs](/squib/doc/Squib/Deck#text-instance_method) on an option-by-option discussion, but here are the highlights.
196
+
197
+ ###Fonts.
198
+
199
+ To set the font, your `text` method call will look something like this:
200
+
201
+ ```ruby
202
+ text str: "Hello", font: 'MyFont Bold 32'
203
+ ```
204
+
205
+ The `'MyFont Bold 32'` is specified as a "Pango font string", which can involve [a lot of options](http://ruby-gnome2.osdn.jp/hiki.cgi?Pango%3A%3AFontDescription#Pango%3A%3AFontDescription.new) including backup font families, size, all-caps, stretch, oblique, italic, and degree of boldness. (These options are only available if the underlying font supports them, however.) Here's are some `text` calls with different Pango font strings:
206
+
207
+ ```
208
+ text str: "Hello", font: 'Sans 18'
209
+ text str: "Hello", font: 'Arial,Verdana weight=900 style=oblique 36'
210
+ text str: "Hello", font: 'Times New Roman,Sans 25'
211
+ ```
212
+
213
+ Note: When the font has a space in the name (e.g. Times New Roman), you'll need to put a backup to get Pango's parsing to work.
214
+
215
+ It's also important to note that most of the font rendering is done by a combination of your installed fonts, your OS, and your graphics card. Thus, different systems will render text slightly differently.
216
+
217
+ Fonts can also be set globally using the `set` method. For example:
218
+
219
+ ```
220
+ set font: 'Arial 26'
221
+ text str: 'blah' # in Arial 26
222
+ ```
223
+
224
+ Furthermore, Squib's `text` method has options such as `font_size` that allow you to override the font string. This means that you can set a blanket font for the whole deck, then adjust sizes from there. This is useful with layouts and `extends` too.
225
+
226
+ ### Width and Height
227
+
228
+ By default, Pango text boxes will scale the text box to whatever you need, hence the `:native` default. However, for most of the other customizations to work (e.g. center-aligned) you'll need to specify the width. If both the width and the height are specified and the text overflows, then the `ellipsize` option is consulted to figure out what to do with the overflow. Also, the `valign` will only work if `height` is also set to something other than `:native`.
229
+
230
+ ###Hints
231
+
232
+ Laying out text by typing in numbers can be confusing. What Squib calls "hints" is merely a rectangle around the text box. Hints can be turned on globally in the config file, using the `set` method, or in an individual text method. These are there merely for prototyping and are not intended for production. Additionally, these are not to be conflated with "rendering hints" that Pango and Cairo mention in their documentation.
233
+
234
+ ###Extents
235
+
236
+ Sometimes you want size things based on the size of your rendered text. For example, drawing a rectangle around card's title such that the rectangle perfectly fits. Squib returns the final rendered size of the text so you can work with it afterward. It's an array of hashes that correspond to each card. The output looks like this:
237
+
238
+ ```ruby
239
+ Squib::Deck.new(cards: 2) do
240
+ extents = text(str: ['Hello', 'World!'])
241
+ p extents
242
+ end
243
+ ```
244
+ Will output:
245
+ ```
246
+ [{:width=>109, :height=>55}, {:width=>142, :height=>55}] # Hello was 109 pixels wide, World 142 pixels
247
+ ```
248
+
249
+ ###Embedding Images
250
+
251
+ Squib can embed icons into the flow of text. To do this, you need to define text keys for Squib to look for, and then the corresponding files. The object given to the block is a [TextEmbed](docs/Squib/TextEmbed), which supports PNG and SVG. Here's a minimal example:
252
+
253
+ ```ruby
254
+ text(str: 'Gain 1 :health:') do |embed|
255
+ embed.svg key: ':health:', file: 'heart.svg'
256
+ end
257
+ ```
258
+
259
+ ###Markup
260
+
261
+ If you want to do specialized formatting within a given string, Squib has lots of options. By setting `markup: true`, you enable tons of text processing. This includes:
262
+
263
+ * Pango Markup. This is an HTML-like formatting language that specifies formatting inside your string. Pango Markup essentially supports any formatting option, but on a letter-by-letter basis. Such as: font options, letter spacing, gravity, color, etc. See the [Pango docs](https://developer.gnome.org/pango/stable/PangoMarkupFormat.html) for details.
264
+ * Quotes are converted to their curly counterparts where appropriate (i.e. &ldquo;smart quotes&rdquo; instead of "straight quotes").
265
+ * Apostraphes are converted to curly as well.
266
+ * LaTeX-style quotes are explicitly converted (<tt>``like this''</tt>)
267
+ * Em-dash and en-dash are converted with triple and double-dashes respectively (<tt>--</tt> is an en-dash, and <tt>---</tt> becomes an em-dash.)
268
+ * Ellipses can be specified with <tt>...</tt>. Note that this is entirely different from the `ellipsize` option (which determines what to do with overflowing text).
269
+
270
+ A few notes:
271
+ * Smart quoting assumes the UTF-8 character set.
272
+ * Pango markup uses an XML/HTML-ish processor. Some characters require HTML-entity escaping (e.g. `&amp;` for `&')
273
+
274
+ ### Text Sample
275
+ ```yaml
276
+ lsquote: "\u2018" #note that Yaml wants double quotes here to use escape chars
277
+ rsquote: "\u2019"
278
+ ldquote: "\u201C"
279
+ rdquote: "\u201D"
280
+ em_dash: "\u2014"
281
+ en_dash: "\u2013"
282
+ ellipsis: "\u2026"
283
+ ```
284
+
285
+ You can also disable the auto-quoting mechanism by setting `smart_quotes: false` in your config. Explicit replacements will still be performed.
286
+
287
+ ### Text Samples
288
+
289
+ Examples of all of the above are crammed into the `text_options.rb` sample [found here](https://github.com/andymeneely/squib/tree/master/samples/text_options.rb).
290
+
291
+ {include:file:samples/text_options.rb}
292
+
293
+ The `embed_text.rb` sample has more examples of embedding text, which can be [found here](https://github.com/andymeneely/squib/tree/master/samples/embed_text.rb).
294
+
295
+ {include:file:samples/embed_text.rb}
296
+
297
+ The `config_text_markup.rb` sample demonstrates how quoting can be configured, [found here](https://github.com/andymeneely/squib/tree/master/samples/config_text_markup.rb)
298
+
299
+ {include:file:samples/config_text_markup.rb}
300
+
301
+
302
+ ## Custom Layouts
303
+
304
+ Working with x-y coordinates all the time can be tiresome, and ideally everything in a game prototype should be data-driven and easily changed. For this, many Squib methods allow for a `layout` to be set. In essence, layouts are a way of setting default values for any argument given to the command.
305
+
306
+ To use a layout, set the `layout:` option on a `Deck.new` command to point to a YAML file. Any command that allows a `layout` option can be set with a Ruby symbol or String, and the command will then load the specified `x`, `y`, `width`, and `height`. The individual command can also override these options.
307
+
308
+ Instead of this:
309
+ ```ruby
310
+ # deck.rb
311
+ Squib::Deck.new(layout: 'custom-layout.yml') do
312
+ rect x: 75, y: 75, width: 675, height: 975
313
+ end
314
+ ```
315
+
316
+ You can put your logic in the layout file and reference them:
317
+ ```yaml
318
+ # custom-layout.yml
319
+ frame:
320
+ x: 75
321
+ y: 75
322
+ width: 975
323
+ height: 675
324
+ ```
325
+ Then your script looks like this:
326
+ ```ruby
327
+ # deck.rb
328
+ Squib::Deck.new(layout: 'custom-layout.yml') do
329
+ rect layout: 'frame'
330
+ end
331
+ ```
332
+ The goal is to make your Ruby code more separate data from logic, which in turn makes your code more readable and maintainable. With `extends` (see below), layouts become even more powerful in keeping you from repeating yourself.
333
+
334
+ Note: YAML is very finnicky about not allowing tab characters. Use two spaces for indentation instead. If you get a `Psych` syntax error, this is likely the culprit. Indendation is also strongly enforced in Yaml too. See the [Yaml docs](http://www.yaml.org/YAML_for_ruby.html).
335
+
336
+ ### Order of Precedence
337
+
338
+ Layouts will override Squib's system defaults, but are overriden by anything specified in the command itself. Thus, the order of precedence looks like this:
339
+
340
+ * Use what the command specified
341
+ * If anything was not yet specified, use what was given in a layout (if a layout was specified in the command and the file was given to the Deck)
342
+ * If still anything was not yet specified, use what was given in Squib's defaults.
343
+
344
+ ### Special key: `extends`
345
+
346
+ Squib provides a way of reusing layouts with the special `extends` key. When defining an `extends` key, we can merge in another key and modify data coming in if we want to. This allows us to do things like place text next to an icon and be able to move them with each other. Like this:
347
+
348
+ ```yaml
349
+ # If we change the xy of attack, we move defend too!
350
+ attack:
351
+ x: 100
352
+ y: 100
353
+ radius: 100
354
+ defend:
355
+ extends: attack
356
+ x: += 50
357
+ #defend now is {:x => 150, :y => 100}
358
+ ```
359
+
360
+ If you want to extend multiple parents, it looks like this:
361
+
362
+ ```yaml
363
+ socrates:
364
+ x: 100
365
+ plato:
366
+ y: 200
367
+ aristotle:
368
+ extends:
369
+ - socrates
370
+ - plato
371
+ x: += 50
372
+ ```
373
+ If multiple keys override the same keys in a parent, the later ("younger") child takes precedent.
374
+
375
+ Note that extends keys are similar to Yaml's ["merge keys"](http://www.yaml.org/YAML_for_ruby.html#merge_key). With merge keys, you can define base styles in one entry, then include those keys elsewhere. For example:
376
+
377
+ ```yaml
378
+ icon: &icon
379
+ width: 50
380
+ height: 50
381
+ icon_left
382
+ <<: *icon
383
+ x: 100
384
+ # The layout for icon_left will have the width/height from icon!
385
+ ```
386
+
387
+ If you use both `extends` and Yaml merge keys, the Yaml merge keys are processed first, then extends. For clarity, however, you're probably just better off using `extends` exclusively.
388
+
389
+ ### Multiple layout files
390
+
391
+ Squib also supports the combination of multiple layout files. If you provide an `Array` of files then Squib will merge them sequentially. Colliding keys will be completely re-defined by the later file. Extends is processed after _each file_. Here's a complex example:
392
+
393
+ ```yaml
394
+ # load order: a.yml, b.yml
395
+
396
+ ##############
397
+ # file a.yml #
398
+ ##############
399
+ grandparent:
400
+ x: 100
401
+ parent_a:
402
+ extends: grandparent
403
+ x: += 10 # evaluates to 110
404
+ parent_b:
405
+ extends: grandparent
406
+ x: += 20 # evaluates to 120
407
+
408
+ ##############
409
+ # file b.yml #
410
+ ##############
411
+ child_a:
412
+ extends: parent_a # i.e. extends a layout in a separate file
413
+ x: += 3 # evaluates to 113 (i.e 110 + 3)
414
+ parent_b: # redefined
415
+ extends: grandparent
416
+ x: += 30 # evaluates to 130 (i.e. 100 + 30)
417
+ child_b:
418
+ extends: parent_b
419
+ x: += 3 # evaluates to 133 (i.e. 130 + 3)
420
+ ```
421
+
422
+ This can be helpful for:
423
+ * Creating a base layout for structure, and one for color (for easier color/black-and-white switching)
424
+ * Sharing base layouts with other designers
425
+
426
+ YAML merge keys are NOT supported across multiple files - use `extends` instead.
427
+
428
+ ### Built-in Layout Files
429
+
430
+ Why mess with x-y coordinates when you're first prototyping your game?!?!? Just use a built-in layout to get your game to the table as quickly as possible.
431
+
432
+ If your layout file is not found in the current directory, Squib will search for its own set of layout files. The latest the development version of these can be found [on GitHub](https://github.com/andymeneely/squib/tree/master/lib/squib/layouts). The `layouts_builtin.rb` sample (found [here](https://github.com/andymeneely/squib/tree/master/samples/)) demonstrate built-in layouts based on popular games (e.g. `fantasy.yml` and `economy.yml`)
433
+
434
+ Contributions in this area are particularly welcome!
435
+
436
+ ### Layout Sample
437
+ This sample demonstrates many different ways of using and combining layouts. This is the `layouts.rb` sample found [here](https://github.com/andymeneely/squib/tree/master/samples/)
438
+
439
+ {include:file:samples/layouts.rb}
440
+
441
+ ## Backends: Raster vs. Vector
442
+ Under the hood, Cairo has the ability to support a variety of surfaces to draw on, including both raster images stored in memory and vectors stored in SVG files. Thus, Squib supports the ability to handle both. They are options in the configuration file `backend: memory` or `backend: svg`.
443
+
444
+ If you save to a PDF then the backend will determine how your cards are saved too. For `memory`, the PDF will be filled with compressed raster images and be a larger file (yet it will still print at high quality... see discussion below). For SVG backends, PDFs will be smaller. If you have your deck backed by SVG, then the cards are auto-saved, so there is no `save_svg` in Squib. (Technically, the operations are stored and then flushed to the SVG file at the very end.)
445
+
446
+ There are trade-offs that one should consider here.
447
+
448
+ * _Print quality is **higher** for raster images_. This seems counterintuitive at first, but consider where Squib sits in your workflow. It's the final assembly line for your cards before they get printed. Cairo puts _a ton_ of work into rendering each pixel perfectly when it works with raster images. Printers, on the other hand, don't think in vectors and will render your paths in their own memory with their own embedded libraries without putting a lot of work into antialiasing and various other graphical esoterica. You may notice that print-on-demand companies such as The Game Crafter [only accept raster file types](https://www.thegamecrafter.com/help/supported-file-types), because they don't want their customers complaining about printers not rendering vectors with enough care.
449
+ * _PDFs are **smaller** for SVG back ends_. If file size is a limitation for you, and it can be for some printers or internet forums, then an SVG back end for vectorized PDFs is the way to go.
450
+ * _Squib is **greedy** with memory_. While I've tested Squib with big decks on older computers, the `memory` backend is quite greedy with RAM. If memory is at a premium for you, switching to SVG might help.
451
+
452
+ Note: you can still load PNGs into an SVG-backed deck and load SVGs into a memory-backed deck. To me, the sweet spot is to keep all of my icons, text, and other stuff in vector form for infinite scaling and then render them all to pixels with Squib.
453
+
454
+ Fortunately, switching backends in Squib should be as trivial as changing the setting in the config file. So go ahead and experiment with both and see what works for you. See below for how the configuration options work.
455
+
456
+ ## Configuration File
457
+
458
+ Squib supports various configuration properties that can be specified in an external file. The `config:` option in `Deck.new` can specify an optional configuration file in YML format. The properties there are intended to be immutable for the life of the Deck. The options include:
459
+
460
+ * `progress_bars` (Boolean, default: false). When set to `true`, long-running operations will show a progress bar on the command line.
461
+ * `hint` (ColorString, default: off). Text hints are used to show the boundaries of text boxes. Can be enabled/disabled for individual commands, or set globally with the `set` command. This setting is overriden by `set` and individual commands.
462
+ * `custom_colors` (Hash of Colors, default: {}). Defines globally-available colors available to the deck that can be specified in commands.
463
+ * `antialias` (`fast, good, best, none, gray, subpixel`, default: best). Set the algorithm that Cairo will use for antialiasing. Using our benchmarks on large decks, `best` is only ~10% slower anyway. For more info see the [Cairo docs](http://www.cairographics.org/manual/cairo-cairo-t.html#cairo-antialias-t).
464
+ * `backend` (`svg` or `memory`, default: `memory`). Defines how Cairo will store the operations. Memory is recommended for higher quality rendering.
465
+ * `prefix` (default: `card_`). When using an SVG backend, cards are auto-saved with this prefix and `"%02d"` numbering format.
466
+
467
+ For debugging/sanity purposes, if you want to make sure your configuration options are parsed correclty, the above options are also available as methods within Squib::Deck, for example:
468
+
469
+ ```ruby
470
+ Squib::Deck.new do
471
+ puts backend # prints 'memory' by default
472
+ end
473
+ ```
474
+
475
+ The following sample demonstrates the config file, found [here](https://github.com/andymeneely/squib/tree/master/samples/)
476
+
477
+ {include:file:samples/custom_config.rb}
478
+
479
+ ## Importing from Excel and CSV
480
+
481
+ Squib supports importing data from `xlsx` files and `csv` files. These methods are column-based, which means that they assume you have a header row in your table, and that header row will define the column. Squib will return a `Hash` of `Arrays` correspoding to each row. Warnings are thrown on things like duplicate columns. See the `excel.rb` and the `csv_import.rb` sample found [here](https://github.com/andymeneely/squib/tree/master/samples/).
482
+
483
+ {include:file:samples/excel.rb}
484
+
485
+ Of course, you can always import your game data other ways using just Ruby. There's nothing special about Squib's methods other than their convenience.
486
+
487
+ ## Making Squib Verbose
488
+
489
+ By default, Squib's logger is set to WARN, but more fine-grained logging is embedded in the code. To set the logger, just put this at the top of your script:
490
+
491
+ ```ruby
492
+ Squib::logger.level = Logger::INFO
493
+ ```
494
+
495
+ If you REALLY want to see tons of output, you can also set DEBUG, but that's not intended for general consumption.
496
+
497
+ # "Best" Practices
498
+
499
+ Here's a collection of workflow tips and code snippets that will hopefully improve your Squibbing. Contributions are welcome!
500
+
501
+ ## Staying DRY
502
+
503
+ Squib tries to keep you DRY (Don't Repeat Yourself) with the following features:
504
+
505
+ * Custom layouts allow you to specify various arguments in a separate file. This is great for x-y coordinates and alignment properties that would otherwise clutter up perfectly readable code. Squib goes even further and has a special "extends" that works especially well for grouped-together styles.
506
+ * Flexible ranges and array handling: the `range` parameter in Squib is very flexible, meaning that one `text` command can specify different text in different fonts, styles, colors, etc. for each card. If you find yourself doing multiple `text` command for the same field across different ranges of cards, there's probably a better way to condense.
507
+ * Custom colors keep you from hardcoding magic color strings everywhere. Custom colors go into `config.yml` file.
508
+ * Plus, you know, Ruby.
509
+
510
+ ## Get to know Ruby's Array and Enumerable
511
+
512
+ Don't know Ruby? Welcome! We are so happy that Squib is your excuse to learn Ruby.
513
+
514
+ Ruby has a *very* rich library for all of its built-in data types, especially [Array](http://ruby-doc.org/core-2.2.0/Array.html), and it's broader module [Enumerable](http://ruby-doc.org/core-2.2.0/Enumerable.html). Since Squib primarily takes in arrays into most of its fields, getting to know these methods will help you out enormously:
515
+
516
+ * [Array#each](http://ruby-doc.org/core-2.2.0/Array.html#method-i-each) - do something on each element of the array (Ruby folks seldom use for-loops)
517
+ * [Array#map](http://ruby-doc.org/core-2.2.0/Array.html#method-i-map) - do something on each element of an array and put it into a new array
518
+ * [Array#select](http://ruby-doc.org/core-2.2.0/Array.html#method-i-select) - select a subset of an array
519
+ * [Enumerable#each_with_index](http://ruby-doc.org/core-2.2.0/Enumerable.html#method-i-each_with_index) - do something to each element, also being aware of the index
520
+ * [Array#zip](http://ruby-doc.org/core-2.2.0/Enumerable.html#method-i-zip) - combine two arrays, element by element
521
+
522
+ ## Source control
523
+
524
+ You are using source control, right??
525
+
526
+ By default, Squib assumes Git. But it's not dogmatic about it. Tracking your progress, backing up, sharing data, topic branches, release management, and reverting into history are just some of the many, many useful things you can do with source control. For me, I tend to ignore any auto-generated files in my output folder, but version control everything else. I also try to keep my graphics vector files, so the files stay small. Version control is intended for source code, so large binary files that change often probably should not get checked in unless absolutely necessary. I tend to keep big raster graphics files (e.g. from Gimp) in cloud storage or elsewhere.
527
+
528
+ ## SublimeText
529
+
530
+ Using SublimeText? I like you already. I've written up some Squib snippets to ease remembering Squib commands. It's called `Squib Snippets` on Package Control. Compatible with SublimeText 3. Source code is also [on Github](https://github.com/andymeneely/sublime-squib) (contributions welcome!). Check it out:
531
+
532
+ ![Sublime Squib Snippets](https://raw.githubusercontent.com/andymeneely/squib/screencasts/sublime-squib-snippets.gif)
533
+
534
+ ## Decks with multiple orientations or sizes
535
+
536
+ If you want to make a deck that has some portrait and some landscape cards, I recommend you use multiple `Squib::Deck`s. The pixel size of a given card is designed to not change thorughout the life of a `Squib::Deck`. To work with landscape cards, there is a `rotate` option on `save_png` so you can render your print-on-demand PNGs in portrait but keep everything else oriented toward landscape. The following example demonstrates how to do this, found [here](https://github.com/andymeneely/squib/tree/master/samples/portrait-landscape.rb).
537
+
538
+ {include:file:samples/portrait-landscape.rb}
539
+
540
+ ## Rakefile
541
+
542
+ When you run `squib new`, you are given a basic Rakefile. At this stage of Squib, it's basically just a shortcut for `ruby deck.rb`. But, even in this simple form this Rakefile has some advantages:
543
+
544
+ * If you're in a subdirectory at the time, `rake` will simply traverse up and `cd` to the proper directory so you don't get rogue `_output` directories
545
+ * If you find yourself building multiple decks, you can make your own tasks for each one individually, or all (e.g. `rake marketing`)
546
+ * Don't need the `require squib` at the top of your code (although that breaks `ruby deck.rb`, so that's probably a bad idea)
547
+
548
+ ## Using Google Sheets
549
+
550
+ We don't officially support Google Sheets ([yet](https://github.com/andymeneely/squib/issues/49)), but [this Gist](https://gist.github.com/pickfifteen/aeee73ec2ce162b0aee8) might be helpful in automatically exporting the CSV.
551
+
552
+ ## Combining Multiple Columns
553
+
554
+ Say you have multiple columns in your Excel sheet that need to be combined into one text field on your card. Consider using `zip` in conjunction with `map`.
555
+
556
+ ```ruby
557
+ data['BuyText'] = data['BuyAmount'].zip(data['BuyType']).map do |amt, type|
558
+ "You may purchase #{amt} #{type}" #e.g. You may purchase 1 Wood.
559
+ end
560
+
561
+ data['Cost'] = data['Action Cost'].zip(data['Card Cost']).map do |ac, cc|
562
+ ':action:' * ac.to_i + ":card#{cc}:"
563
+ end
564
+ ```
565
+
566
+ Second example adapted from [this conversation](https://github.com/andymeneely/squib/issues/90)
567
+
568
+ # Get Involved
569
+
570
+ Squib is an open source tool, so I welcome participation. Squib is currently in pre-release alpha, so the API is still maturing. I do change my mind about the names and meaning of things at this stage. I will document these changes as best as I can.
571
+
572
+ I also highly recommend upgrading to new versions of Squib every chance you get (using Bundler). You can watch for new upgrades by following the RubyGems [RSS](https://rubygems.org/gems/squib/versions.atom), or by watching the project on GitHub.
573
+
574
+ For bugs and feature requests, feel free to [file a bug or feature request](https://github.com/andymeneely/squib/issues). A minimal code example along with your OS and Ruby details would be ideal.
575
+
576
+ ## New to Programming?
577
+
578
+ I often hear statements like "I'm not a programmer, but I want to use Squib." If you want to use Squib, then maybe you really were a programmer all along :)
579
+
580
+ Squib is a Ruby library. To learn Squib, you will need to learn Ruby. There is no getting around that fact. Don't fight it, embrace it.
581
+
582
+ Fortunately, Ruby is wonderfully rich in features and very expressive in its syntax. Ruby has a vibrant, friendly community (much like tabletop game designers!). Ruby is the language of choice for many new programmers, including many universities. Plus, learning how to code is ubiquitous on the Internet.
583
+
584
+ Doubly fortunately, Squib doesn't require tons of Ruby-fu to get going either. The main things you'll need to know are:
585
+ * Working on the command line
586
+ * Ruby Arrays, so that the `range` parameter makes more sense
587
+ * Strings, variables, and symbols
588
+ * If you are using Excel or CSV, then Ruby hashes are worth a glance.
589
+ * Working iteratively: making small edits and run your code frequently (every few minutes)
590
+
591
+ Anything related to Ruby on Rails is not necessary to learn for Squib. Rails is a heavyweight framework for web development (awesome in its own way, but not relevant to learning Ruby). Squib is about scripting.
592
+
593
+ ## Get Help
594
+
595
+ There are lots of people using Squib already. If you've gone through the [samples](https://github.com/andymeneely/squib/tree/master/samples) and still have questions, here are some other places to get help.
596
+
597
+ * Our [thread on BoardGameGeek](http://boardgamegeek.com/thread/1293453) is quite active and informal (if a bit unstructured).
598
+ * [StackOverflow](http://stackoverflow.com/questions/ask?tags=ruby squib) with the tag "ruby" and "squib" will get you answers quickly and a great way to document questions for future Squibbers.
599
+
600
+ Please use GitHub issues for bugs and feature requests.
601
+
602
+ ## Testing Pre-Builds
603
+
604
+ If you want to test new features as I develop them, you can always point your Gemfile to the repository. Your Gemfile specification looks like this:
605
+
606
+ ```ruby
607
+ gem 'squib', git: 'git://github.com/andymeneely/squib', branch: 'dev'
608
+ ```
609
+ * The `dev` branch is where I am working on features in-process. I have not done much regression testing at this point, but would love testing feedback nonetheless.
610
+ * The `master` branch is where I consider features and bug that are done and tested, but not released yet.
611
+
612
+ ## Contributing
613
+
614
+ If you want your code integrated:
615
+
616
+ 1. Fork the git repository ( https://github.com/[my-github-username]/squib/fork )
617
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
618
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
619
+ 4. Push to the branch (`git push origin my-new-feature`)
620
+ 5. Create a new Pull Request
621
+
622
+ Be sure to run the unit tests and packaging with just `rake`. Also, you can check that the samples render properly with `rake sanity`.
623
+
624
+ # What's up the with the name?
625
+
626
+ Truthfully, I just thought it was a cool, simple word that was not used much in the Ruby community nor the board game community. But, now that I've committed to the name, I've realized that:
627
+
628
+ * Squibs are small explosive devices, much like Squib "explodes" your rules into a playable game
629
+ * Squibs are often used in heist movies, leading to a sudden plot twist that often resembles the twists of good tabletop game
630
+ * Squibs are also part of the Harry Potter world - they are people who are non-magical but wizard-born. Squib is aware of wizarding magic and comes from that heritage, but it's not magical itself.