squib 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +3 -1
- data/CHANGELOG.md +10 -0
- data/README.md +65 -4
- data/lib/squib/api/data.rb +48 -1
- data/lib/squib/api/text.rb +4 -2
- data/lib/squib/deck.rb +22 -5
- data/lib/squib/graphics/text.rb +4 -0
- data/lib/squib/layouts/hand.yml +46 -0
- data/lib/squib/layouts/playing-card.yml +18 -0
- data/lib/squib/version.rb +1 -1
- data/samples/cairo_access.rb +4 -3
- data/samples/csv_import.rb +20 -0
- data/samples/custom-layout.yml +5 -4
- data/samples/custom-layout2.yml +15 -0
- data/samples/custom_config.rb +0 -1
- data/samples/excel.rb +1 -2
- data/samples/layouts.rb +61 -0
- data/samples/ranges.rb +0 -1
- data/samples/sample.csv +3 -0
- data/samples/text_options.rb +14 -3
- data/samples/tgc_proofs.rb +0 -1
- data/samples/units.rb +1 -1
- data/spec/api/api_data_spec.rb +31 -0
- data/spec/api/api_image_spec.rb +38 -0
- data/spec/data/csv/basic.csv +3 -0
- data/spec/data/csv/dup_cols.csv +3 -0
- data/spec/data/csv/with_spaces.csv +3 -0
- data/spec/data/{easy-circular-extends.yml → layouts/easy-circular-extends.yml} +0 -0
- data/spec/data/{hard-circular-extends.yml → layouts/hard-circular-extends.yml} +0 -0
- data/spec/data/{multi-extends-single-entry.yml → layouts/multi-extends-single-entry.yml} +0 -0
- data/spec/data/{multi-level-extends.yml → layouts/multi-level-extends.yml} +0 -0
- data/spec/data/layouts/multifile-a.yml +4 -0
- data/spec/data/layouts/multifile-b.yml +4 -0
- data/spec/data/layouts/multifile-extends-a.yml +8 -0
- data/spec/data/layouts/multifile-extends-b.yml +9 -0
- data/spec/data/{no-extends.yml → layouts/no-extends.yml} +0 -0
- data/spec/data/{pre-extends.yml → layouts/pre-extends.yml} +0 -0
- data/spec/data/{self-circular-extends.yml → layouts/self-circular-extends.yml} +0 -0
- data/spec/data/{single-extends.yml → layouts/single-extends.yml} +0 -0
- data/spec/data/{single-level-multi-extends.yml → layouts/single-level-multi-extends.yml} +0 -0
- data/spec/data/samples/autoscale_font.rb.txt +81 -0
- data/spec/data/samples/basic.rb.txt +206 -0
- data/spec/data/samples/cairo_access.rb.txt +25 -0
- data/spec/data/samples/colors.rb.txt +124 -0
- data/spec/data/samples/csv_import.rb.txt +112 -0
- data/spec/data/samples/custom_config.rb.txt +45 -0
- data/spec/data/samples/draw_shapes.rb.txt +35 -0
- data/spec/data/samples/excel.rb.txt +168 -0
- data/spec/data/samples/hello_world.rb.txt +36 -0
- data/spec/data/samples/layouts.rb.txt +489 -0
- data/spec/data/samples/load_images.rb.txt +104 -0
- data/spec/data/samples/portrait-landscape.rb.txt +49 -0
- data/spec/data/samples/ranges.rb.txt +426 -0
- data/spec/data/samples/save_pdf.rb.txt +545 -0
- data/spec/data/samples/text_options.rb.txt +819 -0
- data/spec/data/samples/tgc_proofs.rb.txt +81 -0
- data/spec/data/samples/units.rb.txt +14 -0
- data/spec/deck_spec.rb +33 -9
- data/spec/graphics/graphics_text_spec.rb +7 -5
- data/spec/samples/samples_regression_spec.rb +73 -0
- data/spec/spec_helper.rb +64 -2
- data/squib.gemspec +2 -2
- metadata +100 -27
- data/samples/use_layout.rb +0 -34
- data/spec/samples_run_spec.rb +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f92ed35ef9dd4ecc229f5608a621af891c3e31f
|
4
|
+
data.tar.gz: d45847e33458b00f6642558892abeb4f7682e0f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0fe30d4bfcf1f528140cbda4cd3662b88a06b605093390d2bf0ad28243b83b54ca97a294a3882f161db92d51ee13654519285df0c555c1e7aa5848a14de3520
|
7
|
+
data.tar.gz: 0acfc9a5e09394528b0eb3a6ed5df1ae528b18324ffe336e1f01d981ef839808283ab1b66468d66568869a376e99fde087bd2dfb9381069d353be29d15ba8a75
|
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Squib CHANGELOG
|
2
2
|
|
3
|
+
## v0.0.6
|
4
|
+
# Added a `csv` command that works just like `xslx`. Uses Ruby's CSV inside, with some extra checking and warnings.
|
5
|
+
# Custom layouts now support loading & merging multiple Yaml files! Updated README, docs, and sample to document it.
|
6
|
+
# Built-in layouts! Currently we support `hand.yml` and `playing-card.yml`. Documented in the `layouts.rb` sample.
|
7
|
+
# `text` now returns the ink extent rectangle of the rendered text. Updated docs and sample to document it.
|
8
|
+
# Samples now show that you can use text instead of symbols for things like `center`
|
9
|
+
# Improved logging, and documentation on increasing logger verboseness
|
10
|
+
# Better regression testing technique that tracks when a sample has changed.
|
11
|
+
# Bumped version of Cairo to ~> 1.14
|
12
|
+
|
3
13
|
## v0.0.5
|
4
14
|
* Image rotation for png and svg via `angle`
|
5
15
|
* New sample for demonstrating direct cairo access
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Squib is a Ruby [DSL](http://en.wikipedia.org/wiki/Domain-specific_language) for
|
|
4
4
|
* A concise set of rules for laying out your cards
|
5
5
|
* Loading PNGs and SVGs using [Cairo](http://cairographics.org/)
|
6
6
|
* Complex text rendering using [Pango](http://www.pango.org/)
|
7
|
-
* Reading
|
7
|
+
* Reading `xlsx` and `csv` files
|
8
8
|
* Basic shape drawing
|
9
9
|
* Rendering decks to PNGs and PDFs
|
10
10
|
* Data-driven layouts
|
@@ -38,7 +38,7 @@ And then execute:
|
|
38
38
|
|
39
39
|
$ bundle
|
40
40
|
|
41
|
-
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 all require DevKit to compile C code. This is usually not painful, but can cause headaches on some setups. For Windows users, I *strongly* recommend using the *non-64 bit* RubyInstaller at http://rubyinstaller.org. For Mac, I recommend using [rvm](https://rvm.io).
|
41
|
+
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 all require DevKit to compile C code. This is usually not painful, but can cause headaches on some setups. For Windows users, I *strongly* recommend using the *non-64 bit* RubyInstaller at http://rubyinstaller.org along with installing DevKit. For Mac, I recommend using [rvm](https://rvm.io).
|
42
42
|
|
43
43
|
Note: Squib requires Ruby 2.0 or later.
|
44
44
|
|
@@ -169,6 +169,12 @@ Layouts will override Squib's defaults, but are overriden by anything specified
|
|
169
169
|
* 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)
|
170
170
|
* If still anything was not yet specified, use what was given in Squib's defaults.
|
171
171
|
|
172
|
+
Layouts also allow merging, extending, and combining layouts. The sample demonstrates this, but they are also explained below. See the `layouts.rb` sample found [here](https://github.com/andymeneely/squib/tree/master/samples/)
|
173
|
+
|
174
|
+
{include:file:samples/layouts.rb}
|
175
|
+
|
176
|
+
### Merge Keys and `extends`
|
177
|
+
|
172
178
|
Since Layouts are in Yaml, we have the full power of that data format. One particular feature you should look into are ["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:
|
173
179
|
|
174
180
|
```yaml
|
@@ -193,9 +199,46 @@ yang:
|
|
193
199
|
x: += 50
|
194
200
|
```
|
195
201
|
|
196
|
-
|
202
|
+
### Multiple layout files
|
203
|
+
|
204
|
+
Squib also supports the combination of multiple layout files. As shown in the above example, 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_. YAML merge keys are NOT supported across multiple files - use extends instead. Here's a demonstrative example:
|
205
|
+
|
206
|
+
```yaml
|
207
|
+
# load order: a.yml, b.yml
|
208
|
+
|
209
|
+
##############
|
210
|
+
# file a.yml #
|
211
|
+
##############
|
212
|
+
grandparent:
|
213
|
+
x: 100
|
214
|
+
parent_a:
|
215
|
+
extends: grandparent
|
216
|
+
x: += 10 # evaluates to 110
|
217
|
+
parent_b:
|
218
|
+
extends: grandparent
|
219
|
+
x: += 20 # evaluates to 120
|
220
|
+
|
221
|
+
##############
|
222
|
+
# file b.yml #
|
223
|
+
##############
|
224
|
+
child_a:
|
225
|
+
extends: parent_a
|
226
|
+
x: += 3 # evaluates to 113
|
227
|
+
parent_b: # redefined
|
228
|
+
extends: grandparent
|
229
|
+
x: += 30 # evaluates to 130
|
230
|
+
child_b:
|
231
|
+
extends: parent_b
|
232
|
+
x: += 3 # evaluates to 133
|
233
|
+
```
|
234
|
+
|
235
|
+
This can hopefully be helpful for:
|
236
|
+
* Creating a base layout for structure, and one for color (for easier color/black-and-white switching)
|
237
|
+
* Sharing base layouts with other designers
|
238
|
+
|
239
|
+
### Built-in Layout Files
|
197
240
|
|
198
|
-
|
241
|
+
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.
|
199
242
|
|
200
243
|
## Configuration File
|
201
244
|
|
@@ -212,6 +255,24 @@ See the `custom_config` sample found [here](https://github.com/andymeneely/squib
|
|
212
255
|
|
213
256
|
{include:file:samples/custom_config.rb}
|
214
257
|
|
258
|
+
## Importing from Excel and CSV
|
259
|
+
|
260
|
+
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/).
|
261
|
+
|
262
|
+
{include:file:samples/excel.rb}
|
263
|
+
|
264
|
+
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.
|
265
|
+
|
266
|
+
## Making Squib Verbose
|
267
|
+
|
268
|
+
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:
|
269
|
+
|
270
|
+
```ruby
|
271
|
+
Squib::logger.level = Logger::INFO
|
272
|
+
```
|
273
|
+
|
274
|
+
If you REALLY want to see tons of output, you can also set DEBUG, but that's not intended for general consumption.
|
275
|
+
|
215
276
|
## Staying DRY
|
216
277
|
|
217
278
|
Squib tries to keep you DRY (Don't Repeat Yourself) with the following features:
|
data/lib/squib/api/data.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'roo'
|
2
|
+
require 'csv'
|
2
3
|
|
3
4
|
module Squib
|
4
5
|
|
@@ -40,12 +41,58 @@ module Squib
|
|
40
41
|
end#xlsx
|
41
42
|
module_function :xlsx
|
42
43
|
|
44
|
+
# Pulls CSV data from `.csv` files into a column-based hash
|
45
|
+
#
|
46
|
+
# Pulls the data into a Hash of arrays based on the columns. First row is assumed to be the header row.
|
47
|
+
# See the example `samples/csv.rb` in the [source repository](https://github.com/andymeneely/squib/tree/master/samples)
|
48
|
+
#
|
49
|
+
# @example
|
50
|
+
# # File data.csv looks like this (without the comment symbols)
|
51
|
+
# # h1,h2
|
52
|
+
# # 1,2
|
53
|
+
# # 3,4
|
54
|
+
# data = csv file: 'data.csv'
|
55
|
+
# => {'h1' => [1,3], 'h2' => [2,4]}
|
56
|
+
#
|
57
|
+
# Parsing uses Ruby's CSV, options: {headers: true, converters: :numeric}
|
58
|
+
# http://www.ruby-doc.org/stdlib-2.0/libdoc/csv/rdoc/CSV.html
|
59
|
+
#
|
60
|
+
# @option opts file [String] the CSV-formatted file to open. Opens relative to the current directory.
|
61
|
+
# @return [Hash] a hash of arrays based on columns in the spreadsheet
|
62
|
+
# @api public
|
63
|
+
def csv(opts = {})
|
64
|
+
opts = Squib::SYSTEM_DEFAULTS.merge(opts)
|
65
|
+
opts = Squib::InputHelpers.fileify(opts)
|
66
|
+
table = CSV.read(opts[:file], headers: true, converters: :numeric)
|
67
|
+
check_duplicate_csv_headers(table)
|
68
|
+
hash = Hash.new
|
69
|
+
table.headers.each do |header|
|
70
|
+
hash[header.to_s] ||= table[header]
|
71
|
+
end
|
72
|
+
return hash
|
73
|
+
end
|
74
|
+
module_function :csv
|
75
|
+
|
76
|
+
# Check if the given CSV table has duplicate columns, and throw a warning
|
77
|
+
# @api private
|
78
|
+
def check_duplicate_csv_headers(table)
|
79
|
+
if table.headers.size != table.headers.uniq.size
|
80
|
+
dups = table.headers.select{|e| table.headers.count(e) > 1 }
|
81
|
+
Squib.logger.warn "CSV duplicated the following column keys: #{dups.join(',')}"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
module_function :check_duplicate_csv_headers
|
85
|
+
|
43
86
|
class Deck
|
44
87
|
|
45
|
-
# Convenience call
|
88
|
+
# Convenience call on deck goes to the module function
|
46
89
|
def xlsx(opts = {})
|
47
90
|
Squib.xlsx(opts)
|
48
91
|
end
|
49
92
|
|
93
|
+
def csv(opts = {})
|
94
|
+
Squib.csv(opts)
|
95
|
+
end
|
96
|
+
|
50
97
|
end
|
51
98
|
end
|
data/lib/squib/api/text.rb
CHANGED
@@ -36,18 +36,20 @@ module Squib
|
|
36
36
|
# @option opts ellipsize [:none, :start, :middle, :end, true, false] (:end) When width and height are set, determines the behavior of overflowing text. Also: `true` maps to `:end` and `false` maps to `:none`. Default `:end`
|
37
37
|
# @option opts angle [FixNum] (0) Rotation of the text in radians. Note that this rotates around the upper-left corner of the text box, making the placement of x-y coordinates slightly tricky.
|
38
38
|
# @option opts hint [String] (:nil) draw a rectangle around the text with the given color. Overrides global hints (see {Deck#hint}).
|
39
|
-
# @return [
|
39
|
+
# @return [Array] Returns an Array of hashes keyed by :width and :height that mark the ink extents of the text rendered.
|
40
40
|
# @api public
|
41
41
|
def text(opts = {})
|
42
42
|
opts = needs(opts, [:range, :str, :font, :font_size, :x, :y, :width, :height, :color, :wrap,
|
43
43
|
:align, :justify, :spacing, :valign, :markup, :ellipsize, :hint, :layout, :angle])
|
44
|
+
extents = Array.new(@cards.size)
|
44
45
|
opts[:range].each do |i|
|
45
|
-
@cards[i].text(opts[:str][i], opts[:font][i], opts[:font_size][i], opts[:color][i],
|
46
|
+
extents[i] = @cards[i].text(opts[:str][i], opts[:font][i], opts[:font_size][i], opts[:color][i],
|
46
47
|
opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
|
47
48
|
opts[:markup][i], opts[:justify][i], opts[:wrap][i],
|
48
49
|
opts[:ellipsize][i], opts[:spacing][i], opts[:align][i],
|
49
50
|
opts[:valign][i], opts[:hint][i], opts[:angle][i])
|
50
51
|
end
|
52
|
+
return extents
|
51
53
|
end
|
52
54
|
|
53
55
|
end
|
data/lib/squib/deck.rb
CHANGED
@@ -50,6 +50,7 @@ module Squib
|
|
50
50
|
# @param cards [Integer] the number of cards in the deck
|
51
51
|
# @param dpi [Integer] the pixels per inch when rendering out to PDF or calculating using inches.
|
52
52
|
# @param config [String] the file used for global settings of this deck
|
53
|
+
# @param layout [String, Array] load a YML file of custom layouts. Multiple files are merged sequentially, redefining collisons. See README and sample for details.
|
53
54
|
# @param block [Block] the main body of the script.
|
54
55
|
# @api public
|
55
56
|
def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block)
|
@@ -62,6 +63,7 @@ module Squib
|
|
62
63
|
@progress_bar = Squib::Progress.new(false)
|
63
64
|
@text_hint = :off
|
64
65
|
cards.times{ @cards << Squib::Card.new(self, width, height) }
|
66
|
+
show_info(config, layout)
|
65
67
|
load_config(config)
|
66
68
|
load_layout(layout)
|
67
69
|
if block_given?
|
@@ -94,6 +96,7 @@ module Squib
|
|
94
96
|
# @api private
|
95
97
|
def load_config(file)
|
96
98
|
if File.exists?(file) && config = YAML.load_file(file)
|
99
|
+
Squib::logger.info { " using config: #{file}" }
|
97
100
|
config = Squib::CONFIG_DEFAULTS.merge(config)
|
98
101
|
@dpi = config['dpi'].to_i
|
99
102
|
@text_hint = config['text_hint']
|
@@ -105,12 +108,21 @@ module Squib
|
|
105
108
|
|
106
109
|
# Load the layout configuration file, if exists
|
107
110
|
# @api private
|
108
|
-
def load_layout(
|
109
|
-
return if file.nil?
|
111
|
+
def load_layout(files)
|
110
112
|
@layout = {}
|
111
|
-
|
112
|
-
|
113
|
-
|
113
|
+
Squib::logger.info { " using layout(s): #{files}" }
|
114
|
+
Array(files).each do |file|
|
115
|
+
thefile = file
|
116
|
+
thefile = "#{File.dirname(__FILE__)}/layouts/#{file}" unless File.exists?(file)
|
117
|
+
if File.exists? thefile
|
118
|
+
yml = @layout.merge(YAML.load_file(thefile))
|
119
|
+
yml.each do |key, value|
|
120
|
+
@layout[key] = recurse_extends(yml, key, {})
|
121
|
+
end
|
122
|
+
else
|
123
|
+
puts "the file: #{thefile}"
|
124
|
+
Squib::logger.error { "Layout file not found: #{file}" }
|
125
|
+
end
|
114
126
|
end
|
115
127
|
end
|
116
128
|
|
@@ -157,6 +169,11 @@ module Squib
|
|
157
169
|
end
|
158
170
|
end
|
159
171
|
|
172
|
+
def show_info(config, layout)
|
173
|
+
Squib::logger.info "Squib v#{Squib::VERSION}"
|
174
|
+
Squib::logger.info " building #{@cards.size} #{@width}x#{@height} cards"
|
175
|
+
end
|
176
|
+
|
160
177
|
##################
|
161
178
|
### PUBLIC API ###
|
162
179
|
##################
|
data/lib/squib/graphics/text.rb
CHANGED
@@ -89,6 +89,7 @@ module Squib
|
|
89
89
|
markup, justify, wrap, ellipsize,
|
90
90
|
spacing, align, valign, hint, angle)
|
91
91
|
Squib.logger.debug {"Placing '#{str}'' with font '#{font}' @ #{x}, #{y}, color: #{color}, angle: #{angle} etc."}
|
92
|
+
extents = nil
|
92
93
|
use_cairo do |cc|
|
93
94
|
cc.set_source_color(color)
|
94
95
|
cc.translate(x,y)
|
@@ -112,7 +113,10 @@ module Squib
|
|
112
113
|
valign!(cc, layout, x, y, valign)
|
113
114
|
cc.update_pango_layout(layout) ; cc.show_pango_layout(layout)
|
114
115
|
draw_text_hint(cc,x,y,layout,hint,angle)
|
116
|
+
extents = { width: layout.extents[1].width / Pango::SCALE,
|
117
|
+
height: layout.extents[1].height / Pango::SCALE }
|
115
118
|
end
|
119
|
+
return extents
|
116
120
|
end
|
117
121
|
|
118
122
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# A layout designed for a card to be held in your hand.
|
2
|
+
# * Bonuses align along the left-hand side.
|
3
|
+
# * Title along the top.
|
4
|
+
# * Middle area for artwork,
|
5
|
+
# * Room for a text description
|
6
|
+
# * And some theme-based text (which I like call the "snark")
|
7
|
+
# Along the lines of Race for the Galaxy or 7 Wonders
|
8
|
+
# Based on TheGameCrafter.com's Poker Card, which is 825x1125
|
9
|
+
# Sample usage is found in samples/layouts.rb
|
10
|
+
title:
|
11
|
+
x: 275
|
12
|
+
y: 75
|
13
|
+
width: 475
|
14
|
+
height: 125
|
15
|
+
art:
|
16
|
+
x: 275
|
17
|
+
y: 225
|
18
|
+
width: 475
|
19
|
+
height: 475
|
20
|
+
description:
|
21
|
+
x: 275
|
22
|
+
y: 725
|
23
|
+
width: 475
|
24
|
+
height: 200
|
25
|
+
snark:
|
26
|
+
x: 275
|
27
|
+
y: 950
|
28
|
+
width: 475
|
29
|
+
height: 100
|
30
|
+
bonus1:
|
31
|
+
x: 75
|
32
|
+
y: 75
|
33
|
+
width: 175
|
34
|
+
height: 175
|
35
|
+
bonus2:
|
36
|
+
extends: bonus1
|
37
|
+
y: += 198
|
38
|
+
bonus3:
|
39
|
+
extends: bonus2
|
40
|
+
y: += 198
|
41
|
+
bonus4:
|
42
|
+
extends: bonus3
|
43
|
+
y: += 198
|
44
|
+
bonus5:
|
45
|
+
extends: bonus4
|
46
|
+
y: += 198
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# A basic playing card layout with bonuses in the upper-left and lower-right. The lower-right angle is rotated for text.
|
2
|
+
bonus_ul:
|
3
|
+
x: 75
|
4
|
+
y: 75
|
5
|
+
width: 200
|
6
|
+
height: 200
|
7
|
+
bonus_lr:
|
8
|
+
extends: bonus_ul
|
9
|
+
x: 750
|
10
|
+
y: 1050
|
11
|
+
angle: 3.14159
|
12
|
+
art:
|
13
|
+
x: 150
|
14
|
+
y: 275
|
15
|
+
width: 525
|
16
|
+
height: 575
|
17
|
+
valign: middle
|
18
|
+
align: center
|
data/lib/squib/version.rb
CHANGED
data/samples/cairo_access.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'squib'
|
2
2
|
|
3
3
|
Squib::Deck.new(cards: 2) do
|
4
|
-
|
4
|
+
background color: :white
|
5
5
|
# If you really need something custom-made, the underlying cairo context
|
6
6
|
# can be accessed directly via each Squib::Card
|
7
7
|
#
|
@@ -11,8 +11,9 @@ Squib::Deck.new(cards: 2) do
|
|
11
11
|
# I also recommend wrapping it in a Cairo save/restore, which Squib calls "use_cairo"
|
12
12
|
each do |card|
|
13
13
|
card.use_cairo do |cairo_context|
|
14
|
-
cairo_context.set_source_color(:
|
15
|
-
cairo_context.
|
14
|
+
cairo_context.set_source_color(:blue)
|
15
|
+
cairo_context.circle(150, 150, 150)
|
16
|
+
cairo_context.fill
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'squib'
|
2
|
+
|
3
|
+
Squib::Deck.new(cards: 2) do
|
4
|
+
background color: :white
|
5
|
+
|
6
|
+
# Outputs a hash of arrays with the header names as keys
|
7
|
+
data = csv file: 'sample.csv'
|
8
|
+
|
9
|
+
text str: data['Name'], x: 250, y: 55, font: 'Arial 54'
|
10
|
+
text str: data['Level'], x: 65, y: 65, font: 'Arial 72'
|
11
|
+
text str: data['Description'], x: 65, y: 600, font: 'Arial 36'
|
12
|
+
|
13
|
+
# You can also specify the sheet, starting at 0
|
14
|
+
data = xlsx file: 'sample.xlsx', sheet: 2
|
15
|
+
|
16
|
+
save format: :png, prefix: 'sample_csv_'
|
17
|
+
end
|
18
|
+
|
19
|
+
# CSV is also a Squib-module-level function, so this also works:
|
20
|
+
data = Squib.csv file: 'sample.csv'
|
data/samples/custom-layout.yml
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# Used in the layouts.rb sample in conjunction with custom-layout2.yml
|
1
2
|
frame:
|
2
3
|
x: 38
|
3
4
|
y: 38
|
@@ -9,15 +10,15 @@ title:
|
|
9
10
|
y: 50
|
10
11
|
width: 625
|
11
12
|
height: 100
|
12
|
-
align:
|
13
|
-
valign: !ruby/symbol middle
|
13
|
+
align: center #strings also work for most options
|
14
|
+
valign: !ruby/symbol middle #yaml also support symbols, see http://www.yaml.org/YAML_for_ruby.html#symbols
|
14
15
|
subtitle:
|
15
16
|
x: 150
|
16
17
|
y: 150
|
17
18
|
width: 575
|
18
19
|
height: 60
|
19
|
-
align:
|
20
|
-
valign:
|
20
|
+
align: center
|
21
|
+
valign: middle
|
21
22
|
icon:
|
22
23
|
width: 125
|
23
24
|
height: 125
|