Browse Source

Rubocop: Trailing Whitespace

dev
Andy Meneely 11 years ago
parent
commit
37fd4e7733
  1. 2
      Rakefile
  2. 4
      bin/squib
  3. 10
      lib/squib.rb
  4. 4
      lib/squib/api/background.rb
  5. 8
      lib/squib/api/data.rb
  6. 10
      lib/squib/api/image.rb
  7. 8
      lib/squib/api/save.rb
  8. 8
      lib/squib/api/settings.rb
  9. 38
      lib/squib/api/shapes.rb
  10. 20
      lib/squib/api/text.rb
  11. 4
      lib/squib/api/units.rb
  12. 8
      lib/squib/card.rb
  13. 6
      lib/squib/commands/new.rb
  14. 14
      lib/squib/constants.rb
  15. 36
      lib/squib/deck.rb
  16. 4
      lib/squib/graphics/background.rb
  17. 6
      lib/squib/graphics/image.rb
  18. 4
      lib/squib/graphics/save_doc.rb
  19. 4
      lib/squib/graphics/save_images.rb
  20. 12
      lib/squib/graphics/shapes.rb
  21. 26
      lib/squib/graphics/text.rb
  22. 20
      lib/squib/input_helpers.rb
  23. 4
      lib/squib/progress.rb
  24. 2
      lib/squib/project_template/deck.rb
  25. 4
      lib/squib/version.rb
  26. 6
      samples/autoscale_font.rb
  27. 4
      samples/basic.rb
  28. 10
      samples/custom-layout.yml
  29. 2
      samples/custom_config.rb
  30. 14
      samples/draw_shapes.rb
  31. 2
      samples/hello_world.rb
  32. 2
      samples/load_images.rb
  33. 4
      samples/portrait-landscape.rb
  34. 16
      samples/ranges.rb
  35. 14
      samples/text_options.rb
  36. 4
      samples/tgc_proofs.rb
  37. 4
      samples/use_layout.rb
  38. 18
      spec/api/api_text_spec.rb
  39. 6
      spec/commands/new_spec.rb
  40. 2
      spec/data/easy-circular-extends.yml
  41. 4
      spec/data/hard-circular-extends.yml
  42. 6
      spec/data/multi-extends-single-entry.yml
  43. 2
      spec/data/multi-level-extends.yml
  44. 4
      spec/data/no-extends.yml
  45. 2
      spec/data/pre-extends.yml
  46. 2
      spec/data/self-circular-extends.yml
  47. 2
      spec/data/single-extends.yml
  48. 2
      spec/data/single-level-multi-extends.yml
  49. 84
      spec/deck_spec.rb
  50. 12
      spec/input_helpers_spec.rb
  51. 4
      spec/samples_run_spec.rb

2
Rakefile

@ -3,7 +3,7 @@ require 'rspec/core/rake_task'
require 'yard' require 'yard'
RSpec::Core::RakeTask.new(:spec) RSpec::Core::RakeTask.new(:spec)
task :default => [:install, :spec] task default: [:install, :spec]
YARD::Rake::YardocTask.new(:doc) do |t| YARD::Rake::YardocTask.new(:doc) do |t|
t.files = ['lib/**/*.rb', 'samples/**/*.rb'] # optional t.files = ['lib/**/*.rb', 'samples/**/*.rb'] # optional

4
bin/squib

@ -9,11 +9,11 @@ Mercenary.program(:squib) do |p|
p.command(:new) do |c| p.command(:new) do |c|
c.syntax "new PATH" c.syntax "new PATH"
c.description "Creates a new Squib project scaffolding in PATH. Must be a new directory or already empty." c.description "Creates a new Squib project scaffolding in PATH. Must be a new directory or already empty."
c.action do |args, options| c.action do |args, options|
Squib::Commands::New.new.process(args) Squib::Commands::New.new.process(args)
end end
end end
end end

10
lib/squib.rb

@ -8,15 +8,15 @@ require 'squib/deck'
require 'squib/card' require 'squib/card'
module Squib module Squib
# Access the internal logger that Squib uses. By default, Squib configure the logger to the WARN level # Access the internal logger that Squib uses. By default, Squib configure the logger to the WARN level
# Use this to suppress or increase output levels. # Use this to suppress or increase output levels.
# @example # @example
# Squib.logger.level = Logger::DEBUG #show waaaay more information than you probably need, unless you're a dev # Squib.logger.level = Logger::DEBUG #show waaaay more information than you probably need, unless you're a dev
# Squib.logger.level = Logger::ERROR #basically turns it off # Squib.logger.level = Logger::ERROR #basically turns it off
# #
# @return [Logger] the ruby logger # @return [Logger] the ruby logger
# @api public # @api public
def logger def logger
if @logger.nil? if @logger.nil?
@logger = Logger.new(STDOUT); @logger = Logger.new(STDOUT);
@ -28,5 +28,5 @@ module Squib
@logger @logger
end end
module_function :logger module_function :logger
end end

4
lib/squib/api/background.rb

@ -1,6 +1,6 @@
module Squib module Squib
class Deck class Deck
# Fills the background with the given color # Fills the background with the given color
# @example # @example
# background color: :white # background color: :white
# #
@ -14,6 +14,6 @@ module Squib
opts = needs(opts,[:range, :color]) opts = needs(opts,[:range, :color])
opts[:range].each { |i| @cards[i].background(opts[:color][i]) } opts[:range].each { |i| @cards[i].background(opts[:color][i]) }
end end
end end
end end

8
lib/squib/api/data.rb

@ -4,13 +4,13 @@ module Squib
# Pulls Excel data from `.xlsx` files into a column-based hash # Pulls Excel data from `.xlsx` files into a column-based hash
# #
# Pulls the data into a Hash of arrays based on the columns. First row is assumed to be the header row. # Pulls the data into a Hash of arrays based on the columns. First row is assumed to be the header row.
# See the example `samples/excel.rb` in the [source repository](https://github.com/andymeneely/squib/tree/master/samples) # See the example `samples/excel.rb` in the [source repository](https://github.com/andymeneely/squib/tree/master/samples)
# #
# @example # @example
# # Excel file looks like this: # # Excel file looks like this:
# # | h1 | h2 | # # | h1 | h2 |
# # ------------ # # ------------
# # | 1 | 2 | # # | 1 | 2 |
# # | 3 | 4 | # # | 3 | 4 |
# data = xlsx file: 'data.xlsx', sheet: 0 # data = xlsx file: 'data.xlsx', sheet: 0
@ -41,11 +41,11 @@ module Squib
module_function :xlsx module_function :xlsx
class Deck class Deck
# Convenience call for Squib.xlsx # Convenience call for Squib.xlsx
def xlsx(opts = {}) def xlsx(opts = {})
Squib.xlsx(opts) Squib.xlsx(opts)
end end
end end
end end

10
lib/squib/api/image.rb

@ -21,8 +21,8 @@ module Squib
opts = needs(opts, [:range, :files, :x, :y, :alpha, :layout, :blend]) opts = needs(opts, [:range, :files, :x, :y, :alpha, :layout, :blend])
Dir.chdir(@img_dir) do Dir.chdir(@img_dir) do
@progress_bar.start("Loading PNG(s)", opts[:range].size) do |bar| @progress_bar.start("Loading PNG(s)", opts[:range].size) do |bar|
opts[:range].each do |i| opts[:range].each do |i|
@cards[i].png(opts[:file][i], opts[:x][i], opts[:y][i], opts[:alpha][i], opts[:blend][i]) @cards[i].png(opts[:file][i], opts[:x][i], opts[:y][i], opts[:alpha][i], opts[:blend][i])
bar.increment bar.increment
end end
end end
@ -32,7 +32,7 @@ module Squib
# Renders an entire svg file at the given location. Uses the SVG-specified units and DPI to determine the pixel width and height. # Renders an entire svg file at the given location. Uses the SVG-specified units and DPI to determine the pixel width and height.
# #
# See {file:samples/load-images.rb samples/load-images.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples. # See {file:samples/load-images.rb samples/load-images.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
# @example # @example
# svg 1..2, 'icon.svg', '#stone', x: 50, y:50 # svg 1..2, 'icon.svg', '#stone', x: 50, y:50
# #
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges} # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
@ -54,8 +54,8 @@ module Squib
@progress_bar.start("Loading SVG(s)", p[:range].size) do |bar| @progress_bar.start("Loading SVG(s)", p[:range].size) do |bar|
p[:range].each do |i| p[:range].each do |i|
unless p[:force_id][i] && p[:id][i].to_s.empty? unless p[:force_id][i] && p[:id][i].to_s.empty?
@cards[i].svg(p[:file][i], p[:id][i], p[:x][i], p[:y][i], @cards[i].svg(p[:file][i], p[:id][i], p[:x][i], p[:y][i],
p[:width][i], p[:height][i], p[:alpha][i], p[:blend][i]) p[:width][i], p[:height][i], p[:alpha][i], p[:blend][i])
end end
bar.increment bar.increment
end end

8
lib/squib/api/save.rb

@ -1,6 +1,6 @@
module Squib module Squib
class Deck class Deck
# Saves the given range of cards to either PNG or PDF # Saves the given range of cards to either PNG or PDF
# #
# @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges} # @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
@ -16,8 +16,8 @@ module Squib
save_pdf(opts) if opts[:format].include? :pdf save_pdf(opts) if opts[:format].include? :pdf
self self
end end
# Saves the given range of cards to a PNG # Saves the given range of cards to a PNG
# #
# @example # @example
# save range: 1..8, dir: '_pnp', prefix: 'bw_' # save range: 1..8, dir: '_pnp', prefix: 'bw_'
@ -31,7 +31,7 @@ module Squib
def save_png(opts = {}) def save_png(opts = {})
opts = needs(opts,[:range, :creatable_dir, :prefix, :rotate]) opts = needs(opts,[:range, :creatable_dir, :prefix, :rotate])
@progress_bar.start("Saving PNGs to #{opts[:dir]}/#{opts[:prefix]}*", @cards.size) do |bar| @progress_bar.start("Saving PNGs to #{opts[:dir]}/#{opts[:prefix]}*", @cards.size) do |bar|
opts[:range].each do |i| opts[:range].each do |i|
@cards[i].save_png(i, opts[:dir], opts[:prefix], opts[:rotate], opts[:angle]) @cards[i].save_png(i, opts[:dir], opts[:prefix], opts[:rotate], opts[:angle])
bar.increment bar.increment
end end

8
lib/squib/api/settings.rb

@ -1,7 +1,7 @@
module Squib module Squib
class Deck class Deck
# Toggle hints globally. # Toggle hints globally.
# #
# Text hints are rectangles around where the text will be laid out. They are intended to be temporary. # Text hints are rectangles around where the text will be laid out. They are intended to be temporary.
# Setting a hint to nil or to :off will disable hints. @see samples/text.rb # Setting a hint to nil or to :off will disable hints. @see samples/text.rb
@ -9,7 +9,7 @@ module Squib
# hint text: :cyan # hint text: :cyan
# hint text: :cyan # hint text: :cyan
# #
# @param [String] text the color of the text hint. To turn off use :off. @see README.md # @param [String] text the color of the text hint. To turn off use :off. @see README.md
# @return [nil] Returns nothing # @return [nil] Returns nothing
# @api public # @api public
def hint(text: :off) def hint(text: :off)
@ -17,7 +17,7 @@ module Squib
end end
# Sets various defaults for this deck. Defaults can be overriden by the commands themselves when that command supports it. # Sets various defaults for this deck. Defaults can be overriden by the commands themselves when that command supports it.
# @example # @example
# set font: 'Arial 26' # set font: 'Arial 26'
# text 'blah' # in Arial 26 # text 'blah' # in Arial 26
# text 'blah24', font: 'Arial 24' # in Arial 24 # text 'blah24', font: 'Arial 24' # in Arial 24
@ -31,7 +31,7 @@ module Squib
opts = needs(opts, [:font, :img_dir]) opts = needs(opts, [:font, :img_dir])
@font = opts[:font][0] #was expanded - just need the first @font = opts[:font][0] #was expanded - just need the first
@img_dir = opts[:img_dir] @img_dir = opts[:img_dir]
end end
end end
end end

38
lib/squib/api/shapes.rb

@ -1,11 +1,11 @@
module Squib module Squib
class Deck class Deck
# Draw a rounded rectangle # Draw a rounded rectangle
# #
# @example # @example
# rect x: 0, y: 0, width: 825, height: 1125, radius: 25 # rect x: 0, y: 0, width: 825, height: 1125, radius: 25
# #
# Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion} # Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
# #
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges} # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
@ -26,16 +26,16 @@ module Squib
opts = needs(opts, [:range, :x, :y, :width, :height, :rect_radius, :x_radius, :y_radius, opts = needs(opts, [:range, :x, :y, :width, :height, :rect_radius, :x_radius, :y_radius,
:fill_color, :stroke_color, :stroke_width, :layout]) :fill_color, :stroke_color, :stroke_width, :layout])
opts[:range].each do |i| opts[:range].each do |i|
@cards[i].rect(opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i], @cards[i].rect(opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
opts[:x_radius][i], opts[:y_radius][i], opts[:x_radius][i], opts[:y_radius][i],
opts[:fill_color][i], opts[:stroke_color][i], opts[:fill_color][i], opts[:stroke_color][i],
opts[:stroke_width][i]) opts[:stroke_width][i])
end end
end end
# Draw a circle centered at the given coordinates # Draw a circle centered at the given coordinates
# #
# @example # @example
# circle x: 0, y: 0, radius: 100 # circle x: 0, y: 0, radius: 100
# #
# Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion} # Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
@ -54,14 +54,14 @@ module Squib
opts = needs(opts, [:range, :x, :y, :circle_radius, :layout, opts = needs(opts, [:range, :x, :y, :circle_radius, :layout,
:fill_color, :stroke_color, :stroke_width]) :fill_color, :stroke_color, :stroke_width])
opts[:range].each do |i| opts[:range].each do |i|
@cards[i].circle(opts[:x][i], opts[:y][i], opts[:radius][i], @cards[i].circle(opts[:x][i], opts[:y][i], opts[:radius][i],
opts[:fill_color][i], opts[:stroke_color][i], opts[:stroke_width][i]) opts[:fill_color][i], opts[:stroke_color][i], opts[:stroke_width][i])
end end
end end
# Draw a triangle using the given coordinates # Draw a triangle using the given coordinates
# #
# @example # @example
# triangle :x1 => 0, :y1 => 0, :x2 => 50, :y2 => 50, :x3 => 0, :y3 => 50 # triangle :x1 => 0, :y1 => 0, :x2 => 50, :y2 => 50, :x3 => 0, :y3 => 50
# #
# Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion} # Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
@ -82,17 +82,17 @@ module Squib
opts = needs(opts, [:range, :x1, :y1, :x2, :y2, :x3, :y3, :layout, opts = needs(opts, [:range, :x1, :y1, :x2, :y2, :x3, :y3, :layout,
:fill_color, :stroke_color, :stroke_width]) :fill_color, :stroke_color, :stroke_width])
opts[:range].each do |i| opts[:range].each do |i|
@cards[i].triangle(opts[:x1][i], opts[:y1][i], @cards[i].triangle(opts[:x1][i], opts[:y1][i],
opts[:x2][i], opts[:y2][i], opts[:x2][i], opts[:y2][i],
opts[:x3][i], opts[:y3][i], opts[:x3][i], opts[:y3][i],
opts[:fill_color][i], opts[:stroke_color][i], opts[:fill_color][i], opts[:stroke_color][i],
opts[:stroke_width][i]) opts[:stroke_width][i])
end end
end end
# Draw a line using the given coordinates # Draw a line using the given coordinates
# #
# @example # @example
# triangle :x1 => 0, :y1 => 0, :x2 => 50, :y2 => 50 # triangle :x1 => 0, :y1 => 0, :x2 => 50, :y2 => 50
# #
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges} # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
@ -112,6 +112,6 @@ module Squib
opts[:stroke_color][i], opts[:stroke_width][i]) opts[:stroke_color][i], opts[:stroke_width][i])
end end
end end
end end
end end

20
lib/squib/api/text.rb

@ -3,20 +3,20 @@ module Squib
# Renders a string at a given location, width, alignment, font, etc. # Renders a string at a given location, width, alignment, font, etc.
# #
# Unix-like newlines are interpreted even on Windows. # Unix-like newlines are interpreted even on Windows.
# See the {file:samples/text-options.rb samples/text.rb} for a lengthy example. # See the {file:samples/text-options.rb samples/text.rb} for a lengthy example.
# #
# @example # @example
# text str: 'hello' # text str: 'hello'
# text str: 'hello', x: 50, y:50, align: center # text str: 'hello', x: 50, y:50, align: center
# #
# Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion} # Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
# #
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges} # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
# @option opts str [String, Array] ('') the string to be rendered. Must support `#to_s`. If the card responds to `#each`, it's mapped out one at a time across the cards. # @option opts str [String, Array] ('') the string to be rendered. Must support `#to_s`. If the card responds to `#each`, it's mapped out one at a time across the cards.
# @option opts font [String] (Arial 36 or whatever was set with `set`) the Font description string, including family, styles, and size. # @option opts font [String] (Arial 36 or whatever was set with `set`) the Font description string, including family, styles, and size.
# (e.g. `'Arial bold italic 12'`) # (e.g. `'Arial bold italic 12'`)
# For the official documentation, see the [Pango docs](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Pango%3A%3AFontDescription#style). # For the official documentation, see the [Pango docs](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Pango%3A%3AFontDescription#style).
# This [description](http://www.pygtk.org/pygtk2reference/class-pangofontdescription.html) is also quite good. # This [description](http://www.pygtk.org/pygtk2reference/class-pangofontdescription.html) is also quite good.
# See the {file:samples/text-options.rb samples/text.rb} as well. # See the {file:samples/text-options.rb samples/text.rb} as well.
# @option opts font_size [Integer] (nil) an override of font string description, for scaling the font according to the size of the string # @option opts font_size [Integer] (nil) an override of font string description, for scaling the font according to the size of the string
@ -27,15 +27,15 @@ module Squib
# @option opts width [Integer, :native] (:native) the width of the box the string will be placed in. Stretches to the content by default. # @option opts width [Integer, :native] (:native) the width of the box the string will be placed in. Stretches to the content by default.
# @option opts height [Integer, :native] the height of the box the string will be placed in. Stretches to the content by default. # @option opts height [Integer, :native] the height of the box the string will be placed in. Stretches to the content by default.
# @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts} # @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts}
# @option opts wrap [:none, :word, :char, :word_char, true, false] (:word_char) When height is set, determines the behavior of how the string wraps. The `:word_char` option will break at words, but then fall back to characters when the word cannot fit. # # @option opts wrap [:none, :word, :char, :word_char, true, false] (:word_char) When height is set, determines the behavior of how the string wraps. The `:word_char` option will break at words, but then fall back to characters when the word cannot fit. #
# Options are `:none, :word, :char, :word_char`. Also: `true` is the same as `:word_char`, `false` is the same as `:none`. Default `:word_char` # Options are `:none, :word, :char, :word_char`. Also: `true` is the same as `:word_char`, `false` is the same as `:none`. Default `:word_char`
# @option opts spacing [Integer] (0) Adjust the spacing when the text is multiple lines. No effect when the text does not wrap. # @option opts spacing [Integer] (0) Adjust the spacing when the text is multiple lines. No effect when the text does not wrap.
# @option opts align [:left, right, :center] (:left) The alignment of the text # @option opts align [:left, right, :center] (:left) The alignment of the text
# @option opts justify [Boolean] (false) toggles whether or not the text is justified or not. # @option opts justify [Boolean] (false) toggles whether or not the text is justified or not.
# @option opts valign [:top, :middle, :bottom] (:top) When width and height are set, align text vertically according to the ink extents of the text. # @option opts valign [:top, :middle, :bottom] (:top) When width and height are set, align text vertically according to the ink extents of the text.
# @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` # @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`
# @option opts angle [FixNum] (0) Rotation of the text in radians. # @option opts angle [FixNum] (0) Rotation of the text in radians.
# @option opts hint [String] (:nil) draw a rectangle around the text with the given color. Overrides global hints (see {Deck#hint}). # @option opts hint [String] (:nil) draw a rectangle around the text with the given color. Overrides global hints (see {Deck#hint}).
# @return [nil] Returns nothing # @return [nil] Returns nothing
# @api public # @api public
def text(opts = {}) def text(opts = {})
@ -44,8 +44,8 @@ module Squib
opts[:range].each do |i| opts[:range].each do |i|
@cards[i].text(opts[:str][i], opts[:font][i], opts[:font_size][i], opts[:color][i], @cards[i].text(opts[:str][i], opts[:font][i], opts[:font_size][i], opts[:color][i],
opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i], opts[:x][i], opts[:y][i], opts[:width][i], opts[:height][i],
opts[:markup][i], opts[:justify][i], opts[:wrap][i], opts[:markup][i], opts[:justify][i], opts[:wrap][i],
opts[:ellipsize][i], opts[:spacing][i], opts[:align][i], opts[:ellipsize][i], opts[:spacing][i], opts[:align][i],
opts[:valign][i], opts[:hint][i], opts[:angle][i]) opts[:valign][i], opts[:hint][i], opts[:angle][i])
end end
end end

4
lib/squib/api/units.rb

@ -2,8 +2,8 @@ module Squib
class Deck class Deck
# Given inches, returns the number of pixels according to the deck's DPI. # Given inches, returns the number of pixels according to the deck's DPI.
# #
# @example # @example
# inches(2.5) # 750 (for default Deck::dpi of 300) # inches(2.5) # 750 (for default Deck::dpi of 300)
# #
# @param [Decimal] n, the number of inches # @param [Decimal] n, the number of inches

8
lib/squib/card.rb

@ -7,15 +7,15 @@ module Squib
include Squib::InputHelpers include Squib::InputHelpers
# :nodoc: # :nodoc:
# @api private # @api private
attr_reader :width, :height attr_reader :width, :height
# :nodoc: # :nodoc:
# @api private # @api private
attr_accessor :cairo_surface, :cairo_context attr_accessor :cairo_surface, :cairo_context
# :nodoc: # :nodoc:
# @api private # @api private
def initialize(deck, width, height) def initialize(deck, width, height)
@deck=deck; @width=width; @height=height @deck=deck; @width=width; @height=height
@cairo_surface = Cairo::ImageSurface.new(width,height) @cairo_surface = Cairo::ImageSurface.new(width,height)
@ -37,6 +37,6 @@ module Squib
require 'squib/graphics/save_images' require 'squib/graphics/save_images'
require 'squib/graphics/shapes' require 'squib/graphics/shapes'
require 'squib/graphics/text' require 'squib/graphics/text'
end end
end end

6
lib/squib/commands/new.rb

@ -6,9 +6,9 @@ module Squib
# Generate a new Squib project into a fresh directory. # Generate a new Squib project into a fresh directory.
# #
# Provides conventions for using Git (you are using version control, right??). # Provides conventions for using Git (you are using version control, right??).
# Also provides some basic layout and config files to start from, along with templates for instructions and other notes you don't want to forget. # Also provides some basic layout and config files to start from, along with templates for instructions and other notes you don't want to forget.
# #
# #
# @example # @example
# squib new foo-blasters # squib new foo-blasters
@ -22,7 +22,7 @@ module Squib
class New class New
# :nodoc: # :nodoc:
# @api private # @api private
def process(args) def process(args)
raise ArgumentError.new('Please specify a path.') if args.empty? raise ArgumentError.new('Please specify a path.') if args.empty?

14
lib/squib/constants.rb

@ -1,8 +1,8 @@
module Squib module Squib
# Squib's defaults for when arguments are not specified in the command nor layouts. # Squib's defaults for when arguments are not specified in the command nor layouts.
# #
# @api public # @api public
SYSTEM_DEFAULTS = { SYSTEM_DEFAULTS = {
:align => :left, :align => :left,
:alpha => 1.0, :alpha => 1.0,
:angle => 0, :angle => 0,
@ -40,7 +40,7 @@ module Squib
:x1 => 100, :x1 => 100,
:x2 => 150, :x2 => 150,
:x3 => 100, :x3 => 100,
:x_radius => 0, :x_radius => 0,
:y => 0, :y => 0,
:y1 => 100, :y1 => 100,
:y2 => 150, :y2 => 150,
@ -49,9 +49,9 @@ module Squib
} }
# Squib's configuration defaults # Squib's configuration defaults
# #
# @api public # @api public
CONFIG_DEFAULTS = { CONFIG_DEFAULTS = {
'custom_colors' => {}, 'custom_colors' => {},
'dpi' => 300, 'dpi' => 300,
'hint' => :none, 'hint' => :none,
@ -59,8 +59,8 @@ module Squib
'img_dir' => '.', 'img_dir' => '.',
} }
# These are parameters that are intended to be "expanded" across # These are parameters that are intended to be "expanded" across
# range if they are singletons. # range if they are singletons.
# #
# For example, using a different font for each card, using one `text` # For example, using a different font for each card, using one `text`
# #

36
lib/squib/deck.rb

@ -19,37 +19,37 @@ module Squib
include Squib::InputHelpers include Squib::InputHelpers
# :nodoc: # :nodoc:
# @api private # @api private
attr_reader :width, :height attr_reader :width, :height
# :nodoc: # :nodoc:
# @api private # @api private
attr_reader :cards attr_reader :cards
# :nodoc: # :nodoc:
# @api private # @api private
attr_reader :text_hint attr_reader :text_hint
# :nodoc: # :nodoc:
# @api private # @api private
attr_reader :layout, :config attr_reader :layout, :config
# Squib's constructor that sets the immutable properties. # Squib's constructor that sets the immutable properties.
# #
# This is the starting point for Squib. In providing a block to the constructor, you have access to all of Deck's instance methods. # This is the starting point for Squib. In providing a block to the constructor, you have access to all of Deck's instance methods.
# The documented methods in Deck are the ones intended for use by most users. # The documented methods in Deck are the ones intended for use by most users.
# If your game requires multiple different sizes or orientations, I recommend using multiple `Squib::Deck`s in your `deck.rb`. You can modify the internals of `Squib::Deck` (e.g. `@cards`), but that's not recommended. # If your game requires multiple different sizes or orientations, I recommend using multiple `Squib::Deck`s in your `deck.rb`. You can modify the internals of `Squib::Deck` (e.g. `@cards`), but that's not recommended.
# @example # @example
# require 'squib' # require 'squib'
# Squib::Deck.new do # Squib::Deck.new do
# text str: 'Hello, World!' # text str: 'Hello, World!'
# end # end
# #
# @param width: [Integer] the width of each card in pixels # @param width [Integer] the width of each card in pixels
# @param height: [Integer] the height of each card in pixels # @param height [Integer] the height of each card in pixels
# @param cards: [Integer] the number of cards in the deck # @param cards [Integer] the number of cards in the deck
# @param dpi: [Integer] the pixels per inch when rendering out to PDF or calculating using inches. # @param dpi [Integer] the pixels per inch when rendering out to PDF or calculating using inches.
# @param config: [String] the file used for global settings of this deck # @param config [String] the file used for global settings of this deck
# @param block [Block] the main body of the script. # @param block [Block] the main body of the script.
# @api public # @api public
def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block) def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block)
@ -77,7 +77,7 @@ module Squib
end end
# Iterates over each card in the deck # Iterates over each card in the deck
# #
# @api private # @api private
def each(&block) def each(&block)
@cards.each { |card| block.call(card) } @cards.each { |card| block.call(card) }
@ -129,10 +129,10 @@ module Squib
parent_val + child_val.sub("+=",'').strip.to_f parent_val + child_val.sub("+=",'').strip.to_f
elsif child_val.to_s.strip.start_with?('-=') elsif child_val.to_s.strip.start_with?('-=')
parent_val - child_val.sub("-=",'').strip.to_f parent_val - child_val.sub("-=",'').strip.to_f
else else
child_val #child overrides parent when merging, no += child_val #child overrides parent when merging, no +=
end end
end end
h = h.merge(from_extends) do |key, older_sibling, younger_sibling| h = h.merge(from_extends) do |key, older_sibling, younger_sibling|
younger_sibling #when two siblings have the same entry, the "younger" (lower one) overrides younger_sibling #when two siblings have the same entry, the "younger" (lower one) overrides
end end

4
lib/squib/graphics/background.rb

@ -2,13 +2,13 @@ module Squib
class Card class Card
# :nodoc: # :nodoc:
# @api private # @api private
def background(color) def background(color)
use_cairo do |cc| use_cairo do |cc|
cc.set_source_color(color) cc.set_source_color(color)
cc.paint cc.paint
end end
end end
end end
end end

6
lib/squib/graphics/image.rb

@ -1,7 +1,7 @@
module Squib module Squib
# Cache all pngs we've already loaded # Cache all pngs we've already loaded
# #
# :nodoc: # :nodoc:
# @api private # @api private
def cache_load_image(file) def cache_load_image(file)
@ -13,7 +13,7 @@ module Squib
class Card class Card
# :nodoc: # :nodoc:
# @api private # @api private
def png(file, x, y, alpha, blend) def png(file, x, y, alpha, blend)
return if file.nil? or file.eql? '' return if file.nil? or file.eql? ''
png = Squib.cache_load_image(file) png = Squib.cache_load_image(file)
@ -25,7 +25,7 @@ module Squib
end end
# :nodoc: # :nodoc:
# @api private # @api private
def svg(file, id, x, y, width, height, alpha, blend) def svg(file, id, x, y, width, height, alpha, blend)
Squib.logger.debug {"Rendering: #{file}, #{id} #{x}, #{y}, #{width}, #{height}, #{alpha}, #{blend}"} Squib.logger.debug {"Rendering: #{file}, #{id} #{x}, #{y}, #{width}, #{height}, #{alpha}, #{blend}"}
return if file.nil? or file.eql? '' return if file.nil? or file.eql? ''

4
lib/squib/graphics/save_doc.rb

@ -9,7 +9,7 @@ module Squib
# @option opts file [String] the name of the PDF file to save. See {file:README.md#Specifying_Files Specifying Files} # @option opts file [String] the name of the PDF file to save. See {file:README.md#Specifying_Files Specifying Files}
# @option opts dir [String] (_output) the directory to save to. Created if it doesn't exist. # @option opts dir [String] (_output) the directory to save to. Created if it doesn't exist.
# @option opts margin [Integer] (75) the margin around the outside of the page # @option opts margin [Integer] (75) the margin around the outside of the page
# @option opts gap [Integer] (0) the space in pixels between the cards # @option opts gap [Integer] (0) the space in pixels between the cards
# @option opts trim [Integer] (0) the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play) # @option opts trim [Integer] (0) the space around the edge of each card to trim (e.g. to cut off the bleed margin for print-and-play)
# @return [nil] # @return [nil]
# @api public # @api public
@ -39,7 +39,7 @@ module Squib
end end
# :nodoc: # :nodoc:
# @api private # @api private
def trim(surface, trim, width, height) def trim(surface, trim, width, height)
if trim > 0 if trim > 0
tmp = Cairo::ImageSurface.new(width-2*trim, height-2*trim) tmp = Cairo::ImageSurface.new(width-2*trim, height-2*trim)

4
lib/squib/graphics/save_images.rb

@ -2,7 +2,7 @@ module Squib
class Card class Card
# :nodoc: # :nodoc:
# @api private # @api private
def save_png(i, dir, prefix, do_rotate, angle) def save_png(i, dir, prefix, do_rotate, angle)
if [true, :clockwise, :counterclockwise].include?(do_rotate) if [true, :clockwise, :counterclockwise].include?(do_rotate)
surface = rotated_image(angle) surface = rotated_image(angle)
@ -24,7 +24,7 @@ module Squib
rotated_cc.target rotated_cc.target
end end
# :nodoc: # :nodoc:
# @api private # @api private
def write_png(surface, i, dir, prefix) def write_png(surface, i, dir, prefix)
surface.write_to_png("#{dir}/#{prefix}#{i}.png") surface.write_to_png("#{dir}/#{prefix}#{i}.png")
end end

12
lib/squib/graphics/shapes.rb

@ -1,8 +1,8 @@
module Squib module Squib
class Card class Card
# :nodoc: # :nodoc:
# @api private # @api private
def rect(x, y, width, height, x_radius, y_radius, fill_color, stroke_color, stroke_width) def rect(x, y, width, height, x_radius, y_radius, fill_color, stroke_color, stroke_width)
width=@width if width==:native; height=@height if height==:native width=@width if width==:native; height=@height if height==:native
use_cairo do |cc| use_cairo do |cc|
@ -17,7 +17,7 @@ module Squib
end end
# :nodoc: # :nodoc:
# @api private # @api private
def circle(x, y, radius, fill_color, stroke_color, stroke_width) def circle(x, y, radius, fill_color, stroke_color, stroke_width)
use_cairo do |cc| use_cairo do |cc|
cc.circle(x, y, radius) cc.circle(x, y, radius)
@ -31,7 +31,7 @@ module Squib
end end
# :nodoc: # :nodoc:
# @api private # @api private
def triangle(x1, y1, x2, y2, x3, y3, fill_color, stroke_color, stroke_width) def triangle(x1, y1, x2, y2, x3, y3, fill_color, stroke_color, stroke_width)
use_cairo do |cc| use_cairo do |cc|
cc.triangle(x1, y1, x2, y2, x3, y3) cc.triangle(x1, y1, x2, y2, x3, y3)
@ -45,7 +45,7 @@ module Squib
end end
# :nodoc: # :nodoc:
# @api private # @api private
def line(x1, y1, x2, y2, stroke_color, stroke_width) def line(x1, y1, x2, y2, stroke_color, stroke_width)
use_cairo do |cc| use_cairo do |cc|
cc.move_to(x1, y1) cc.move_to(x1, y1)
@ -55,6 +55,6 @@ module Squib
cc.stroke cc.stroke
end end
end end
end end
end end

26
lib/squib/graphics/text.rb

@ -4,7 +4,7 @@ module Squib
class Card class Card
# :nodoc: # :nodoc:
# @api private # @api private
def draw_text_hint(cc,x,y,layout, color,angle) def draw_text_hint(cc,x,y,layout, color,angle)
color = @deck.text_hint if color.to_s.eql? 'off' and not @deck.text_hint.to_s.eql? 'off' color = @deck.text_hint if color.to_s.eql? 'off' and not @deck.text_hint.to_s.eql? 'off'
return if color.to_s.eql? 'off' or color.nil? return if color.to_s.eql? 'off' or color.nil?
@ -22,7 +22,7 @@ module Squib
end end
# :nodoc: # :nodoc:
# @api private # @api private
def ellipsize(layout, ellipsize) def ellipsize(layout, ellipsize)
unless ellipsize.nil? unless ellipsize.nil?
h = { :none => Pango::Layout::ELLIPSIZE_NONE, h = { :none => Pango::Layout::ELLIPSIZE_NONE,
@ -38,7 +38,7 @@ module Squib
end end
# :nodoc: # :nodoc:
# @api private # @api private
def wrap(layout, wrap) def wrap(layout, wrap)
unless wrap.nil? unless wrap.nil?
h = { :word => Pango::Layout::WRAP_WORD, h = { :word => Pango::Layout::WRAP_WORD,
@ -54,7 +54,7 @@ module Squib
end end
# :nodoc: # :nodoc:
# @api private # @api private
def align(layout, align) def align(layout, align)
unless align.nil? unless align.nil?
h = { :left => Pango::ALIGN_LEFT, h = { :left => Pango::ALIGN_LEFT,
@ -67,9 +67,9 @@ module Squib
end end
# :nodoc: # :nodoc:
# @api private # @api private
def valign(cc, layout, x, y, valign) def valign(cc, layout, x, y, valign)
if layout.height > 0 if layout.height > 0
ink_extents = layout.extents[1] ink_extents = layout.extents[1]
case valign case valign
when :middle when :middle
@ -81,7 +81,7 @@ module Squib
end end
# :nodoc: # :nodoc:
# @api private # @api private
def setwh(layout, width, height) def setwh(layout, width, height)
layout.width = width * Pango::SCALE unless width.nil? || width == :native layout.width = width * Pango::SCALE unless width.nil? || width == :native
layout.height = height * Pango::SCALE unless height.nil? || height == :native layout.height = height * Pango::SCALE unless height.nil? || height == :native
@ -89,17 +89,17 @@ module Squib
end end
# :nodoc: # :nodoc:
# @api private # @api private
def text(str, font, font_size, color, def text(str, font, font_size, color,
x, y, width, height, x, y, width, height,
markup, justify, wrap, ellipsize, markup, justify, wrap, ellipsize,
spacing, align, valign, hint, angle) spacing, align, valign, hint, angle)
Squib.logger.debug {"Placing '#{str}'' with font '#{font}' @ #{x}, #{y}, color: #{color}, angle: #{angle} etc."} Squib.logger.debug {"Placing '#{str}'' with font '#{font}' @ #{x}, #{y}, color: #{color}, angle: #{angle} etc."}
use_cairo do |cc| use_cairo do |cc|
cc.set_source_color(color) cc.set_source_color(color)
cc.move_to(x,y) cc.move_to(x,y)
cc.rotate(angle) cc.rotate(angle)
layout = cc.create_pango_layout layout = cc.create_pango_layout
font_desc = Pango::FontDescription.new(font) font_desc = Pango::FontDescription.new(font)
font_desc.size = font_size * Pango::SCALE unless font_size.nil? font_desc.size = font_size * Pango::SCALE unless font_size.nil?
@ -111,8 +111,8 @@ module Squib
layout = ellipsize(layout, ellipsize) layout = ellipsize(layout, ellipsize)
layout = align(layout, align) layout = align(layout, align)
layout.justify = justify unless justify.nil? layout.justify = justify unless justify.nil?
layout.spacing = spacing * Pango::SCALE unless spacing.nil? layout.spacing = spacing * Pango::SCALE unless spacing.nil?
cc.update_pango_layout(layout) cc.update_pango_layout(layout)
valign(cc, layout, x,y, valign) valign(cc, layout, x,y, valign)
cc.update_pango_layout(layout) ; cc.show_pango_layout(layout) cc.update_pango_layout(layout) ; cc.show_pango_layout(layout)
draw_text_hint(cc,x,y,layout,hint,angle) draw_text_hint(cc,x,y,layout,hint,angle)

20
lib/squib/input_helpers.rb

@ -12,7 +12,7 @@ module Squib
opts = layoutify(opts) if params.include? :layout opts = layoutify(opts) if params.include? :layout
opts = Squib::SYSTEM_DEFAULTS.merge(opts) opts = Squib::SYSTEM_DEFAULTS.merge(opts)
opts = expand_singletons(opts, params) opts = expand_singletons(opts, params)
opts = rangeify(opts) if params.include? :range opts = rangeify(opts) if params.include? :range
opts = fileify(opts) if params.include? :file opts = fileify(opts) if params.include? :file
opts = fileify(opts, false) if params.include? :file_to_save opts = fileify(opts, false) if params.include? :file_to_save
opts = colorify(opts, true) if params.include? :nillable_color opts = colorify(opts, true) if params.include? :nillable_color
@ -37,7 +37,7 @@ module Squib
Squib::EXPANDING_PARAMS.each_pair do |param_name, api_param| Squib::EXPANDING_PARAMS.each_pair do |param_name, api_param|
if needed_params.include? param_name if needed_params.include? param_name
unless opts[api_param].respond_to?(:each) unless opts[api_param].respond_to?(:each)
opts[api_param] = [opts[api_param]] * @cards.size opts[api_param] = [opts[api_param]] * @cards.size
end end
end end
end end
@ -50,8 +50,8 @@ module Squib
# :nodoc: # :nodoc:
# @api private # @api private
def layoutify(opts) def layoutify(opts)
unless opts[:layout].respond_to?(:each) unless opts[:layout].respond_to?(:each)
opts[:layout] = [opts[:layout]] * @cards.size opts[:layout] = [opts[:layout]] * @cards.size
end end
opts[:layout].each_with_index do |layout, i| opts[:layout].each_with_index do |layout, i|
unless layout.nil? unless layout.nil?
@ -61,7 +61,7 @@ module Squib
opts[key.to_sym] = [] if opts[key.to_sym].nil? opts[key.to_sym] = [] if opts[key.to_sym].nil?
opts[key.to_sym][i] ||= entry[key] #don't override if it's already there opts[key.to_sym][i] ||= entry[key] #don't override if it's already there
end end
else else
Squib.logger.warn ("Layout entry '#{layout}' does not exist." ) Squib.logger.warn ("Layout entry '#{layout}' does not exist." )
end end
end end
@ -99,7 +99,7 @@ module Squib
# @api private # @api private
def fileify(opts, file_must_exist=true) def fileify(opts, file_must_exist=true)
[opts[:file]].flatten.each do |file| [opts[:file]].flatten.each do |file|
if file_must_exist and !File.exists?(file) if file_must_exist and !File.exists?(file)
raise "File #{File.expand_path(file)} does not exist!" raise "File #{File.expand_path(file)} does not exist!"
end end
end end
@ -114,7 +114,7 @@ module Squib
if allow_create if allow_create
Squib.logger.warn {"Dir #{opts[key]} does not exist, creating it."} Squib.logger.warn {"Dir #{opts[key]} does not exist, creating it."}
Dir.mkdir opts[key] Dir.mkdir opts[key]
return opts return opts
else else
raise "'#{opts[key]}' does not exist!" raise "'#{opts[key]}' does not exist!"
end end
@ -145,14 +145,14 @@ module Squib
opts[:font][i] = Squib::SYSTEM_DEFAULTS[:default_font] if font == :default opts[:font][i] = Squib::SYSTEM_DEFAULTS[:default_font] if font == :default
end end
Squib.logger.debug {"After fontify: #{opts}"} Squib.logger.debug {"After fontify: #{opts}"}
opts opts
end end
module_function :fontify module_function :fontify
# :nodoc: # :nodoc:
# @api private # @api private
def radiusify(opts) def radiusify(opts)
opts[:radius].each_with_index do |radius, i| opts[:radius].each_with_index do |radius, i|
unless radius.nil? unless radius.nil?
opts[:x_radius][i] = radius opts[:x_radius][i] = radius
opts[:y_radius][i] = radius opts[:y_radius][i] = radius

4
lib/squib/progress.rb

@ -25,10 +25,10 @@ module Squib
def start(title="", total=100, &block) def start(title="", total=100, &block)
if @enabled if @enabled
@bar = ProgressBar.create(title: title, total: total, format: '%t <%B> %p%% %a') @bar = ProgressBar.create(title: title, total: total, format: '%t <%B> %p%% %a')
yield(@bar) yield(@bar)
@bar.finish @bar.finish
else else
yield(Squib::DoNothing.new) yield(Squib::DoNothing.new)
end end
end end

2
lib/squib/project_template/deck.rb

@ -1,6 +1,6 @@
require 'squib' require 'squib'
Squib::Deck.new(cards: 3, layout: 'layout.yml') do Squib::Deck.new(cards: 3, layout: 'layout.yml') do
text str: "Hello, World!" text str: "Hello, World!"
save format: :png save format: :png
end end

4
lib/squib/version.rb

@ -3,8 +3,8 @@ module Squib
# The next version to be released. # The next version to be released.
# Uses semantic versioning: http://semver.org/ # Uses semantic versioning: http://semver.org/
# #
# Most of the time this is in the alpha of the next release. # Most of the time this is in the alpha of the next release.
# e.g. v0.0.5a is on its way to becoming v0.0.5 # e.g. v0.0.5a is on its way to becoming v0.0.5
# #
VERSION = "0.0.5a" VERSION = "0.0.5a"
end end

6
samples/autoscale_font.rb

@ -1,7 +1,7 @@
require 'squib' require 'squib'
# Here's an exmaple of being able to scale a font # Here's an exmaple of being able to scale a font
# based on the length of individual string. # based on the length of individual string.
# Handy for making minor font scales to fill text boxes. # Handy for making minor font scales to fill text boxes.
def autoscale(str_array) def autoscale(str_array)
str_array.inject([]) do | memo, str | str_array.inject([]) do | memo, str |
@ -21,7 +21,7 @@ Squib::Deck.new(cards: 3) do
title = %w(ShortBig Medium_Length_Name Super_Duper_Long_Name) title = %w(ShortBig Medium_Length_Name Super_Duper_Long_Name)
text str: title, x: 65, y: 400, align: :center, width: 700, text str: title, x: 65, y: 400, align: :center, width: 700,
font: 'Arial', font_size: autoscale(title), hint: :red font: 'Arial', font_size: autoscale(title), hint: :red
save prefix: 'autoscale_', format: :png save prefix: 'autoscale_', format: :png
end end

4
samples/basic.rb

@ -1,7 +1,7 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'squib' require 'squib'
data = {'name' => ['Thief', 'Grifter', 'Mastermind'], data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
'level' => [1,2,3]} 'level' => [1,2,3]}
Squib::Deck.new(width: 825, height: 1125, cards: 3) do Squib::Deck.new(width: 825, height: 1125, cards: 3) do
@ -10,7 +10,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
rect x: 75, y: 75, width: 128, height: 128, radius: 25 rect x: 75, y: 75, width: 128, height: 128, radius: 25
text str: data['name'], x: 220, y: 78, font: 'Arial 54' text str: data['name'], x: 220, y: 78, font: 'Arial 54'
text str: data['level'], x: 75, y: 85, width: 128, text str: data['level'], x: 75, y: 85, width: 128,
font: 'Arial 72', align: :center font: 'Arial 72', align: :center
png range: [0,2], file: 'shiny-purse.png', x: 620, y: 75 png range: [0,2], file: 'shiny-purse.png', x: 620, y: 75

10
samples/custom-layout.yml

@ -1,4 +1,4 @@
frame: frame:
x: 38 x: 38
y: 38 y: 38
width: 750 width: 750
@ -10,7 +10,7 @@ title:
width: 625 width: 625
height: 100 height: 100
align: !ruby/symbol center #see http://www.yaml.org/YAML_for_ruby.html#symbols align: !ruby/symbol center #see http://www.yaml.org/YAML_for_ruby.html#symbols
valign: !ruby/symbol middle valign: !ruby/symbol middle
subtitle: subtitle:
x: 150 x: 150
y: 150 y: 150
@ -37,15 +37,15 @@ icon_right:
# Called "extends" # Called "extends"
# Any layout can extend another layout, so long as it's not a circle # Any layout can extend another layout, so long as it's not a circle
# Order doesn't matter since it's done after YAML procesing # Order doesn't matter since it's done after YAML procesing
# And, if the entry overrides # And, if the entry overrides
bonus: #becomes our bonus rectangle bonus: #becomes our bonus rectangle
x: 250 x: 250
y: 600 y: 600
width: 300 width: 300
height: 200 height: 200
radius: 32 radius: 32
bonus_inner: bonus_inner:
extends: bonus extends: bonus
x: += 10 # i.e. 260 x: += 10 # i.e. 260
y: += 10 # i.e. 610 y: += 10 # i.e. 610
width: -= 20 # i.e. 180 width: -= 20 # i.e. 180

2
samples/custom_config.rb

@ -3,7 +3,7 @@ require 'squib'
Squib::Deck.new(config: 'custom-config.yml') do Squib::Deck.new(config: 'custom-config.yml') do
# Custom color defined in our config # Custom color defined in our config
background color: :foo background color: :foo
# Hints are turned on in the config file # Hints are turned on in the config file
text str: "The Title", x: 0, y: 78, width: 825, text str: "The Title", x: 0, y: 78, width: 825,

14
samples/draw_shapes.rb

@ -1,19 +1,19 @@
require 'squib' require 'squib'
Squib::Deck.new do Squib::Deck.new do
rect x: 300, y: 300, width: 400, height: 400, rect x: 300, y: 300, width: 400, height: 400,
fill_color: :blue, stroke_color: :red, stroke_width: 50.0 fill_color: :blue, stroke_color: :red, stroke_width: 50.0
circle x: 600, y: 600, radius: 75, circle x: 600, y: 600, radius: 75,
fill_color: :gray, stroke_color: :green, stroke_width: 8.0 fill_color: :gray, stroke_color: :green, stroke_width: 8.0
triangle x1: 50, y1: 50, triangle x1: 50, y1: 50,
x2: 150, y2: 150, x2: 150, y2: 150,
x3: 75, y3: 250 x3: 75, y3: 250
line x1: 50, y1: 550, line x1: 50, y1: 550,
x2: 150, y2: 650, x2: 150, y2: 650,
stroke_width: 25.0 stroke_width: 25.0
save_png prefix: 'shape_' save_png prefix: 'shape_'
end end

2
samples/hello_world.rb

@ -2,6 +2,6 @@
require 'squib' require 'squib'
Squib::Deck.new do Squib::Deck.new do
text str: 'Hello, World!' text str: 'Hello, World!'
save_png save_png
end end

2
samples/load_images.rb

@ -19,7 +19,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 1) do
# relative to the SVG page. See this example in an SVG editor # relative to the SVG page. See this example in an SVG editor
svg file: 'offset.svg', id: 'thing', x: 0, y: 0, width: 600, height: 600 svg file: 'offset.svg', id: 'thing', x: 0, y: 0, width: 600, height: 600
# Over 15 different blending operators are supported. # Over 15 different blending operators are supported.
# See http://cairographics.org/operators # See http://cairographics.org/operators
# Alpha transparency too # Alpha transparency too
png file: 'ball.png', x: 50, y: 700 png file: 'ball.png', x: 50, y: 700

4
samples/portrait-landscape.rb

@ -1,11 +1,11 @@
require 'squib' require 'squib'
# For decks with both landscape and portrait orientations, # For decks with both landscape and portrait orientations,
# we recommend using two separate decks. # we recommend using two separate decks.
# For print-on-demand, we can rotate all of the images in the final step. # For print-on-demand, we can rotate all of the images in the final step.
# Normal cards # Normal cards
Squib::Deck.new(width: 825, height: 1125) do Squib::Deck.new(width: 825, height: 1125) do
background color: '#aaa' background color: '#aaa'
text str: "This is portrait" text str: "This is portrait"

16
samples/ranges.rb

@ -1,7 +1,7 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'squib' require 'squib'
data = {'name' => ['Thief', 'Grifter', 'Mastermind'], data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
'type' => ['Thug', 'Thinker', 'Thinker'], 'type' => ['Thug', 'Thinker', 'Thinker'],
'level' => [1,2,3]} 'level' => [1,2,3]}
@ -12,8 +12,8 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
text str: data['level'], x: 65, y: 40, font: 'Arial 72' text str: data['level'], x: 65, y: 40, font: 'Arial 72'
# Could be explicit about using :all, too # Could be explicit about using :all, too
text range: :all, text range: :all,
str: data['type'], x: 40, y: 128, font: 'Arial 18', str: data['type'], x: 40, y: 128, font: 'Arial 18',
width: 100, align: :center width: 100, align: :center
# Ranges are inclusive, zero-based # Ranges are inclusive, zero-based
@ -40,16 +40,16 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
# Useful idiom: construct a hash from card names back to its index (ID), # Useful idiom: construct a hash from card names back to its index (ID),
# then use a range. No need to memorize IDs, and you can add cards easily # then use a range. No need to memorize IDs, and you can add cards easily
id = {} ; data['name'].each_with_index{ |name,i| id[name] = i} id = {} ; data['name'].each_with_index{ |name,i| id[name] = i}
text range: id['Thief']..id['Grifter'], text range: id['Thief']..id['Grifter'],
str: "Thief through Grifter with id lookup!!", str: "Thief through Grifter with id lookup!!",
x:25, y: 400 x:25, y: 400
# Useful idiom: generate arrays from a column called 'type' # Useful idiom: generate arrays from a column called 'type'
type = {}; data['type'].each_with_index{ |t,i| (type[t] ||= []) << i} type = {}; data['type'].each_with_index{ |t,i| (type[t] ||= []) << i}
text range: type['Thinker'], text range: type['Thinker'],
str: "Only for Thinkers!", str: "Only for Thinkers!",
x:25, y: 500 x:25, y: 500
save prefix: 'ranges_', format: :png save prefix: 'ranges_', format: :png
end end

14
samples/text_options.rb

@ -1,7 +1,7 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'squib' require 'squib'
data = {'name' => ['Thief', 'Grifter', 'Mastermind'], data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
'level' => [1,2,3]} 'level' => [1,2,3]}
longtext = "This is left-justified text.\nWhat do you know about tweetle beetles? well... \nWhen tweetle beetles fight, it's called a tweetle beetle battle. And when they battle in a puddle, it's a tweetle beetle puddle battle. AND when tweetle beetles battle with paddles in a puddle, they call it a tweetle beetle puddle paddle battle. AND... When beetles battle beetles in a puddle paddle battle and the beetle battle puddle is a puddle in a bottle... ..they call this a tweetle beetle bottle puddle paddle battle muddle. AND... When beetles fight these battles in a bottle with their paddles and the bottle's on a poodle and the poodle's eating noodles... ...they call this a muddle puddle tweetle poodle beetle noodle bottle paddle battle." longtext = "This is left-justified text.\nWhat do you know about tweetle beetles? well... \nWhen tweetle beetles fight, it's called a tweetle beetle battle. And when they battle in a puddle, it's a tweetle beetle puddle battle. AND when tweetle beetles battle with paddles in a puddle, they call it a tweetle beetle puddle paddle battle. AND... When beetles battle beetles in a puddle paddle battle and the beetle battle puddle is a puddle in a bottle... ..they call this a tweetle beetle bottle puddle paddle battle muddle. AND... When beetles fight these battles in a bottle with their paddles and the bottle's on a poodle and the poodle's eating noodles... ...they call this a muddle puddle tweetle poodle beetle noodle bottle paddle battle."
@ -25,7 +25,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
text str: "Font string sizes can be overridden per card.", x: 65, y: 350, text str: "Font string sizes can be overridden per card.", x: 65, y: 350,
font: 'Impact 36', font_size: [16, 20, 24] font: 'Impact 36', font_size: [16, 20, 24]
text str: "This text has fixed width, fixed height, center-aligned, middle-valigned, and has a red hint", text str: "This text has fixed width, fixed height, center-aligned, middle-valigned, and has a red hint",
hint: :red, hint: :red,
x: 65, y: 400, x: 65, y: 400,
width: 300, height: 200, width: 300, height: 200,
@ -52,16 +52,16 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
font: 'Arial 18' font: 'Arial 18'
text str: longtext, font: 'Arial 16', text str: longtext, font: 'Arial 16',
x: 65, y: 700, x: 65, y: 700,
width: inches(2.25), height: inches(1), width: inches(2.25), height: inches(1),
justify: true justify: true
text str: "<b>Markup</b> is also <i>quite</i> <s>easy</s> awesome", text str: "<b>Markup</b> is also <i>quite</i> <s>easy</s> awesome",
markup: true, markup: true,
x: 50, y: 1000, x: 50, y: 1000,
width: 750, height: 100, width: 750, height: 100,
valign: :bottom, valign: :bottom,
font: 'Arial 32', hint: :cyan font: 'Arial 32', hint: :cyan
save prefix: 'text_', format: :png save prefix: 'text_', format: :png
end end

4
samples/tgc_proofs.rb

@ -2,7 +2,7 @@
require 'squib' require 'squib'
# This sample uses a proof overlay from TheGameCrafter.com to check bleed # This sample uses a proof overlay from TheGameCrafter.com to check bleed
Squib::Deck.new(width: 825, height: 1125, cards: 1) do Squib::Deck.new(width: 825, height: 1125, cards: 1) do
background color: :white background color: :white
rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38 rect x: 38, y: 38, width: 750, height: 1050, x_radius: 38, y_radius: 38
rect x: 75, y: 75, width: 128, height: 128, x_radius: 25, y_radius: 25 rect x: 75, y: 75, width: 128, height: 128, x_radius: 25, y_radius: 25
@ -15,6 +15,6 @@ Squib::Deck.new(width: 825, height: 1125, cards: 1) do
# TGC proof overlay # TGC proof overlay
png file: 'pokercard.png', x:0, y:0, alpha: 0.5 png file: 'pokercard.png', x:0, y:0, alpha: 0.5
save_png prefix: 'tgc_sample_' save_png prefix: 'tgc_sample_'
end end

4
samples/use_layout.rb

@ -1,6 +1,6 @@
require 'squib' require 'squib'
Squib::Deck.new(layout: 'custom-layout.yml') do Squib::Deck.new(layout: 'custom-layout.yml') do
background color: :white background color: :white
hint text: :cyan hint text: :cyan
@ -29,6 +29,6 @@ Squib::Deck.new(layout: 'custom-layout.yml') do
# For debugging purposes, you can always print out the loaded layout # For debugging purposes, you can always print out the loaded layout
#require 'pp' #require 'pp'
#pp @layout #pp @layout
save_png prefix: 'layout_' save_png prefix: 'layout_'
end end

18
spec/api/api_text_spec.rb

@ -6,22 +6,22 @@ describe Squib::Deck, '#text' do
context "fonts" do context "fonts" do
it "should use the default font when #text and #set_font don't specify" do it "should use the default font when #text and #set_font don't specify" do
card = instance_double(Squib::Card) card = instance_double(Squib::Card)
expect(card).to receive(:text).with('a', 'Arial 36', expect(card).to receive(:text).with('a', 'Arial 36',
anything, anything, anything,anything,anything,anything, anything, anything, anything,anything, anything, anything, anything, anything, anything anything, anything, anything,anything,anything,anything, anything, anything, anything,anything, anything, anything, anything, anything, anything
).once ).once
Squib::Deck.new do Squib::Deck.new do
@cards = [card] @cards = [card]
text str: 'a' text str: 'a'
end end
end end
it "should use the #set_font when #text doesn't specify" do it "should use the #set_font when #text doesn't specify" do
card = instance_double(Squib::Card) card = instance_double(Squib::Card)
expect(card).to receive(:text).with('a', 'Times New Roman 16', expect(card).to receive(:text).with('a', 'Times New Roman 16',
anything, anything, anything, anything,anything,anything, anything, anything, anything,anything, anything, anything, anything, anything, anything anything, anything, anything, anything,anything,anything, anything, anything, anything,anything, anything, anything, anything, anything, anything
).once ).once
Squib::Deck.new do Squib::Deck.new do
@cards = [card] @cards = [card]
set font: 'Times New Roman 16' set font: 'Times New Roman 16'
text str: 'a' text str: 'a'
end end
@ -29,11 +29,11 @@ describe Squib::Deck, '#text' do
it "should use the specified font no matter what" do it "should use the specified font no matter what" do
card = instance_double(Squib::Card) card = instance_double(Squib::Card)
expect(card).to receive(:text).with('a', 'Arial 18', expect(card).to receive(:text).with('a', 'Arial 18',
anything, anything, anything, anything,anything,anything,anything, anything, anything,anything, anything, anything, anything, anything, anything anything, anything, anything, anything,anything,anything,anything, anything, anything,anything, anything, anything, anything, anything, anything
).once ).once
Squib::Deck.new do Squib::Deck.new do
@cards = [card] @cards = [card]
set font: 'Times New Roman 16' set font: 'Times New Roman 16'
text str: 'a', font: 'Arial 18' text str: 'a', font: 'Arial 18'
end end

6
spec/commands/new_spec.rb

@ -1,9 +1,9 @@
require 'spec_helper' require 'spec_helper'
require 'squib' require 'squib'
describe Squib::Commands::New do describe Squib::Commands::New do
describe "#process" do describe "#process" do
before(:all) do before(:all) do
@old_stderr = $stderr @old_stderr = $stderr
$stderr = StringIO.new $stderr = StringIO.new
@ -44,5 +44,5 @@ describe Squib::Commands::New do
Dir.chdir(@oldpwd) Dir.chdir(@oldpwd)
end end
end end
end end

2
spec/data/easy-circular-extends.yml

@ -1,4 +1,4 @@
a: a:
extends: b extends: b
x: 50 x: 50
b: b:

4
spec/data/hard-circular-extends.yml

@ -1,9 +1,9 @@
a: a:
extends: c extends: c
x: 50 x: 50
b: b:
extends: a extends: a
x: 150 x: 150
c: c:
extends: b extends: b
y: 250 y: 250

6
spec/data/multi-extends-single-entry.yml

@ -1,13 +1,13 @@
aunt: aunt:
a: 101 a: 101
b: 102 b: 102
c: 103 c: 103
uncle: uncle:
x: 104 x: 104
y: 105 y: 105
b: 106 b: 106
child: child:
extends: extends:
- uncle - uncle
- aunt - aunt
a: 107 a: 107

2
spec/data/multi-level-extends.yml

@ -1,4 +1,4 @@
frame: frame:
x: 38 x: 38
y: 38 y: 38
title: title:

4
spec/data/no-extends.yml

@ -1,5 +1,5 @@
frame: frame:
x: 38 x: 38
valign: !ruby/symbol middle valign: !ruby/symbol middle
str: "blah" str: "blah"
font: Mr. Font font: Mr. Font

2
spec/data/pre-extends.yml

@ -2,6 +2,6 @@ title:
extends: frame extends: frame
y: 50 y: 50
width: 100 width: 100
frame: frame:
x: 38 x: 38
y: 38 y: 38

2
spec/data/self-circular-extends.yml

@ -1,3 +1,3 @@
a: a:
extends: a extends: a
x: 50 x: 50

2
spec/data/single-extends.yml

@ -1,4 +1,4 @@
frame: frame:
x: 38 x: 38
y: 38 y: 38
title: title:

2
spec/data/single-level-multi-extends.yml

@ -1,4 +1,4 @@
frame: frame:
x: 38 x: 38
y: 38 y: 38
title: title:

84
spec/deck_spec.rb

@ -1,10 +1,10 @@
require 'spec_helper' require 'spec_helper'
require 'squib/deck' require 'squib/deck'
describe Squib::Deck do describe Squib::Deck do
it "initializes with default parameters" do it "initializes with default parameters" do
d = Squib::Deck.new d = Squib::Deck.new
expect(d.width).to eq(825) expect(d.width).to eq(825)
expect(d.height).to eq(1125) expect(d.height).to eq(1125)
expect(d.cards.size).to eq(1) expect(d.cards.size).to eq(1)
@ -13,11 +13,11 @@ describe Squib::Deck do
context "in dealing with ranges" do context "in dealing with ranges" do
it "calls text on all cards by default" do it "calls text on all cards by default" do
card1 = instance_double(Squib::Card) card1 = instance_double(Squib::Card)
card2 = instance_double(Squib::Card) card2 = instance_double(Squib::Card)
expect(card1).to receive(:text).once expect(card1).to receive(:text).once
expect(card2).to receive(:text).once expect(card2).to receive(:text).once
Squib::Deck.new do Squib::Deck.new do
@cards = [card1, card2] @cards = [card1, card2]
text str: 'blah' text str: 'blah'
end end
end end
@ -26,11 +26,11 @@ describe Squib::Deck do
card1 = instance_double(Squib::Card) card1 = instance_double(Squib::Card)
card2 = instance_double(Squib::Card) card2 = instance_double(Squib::Card)
expect(card2).to receive(:text).once expect(card2).to receive(:text).once
Squib::Deck.new do Squib::Deck.new do
@cards = [card1, card2] @cards = [card1, card2]
text range: 1, str: 'blah' text range: 1, str: 'blah'
end end
end end
it "calls text with ranges" do it "calls text with ranges" do
card1 = instance_double(Squib::Card) card1 = instance_double(Squib::Card)
@ -38,8 +38,8 @@ describe Squib::Deck do
card3 = instance_double(Squib::Card) card3 = instance_double(Squib::Card)
expect(card1).to receive(:text).once expect(card1).to receive(:text).once
expect(card2).to receive(:text).once expect(card2).to receive(:text).once
Squib::Deck.new do Squib::Deck.new do
@cards = [card1, card2, card3] @cards = [card1, card2, card3]
text range: 0..1, str: 'blah' text range: 0..1, str: 'blah'
end end
end end
@ -48,10 +48,10 @@ describe Squib::Deck do
context "#load_layout" do context "#load_layout" do
it "loads a normal layout with no extends" do it "loads a normal layout with no extends" do
d = Squib::Deck.new(layout: test_file('no-extends.yml')) d = Squib::Deck.new(layout: test_file('no-extends.yml'))
expect(d.layout).to \ expect(d.layout).to \
eq({'frame' => { eq({'frame' => {
'x' => 38, 'x' => 38,
'valign' => :middle, 'valign' => :middle,
'str' => "blah", 'str' => "blah",
'font' => "Mr. Font", 'font' => "Mr. Font",
@ -61,16 +61,16 @@ describe Squib::Deck do
end end
it "loads with a single extends" do it "loads with a single extends" do
d = Squib::Deck.new(layout: test_file('single-extends.yml')) d = Squib::Deck.new(layout: test_file('single-extends.yml'))
expect(d.layout).to \ expect(d.layout).to \
eq({'frame' => { eq({'frame' => {
'x' => 38, 'x' => 38,
'y' => 38, 'y' => 38,
}, },
'title' => { 'title' => {
'extends' => 'frame', 'extends' => 'frame',
'x' => 38, 'x' => 38,
'y' => 50, 'y' => 50,
'width' => 100, 'width' => 100,
} }
} }
@ -78,16 +78,16 @@ describe Squib::Deck do
end end
it "applies the extends regardless of order" do it "applies the extends regardless of order" do
d = Squib::Deck.new(layout: test_file('pre-extends.yml')) d = Squib::Deck.new(layout: test_file('pre-extends.yml'))
expect(d.layout).to \ expect(d.layout).to \
eq({'frame' => { eq({'frame' => {
'x' => 38, 'x' => 38,
'y' => 38, 'y' => 38,
}, },
'title' => { 'title' => {
'extends' => 'frame', 'extends' => 'frame',
'x' => 38, 'x' => 38,
'y' => 50, 'y' => 50,
'width' => 100, 'width' => 100,
} }
} }
@ -95,22 +95,22 @@ describe Squib::Deck do
end end
it "applies the single-level extends multiple times" do it "applies the single-level extends multiple times" do
d = Squib::Deck.new(layout: test_file('single-level-multi-extends.yml')) d = Squib::Deck.new(layout: test_file('single-level-multi-extends.yml'))
expect(d.layout).to \ expect(d.layout).to \
eq({'frame' => { eq({'frame' => {
'x' => 38, 'x' => 38,
'y' => 38, 'y' => 38,
}, },
'title' => { 'title' => {
'extends' => 'frame', 'extends' => 'frame',
'x' => 38, 'x' => 38,
'y' => 50, 'y' => 50,
'width' => 100, 'width' => 100,
}, },
'title2' => { 'title2' => {
'extends' => 'frame', 'extends' => 'frame',
'x' => 75, 'x' => 75,
'y' => 150, 'y' => 150,
'width' => 150, 'width' => 150,
}, },
} }
@ -118,17 +118,17 @@ describe Squib::Deck do
end end
it "applies multiple extends in a single rule" do it "applies multiple extends in a single rule" do
d = Squib::Deck.new(layout: test_file('multi-extends-single-entry.yml')) d = Squib::Deck.new(layout: test_file('multi-extends-single-entry.yml'))
expect(d.layout).to \ expect(d.layout).to \
eq({'aunt' => { eq({'aunt' => {
'a' => 101, 'a' => 101,
'b' => 102, 'b' => 102,
'c' => 103, 'c' => 103,
}, },
'uncle' => { 'uncle' => {
'x' => 104, 'x' => 104,
'y' => 105, 'y' => 105,
'b' => 106, 'b' => 106,
}, },
'child' => { 'child' => {
'extends' => ['uncle','aunt'], 'extends' => ['uncle','aunt'],
@ -143,22 +143,22 @@ describe Squib::Deck do
end end
it "applies multi-level extends" do it "applies multi-level extends" do
d = Squib::Deck.new(layout: test_file('multi-level-extends.yml')) d = Squib::Deck.new(layout: test_file('multi-level-extends.yml'))
expect(d.layout).to \ expect(d.layout).to \
eq({'frame' => { eq({'frame' => {
'x' => 38, 'x' => 38,
'y' => 38, 'y' => 38,
}, },
'title' => { 'title' => {
'extends' => 'frame', 'extends' => 'frame',
'x' => 38, 'x' => 38,
'y' => 50, 'y' => 50,
'width' => 100, 'width' => 100,
}, },
'subtitle' => { 'subtitle' => {
'extends' => 'title', 'extends' => 'title',
'x' => 38, 'x' => 38,
'y' => 150, 'y' => 150,
'width' => 100, 'width' => 100,
}, },
} }

12
spec/input_helpers_spec.rb

@ -19,7 +19,7 @@ describe Squib::InputHelpers do
before(:each) do before(:each) do
@deck = DummyDeck.new @deck = DummyDeck.new
@deck.layout = { @deck.layout = {
'blah' => {x: 25}, 'blah' => {x: 25},
'apples' => {x: 35}, 'apples' => {x: 35},
'oranges' => {y: 45}, 'oranges' => {y: 45},
} }
@ -33,29 +33,29 @@ describe Squib::InputHelpers do
Squib.logger = instance_double(Logger) Squib.logger = instance_double(Logger)
expect(Squib.logger).to receive(:warn).with("Layout entry 'foo' does not exist.").twice expect(Squib.logger).to receive(:warn).with("Layout entry 'foo' does not exist.").twice
expect(Squib.logger).to receive(:debug) expect(Squib.logger).to receive(:debug)
expect(@deck.send(:layoutify, {layout: :foo})).to eq({layout: [:foo,:foo]}) expect(@deck.send(:layoutify, {layout: :foo})).to eq({layout: [:foo,:foo]})
Squib.logger = @old_logger Squib.logger = @old_logger
end end
it "applies the layout in a normal situation" do it "applies the layout in a normal situation" do
expect(@deck.send(:layoutify, {layout: :blah})).to \ expect(@deck.send(:layoutify, {layout: :blah})).to \
eq({layout: [:blah, :blah], x: [25, 25]}) eq({layout: [:blah, :blah], x: [25, 25]})
end end
it "applies two different layouts for two different situations" do it "applies two different layouts for two different situations" do
expect(@deck.send(:layoutify, {layout: ['blah', 'apples']})).to \ expect(@deck.send(:layoutify, {layout: ['blah', 'apples']})).to \
eq({layout: ['blah','apples'], x: [25, 35]}) eq({layout: ['blah','apples'], x: [25, 35]})
end end
it "still has nils when not applied two different layouts differ in structure" do it "still has nils when not applied two different layouts differ in structure" do
expect(@deck.send(:layoutify, {layout: ['apples', 'oranges']})).to \ expect(@deck.send(:layoutify, {layout: ['apples', 'oranges']})).to \
eq({layout: ['apples','oranges'], x: [35], y: [nil, 45]}) eq({layout: ['apples','oranges'], x: [35], y: [nil, 45]})
#...this might behavior that is hard to debug for users. Trying to come up with a warning or something... #...this might behavior that is hard to debug for users. Trying to come up with a warning or something...
end end
it "also looks up based on strings" do it "also looks up based on strings" do
expect(@deck.send(:layoutify, {layout: 'blah'})).to \ expect(@deck.send(:layoutify, {layout: 'blah'})).to \
eq({layout: ['blah','blah'], x: [25, 25]}) eq({layout: ['blah','blah'], x: [25, 25]})
end end
end end

4
spec/samples_run_spec.rb

@ -2,7 +2,7 @@ require 'spec_helper'
require 'squib' require 'squib'
require 'pp' require 'pp'
describe Squib do describe Squib do
context "all samples run without error" do context "all samples run without error" do
it "should execute with no errors" do it "should execute with no errors" do
@ -15,6 +15,6 @@ describe Squib do
end end
end end
end end
end end
end end
Loading…
Cancel
Save