Browse Source

👮 fix spacing inside hashes

dev
Andy Meneely 10 years ago
parent
commit
5e09e0f1e1
  1. 8
      lib/squib/api/save.rb
  2. 2
      lib/squib/api/shapes.rb
  3. 4
      lib/squib/api/text.rb
  4. 4
      lib/squib/api/text_embed.rb
  5. 4
      lib/squib/graphics/text.rb
  6. 4
      samples/basic.rb
  7. 4
      samples/ranges.rb
  8. 4
      samples/text_options.rb
  9. 14
      spec/args/box_spec.rb
  10. 28
      spec/args/draw_spec.rb
  11. 4
      spec/args/input_file_spec.rb
  12. 6
      spec/args/paint_spec.rb
  13. 42
      spec/args/paragraph_spec.rb
  14. 20
      spec/args/save_batch_spec.rb
  15. 18
      spec/args/scale_box_spec.rb
  16. 8
      spec/args/sheet_spec.rb
  17. 6
      spec/args/transform_spec.rb
  18. 12
      spec/layout_parser_spec.rb

8
lib/squib/api/save.rb

@ -17,7 +17,7 @@ module Squib
# DSL method. See http://squib.readthedocs.org # DSL method. See http://squib.readthedocs.org
def save_pdf(opts = {}) def save_pdf(opts = {})
range = Args::CardRange.new(opts[:range], deck_size: size) range = Args::CardRange.new(opts[:range], deck_size: size)
sheet = Args::Sheet.new(custom_colors, {file: 'output.pdf'}).load!(opts, expand_by: size, layout: layout, dpi: dpi) sheet = Args::Sheet.new(custom_colors, { file: 'output.pdf' }).load!(opts, expand_by: size, layout: layout, dpi: dpi)
render_pdf(range, sheet) render_pdf(range, sheet)
end end
@ -37,7 +37,7 @@ module Squib
def save_sheet(opts = {}) def save_sheet(opts = {})
range = Args::CardRange.new(opts[:range], deck_size: size) range = Args::CardRange.new(opts[:range], deck_size: size)
batch = Args::SaveBatch.new.load!(opts, expand_by: size, layout: layout, dpi: dpi) batch = Args::SaveBatch.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
sheet = Args::Sheet.new(custom_colors, {margin: 0}, size).load!(opts, expand_by: size, layout: layout, dpi: dpi) sheet = Args::Sheet.new(custom_colors, { margin: 0 }, size).load!(opts, expand_by: size, layout: layout, dpi: dpi)
render_sheet(range, batch, sheet) render_sheet(range, batch, sheet)
end end
@ -45,7 +45,7 @@ module Squib
def showcase(opts = {}) def showcase(opts = {})
range = Args::CardRange.new(opts[:range], deck_size: size) range = Args::CardRange.new(opts[:range], deck_size: size)
showcase = Args::ShowcaseSpecial.new.load!(opts, expand_by: size, layout: layout, dpi: dpi) showcase = Args::ShowcaseSpecial.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
sheet = Args::Sheet.new(custom_colors, {file: 'showcase.png'}).load!(opts, expand_by: size, layout: layout, dpi: dpi) sheet = Args::Sheet.new(custom_colors, { file: 'showcase.png' }).load!(opts, expand_by: size, layout: layout, dpi: dpi)
render_showcase(range, sheet, showcase) render_showcase(range, sheet, showcase)
end end
@ -53,7 +53,7 @@ module Squib
def hand(opts = {}) def hand(opts = {})
range = Args::CardRange.new(opts[:range], deck_size: size) range = Args::CardRange.new(opts[:range], deck_size: size)
hand = Args::HandSpecial.new(height).load!(opts, expand_by: size, layout: layout, dpi: dpi) hand = Args::HandSpecial.new(height).load!(opts, expand_by: size, layout: layout, dpi: dpi)
sheet = Args::Sheet.new(custom_colors, {file: 'hand.png', trim_radius: 0}).load!(opts, expand_by: size, layout: layout, dpi: dpi) sheet = Args::Sheet.new(custom_colors, { file: 'hand.png', trim_radius: 0 }).load!(opts, expand_by: size, layout: layout, dpi: dpi)
render_hand(range, sheet, hand) render_hand(range, sheet, hand)
end end

2
lib/squib/api/shapes.rb

@ -27,7 +27,7 @@ module Squib
def ellipse(opts = {}) def ellipse(opts = {})
range = Args::CardRange.new(opts[:range], deck_size: size) range = Args::CardRange.new(opts[:range], deck_size: size)
draw = Args::Draw.new(custom_colors).load!(opts, expand_by: size, layout: layout, dpi: dpi) draw = Args::Draw.new(custom_colors).load!(opts, expand_by: size, layout: layout, dpi: dpi)
box = Args::Box.new(self, {width: '0.25in', height: '0.25in'}).load!(opts, expand_by: size, layout: layout, dpi: dpi) box = Args::Box.new(self, { width: '0.25in', height: '0.25in' }).load!(opts, expand_by: size, layout: layout, dpi: dpi)
range.each { |i| @cards[i].ellipse(box[i], draw[i]) } range.each { |i| @cards[i].ellipse(box[i], draw[i]) }
end end

4
lib/squib/api/text.rb

@ -11,9 +11,9 @@ module Squib
def text(opts = {}) def text(opts = {})
range = Args::CardRange.new(opts[:range], deck_size: size) range = Args::CardRange.new(opts[:range], deck_size: size)
para = Args::Paragraph.new(font).load!(opts, expand_by: size, layout: layout) para = Args::Paragraph.new(font).load!(opts, expand_by: size, layout: layout)
box = Args::Box.new(self, {width: :auto, height: :auto}).load!(opts, expand_by: size, layout: layout, dpi: dpi) box = Args::Box.new(self, { width: :auto, height: :auto }).load!(opts, expand_by: size, layout: layout, dpi: dpi)
trans = Args::Transform.new.load!(opts, expand_by: size, layout: layout, dpi: dpi) trans = Args::Transform.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
draw = Args::Draw.new(custom_colors, {stroke_width: 0.0}).load!(opts, expand_by: size, layout: layout, dpi: dpi) draw = Args::Draw.new(custom_colors, { stroke_width: 0.0 }).load!(opts, expand_by: size, layout: layout, dpi: dpi)
embed = TextEmbed.new(size, custom_colors, layout, dpi, img_dir) embed = TextEmbed.new(size, custom_colors, layout, dpi, img_dir)
yield(embed) if block_given? #store the opts for later use yield(embed) if block_given? #store the opts for later use
extents = Array.new(@cards.size) extents = Array.new(@cards.size)

4
lib/squib/api/text_embed.rb

@ -42,7 +42,7 @@ module Squib
key = Args::EmbedKey.new.validate_key(opts[:key]) key = Args::EmbedKey.new.validate_key(opts[:key])
range = Args::CardRange.new(opts[:range], deck_size: @deck_size) range = Args::CardRange.new(opts[:range], deck_size: @deck_size)
paint = Args::Paint.new(@custom_colors).load!(opts, expand_by: @deck_size, layout: @layout) paint = Args::Paint.new(@custom_colors).load!(opts, expand_by: @deck_size, layout: @layout)
box = Args::Box.new(self, {width: :native, height: :native}).load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi) box = Args::Box.new(self, { width: :native, height: :native }).load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
adjust= Args::EmbedAdjust.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi) adjust= Args::EmbedAdjust.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
trans = Args::Transform.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi) trans = Args::Transform.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
ifile = Args::InputFile.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi) ifile = Args::InputFile.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
@ -76,7 +76,7 @@ module Squib
key = Args::EmbedKey.new.validate_key(opts[:key]) key = Args::EmbedKey.new.validate_key(opts[:key])
range = Args::CardRange.new(opts[:range], deck_size: @deck_size) range = Args::CardRange.new(opts[:range], deck_size: @deck_size)
paint = Args::Paint.new(@custom_colors).load!(opts, expand_by: @deck_size, layout: @layout) paint = Args::Paint.new(@custom_colors).load!(opts, expand_by: @deck_size, layout: @layout)
box = Args::Box.new(self, {width: :native, height: :native}).load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi) box = Args::Box.new(self, { width: :native, height: :native }).load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
adjust= Args::EmbedAdjust.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi) adjust= Args::EmbedAdjust.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
trans = Args::Transform.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi) trans = Args::Transform.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)
ifile = Args::InputFile.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi) ifile = Args::InputFile.new.load!(opts, expand_by: @deck_size, layout: @layout, dpi: @dpi)

4
lib/squib/graphics/text.rb

@ -105,8 +105,8 @@ module Squib
x = Pango.pixels(rect.x) + search[:rule][:adjust].dx[@index] x = Pango.pixels(rect.x) + search[:rule][:adjust].dx[@index]
y = Pango.pixels(rect.y) + search[:rule][:adjust].dy[@index] y = Pango.pixels(rect.y) + search[:rule][:adjust].dy[@index]
h = rule[:box].height[@index] h = rule[:box].height[@index]
draw_calls << {x: x, y: y, h: h, # defer drawing until we've valigned draw_calls << { x: x, y: y, h: h, # defer drawing until we've valigned
draw: search[:rule][:draw]} draw: search[:rule][:draw] }
end end
return draw_calls return draw_calls
end end

4
samples/basic.rb

@ -1,7 +1,7 @@
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
background color: :white background color: :white

4
samples/ranges.rb

@ -1,8 +1,8 @@
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] }
Squib::Deck.new(width: 825, height: 1125, cards: 3) do Squib::Deck.new(width: 825, height: 1125, cards: 3) do
# Default range is :all # Default range is :all

4
samples/text_options.rb

@ -1,8 +1,8 @@
# encoding: UTF-8 # encoding: UTF-8
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, with newlines.\nWhat do you know about tweetle beetles? well... When 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." longtext = "This is left-justified text, with newlines.\nWhat do you know about tweetle beetles? well... When 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."
Squib::Deck.new(width: 825, height: 1125, cards: 3) do Squib::Deck.new(width: 825, height: 1125, cards: 3) do

14
spec/args/box_spec.rb

@ -3,7 +3,7 @@ require 'squib/args/box'
describe Squib::Args::Box do describe Squib::Args::Box do
subject(:box) { Squib::Args::Box.new } subject(:box) { Squib::Args::Box.new }
let(:expected_defaults) { {x: [0], y: [0], width: [:deck], height: [:deck] } } let(:expected_defaults) { { x: [0], y: [0], width: [:deck], height: [:deck] } }
it 'intitially has no params set' do it 'intitially has no params set' do
expect(box).not_to respond_to(:x, :y, :width, :height) expect(box).not_to respond_to(:x, :y, :width, :height)
@ -20,13 +20,13 @@ describe Squib::Args::Box do
end end
it 'extracts the defaults from Box on an empty hash' do it 'extracts the defaults from Box on an empty hash' do
box.load!({foo: :bar}) box.load!({ foo: :bar })
expect(box).to have_attributes(expected_defaults) expect(box).to have_attributes(expected_defaults)
expect(box).not_to respond_to(:foo) expect(box).not_to respond_to(:foo)
end end
context 'single expansion' do context 'single expansion' do
let(:args) { {x: [1, 2], y: 3} } let(:args) { { x: [1, 2], y: 3 } }
before(:each) { box.load!(args, expand_by: 2) } before(:each) { box.load!(args, expand_by: 2) }
it 'expands box' do it 'expands box' do
expect(box).to have_attributes({ expect(box).to have_attributes({
@ -81,7 +81,7 @@ describe Squib::Args::Box do
end end
it 'warns on non-existent layouts' do it 'warns on non-existent layouts' do
args = { layout: :heal} args = { layout: :heal }
expect(Squib.logger).to receive(:warn).with('Layout "heal" does not exist in layout file - using default instead').at_least(:once) expect(Squib.logger).to receive(:warn).with('Layout "heal" does not exist in layout file - using default instead').at_least(:once)
box.load!(args, expand_by: 2, layout: layout) box.load!(args, expand_by: 2, layout: layout)
expect(box).to have_attributes( expect(box).to have_attributes(
@ -94,7 +94,7 @@ describe Squib::Args::Box do
context 'unit conversion' do context 'unit conversion' do
it 'converts units on all args' do it 'converts units on all args' do
args = {x: ['1in', '2in'], y: 300, width: '1in', height: '1in'} args = { x: ['1in', '2in'], y: 300, width: '1in', height: '1in' }
box.load!(args, expand_by: 2) box.load!(args, expand_by: 2)
expect(box).to have_attributes( expect(box).to have_attributes(
x: [300, 600], x: [300, 600],
@ -108,7 +108,7 @@ describe Squib::Args::Box do
context 'validation' do context 'validation' do
it 'replaces with deck width and height' do it 'replaces with deck width and height' do
args = {width: :deck, height: :deck} args = { width: :deck, height: :deck }
deck = OpenStruct.new(width: 123, height: 456) deck = OpenStruct.new(width: 123, height: 456)
box = Squib::Args::Box.new(deck) box = Squib::Args::Box.new(deck)
box.load!(args, expand_by: 1) box.load!(args, expand_by: 1)
@ -116,7 +116,7 @@ describe Squib::Args::Box do
end end
it 'has radius override x_radius and y_radius' do it 'has radius override x_radius and y_radius' do
args = {x_radius: 1, y_radius: 2, radius: 3} args = { x_radius: 1, y_radius: 2, radius: 3 }
box.load!(args, expand_by: 2) box.load!(args, expand_by: 2)
expect(box).to have_attributes(x_radius: [3, 3], y_radius: [3, 3]) expect(box).to have_attributes(x_radius: [3, 3], y_radius: [3, 3])
end end

28
spec/args/draw_spec.rb

@ -2,13 +2,13 @@ require 'spec_helper'
require 'squib/args/draw' require 'squib/args/draw'
describe Squib::Args::Draw do describe Squib::Args::Draw do
let(:custom_colors) { {'foo' => 'abc'} } let(:custom_colors) { { 'foo' => 'abc' } }
subject(:draw) {Squib::Args::Draw.new(custom_colors)} subject(:draw) {Squib::Args::Draw.new(custom_colors)}
context 'unit conversion' do context 'unit conversion' do
it 'converts units on stroke width' do it 'converts units on stroke width' do
args = {stroke_width: '2in'} args = { stroke_width: '2in' }
draw.load!(args, expand_by: 2) draw.load!(args, expand_by: 2)
expect(draw).to have_attributes(stroke_width: [600, 600]) expect(draw).to have_attributes(stroke_width: [600, 600])
end end
@ -16,7 +16,7 @@ describe Squib::Args::Draw do
end end
context 'dsl overrides' do context 'dsl overrides' do
subject(:draw) {Squib::Args::Draw.new(custom_colors, {stroke_width: 0.0})} subject(:draw) {Squib::Args::Draw.new(custom_colors, { stroke_width: 0.0 })}
it 'works when specified' do it 'works when specified' do
draw.load!({}) # go right to defaults draw.load!({}) # go right to defaults
@ -28,7 +28,7 @@ describe Squib::Args::Draw do
context 'validation' do context 'validation' do
it 'converts to Cairo options' do it 'converts to Cairo options' do
args = {join: 'bevel', cap: 'round'} args = { join: 'bevel', cap: 'round' }
draw.load!(args) draw.load!(args)
expect(draw).to have_attributes( expect(draw).to have_attributes(
join: [Cairo::LINE_JOIN_BEVEL], join: [Cairo::LINE_JOIN_BEVEL],
@ -37,62 +37,62 @@ describe Squib::Args::Draw do
end end
it 'parses dash options' do it 'parses dash options' do
args = {dash: '3 4 5'} args = { dash: '3 4 5' }
draw.load!(args) draw.load!(args)
expect(draw).to have_attributes(dash: [[3, 4, 5]]) expect(draw).to have_attributes(dash: [[3, 4, 5]])
end end
it 'parses more complex dash options' do it 'parses more complex dash options' do
args = {dash: '30.5, 90, 5'} args = { dash: '30.5, 90, 5' }
draw.load!(args) draw.load!(args)
expect(draw).to have_attributes(dash: [[30.5, 90, 5]]) expect(draw).to have_attributes(dash: [[30.5, 90, 5]])
end end
it 'does unit conversion on dash options' do it 'does unit conversion on dash options' do
args = {dash: '3in 4in 5in'} args = { dash: '3in 4in 5in' }
draw.load!(args) draw.load!(args)
expect(draw).to have_attributes(dash: [[900, 1200, 1500]]) expect(draw).to have_attributes(dash: [[900, 1200, 1500]])
end end
it 'converts line caps to Cairo constants' do it 'converts line caps to Cairo constants' do
args = {cap: :SQUARE} args = { cap: :SQUARE }
draw.load! args draw.load! args
expect(draw).to have_attributes( cap: [Cairo::LINE_CAP_SQUARE] ) expect(draw).to have_attributes( cap: [Cairo::LINE_CAP_SQUARE] )
end end
it 'converts line join' do it 'converts line join' do
args = {join: 'round'} args = { join: 'round' }
draw.load! args draw.load! args
expect(draw).to have_attributes( join: [Cairo::LINE_JOIN_ROUND] ) expect(draw).to have_attributes( join: [Cairo::LINE_JOIN_ROUND] )
end end
it 'allows fill_first stroke_strategy' do it 'allows fill_first stroke_strategy' do
args = {stroke_strategy: :FILL_first} args = { stroke_strategy: :FILL_first }
draw.load! args draw.load! args
expect(draw).to have_attributes( stroke_strategy: [:fill_first] ) expect(draw).to have_attributes( stroke_strategy: [:fill_first] )
end end
it 'allows stroke_first stroke_strategy' do it 'allows stroke_first stroke_strategy' do
args = {stroke_strategy: ' stroke_FIRST '} args = { stroke_strategy: ' stroke_FIRST ' }
draw.load! args draw.load! args
expect(draw).to have_attributes( stroke_strategy: [:stroke_first] ) expect(draw).to have_attributes( stroke_strategy: [:stroke_first] )
end end
it 'disallows anything not stroke_first and fill_first' do it 'disallows anything not stroke_first and fill_first' do
args = {stroke_strategy: 'foo'} args = { stroke_strategy: 'foo' }
expect { draw.load! args }.to raise_error("Only 'stroke_first' or 'fill_first' allowed") expect { draw.load! args }.to raise_error("Only 'stroke_first' or 'fill_first' allowed")
end end
context 'custom colors' do context 'custom colors' do
it 'looks up custom colors in the config' do it 'looks up custom colors in the config' do
draw.load!({color: 'foo'}) draw.load!({ color: 'foo' })
expect(draw.color).to eq ['abc'] expect(draw.color).to eq ['abc']
end end
it 'passes on through for non-custom color' do it 'passes on through for non-custom color' do
draw = Squib::Args::Draw.new(custom_colors) draw = Squib::Args::Draw.new(custom_colors)
draw.load!({color: 'bar'}) draw.load!({ color: 'bar' })
expect(draw.color).to eq ['bar'] expect(draw.color).to eq ['bar']
end end

4
spec/args/input_file_spec.rb

@ -7,13 +7,13 @@ describe Squib::Args::InputFile do
context 'validate_file' do context 'validate_file' do
it 'allows a file if it exists' do it 'allows a file if it exists' do
args = {file: __FILE__} # I code therefore I am. args = { file: __FILE__ } # I code therefore I am.
ifile.load!(args, expand_by: 1) ifile.load!(args, expand_by: 1)
expect(ifile).to have_attributes(file: [File.expand_path(__FILE__)]) expect(ifile).to have_attributes(file: [File.expand_path(__FILE__)])
end end
it 'raises on non-existent file' do it 'raises on non-existent file' do
args = {file: 'foo.rb'} args = { file: 'foo.rb' }
expect { ifile.load!(args, expand_by: 1) }.to raise_error("File #{File.expand_path('foo.rb')} does not exist!") expect { ifile.load!(args, expand_by: 1) }.to raise_error("File #{File.expand_path('foo.rb')} does not exist!")
end end

6
spec/args/paint_spec.rb

@ -2,19 +2,19 @@ require 'spec_helper'
require 'squib/args/paint' require 'squib/args/paint'
describe Squib::Args::Draw do describe Squib::Args::Draw do
let(:custom_colors) { {'foo' => 'abc'} } let(:custom_colors) { { 'foo' => 'abc' } }
subject(:paint) {Squib::Args::Paint.new(custom_colors)} subject(:paint) {Squib::Args::Paint.new(custom_colors)}
context 'alpha' do context 'alpha' do
it 'can be a float' do it 'can be a float' do
args = {alpha: 0.6} args = { alpha: 0.6 }
paint.load!(args) paint.load!(args)
expect(paint.alpha).to eq [0.6] expect(paint.alpha).to eq [0.6]
end end
it 'raises exception when not a float' do it 'raises exception when not a float' do
args = {alpha: /6/} args = { alpha: /6/ }
expect { paint.load!(args) }.to raise_error('alpha must respond to to_f') expect { paint.load!(args) }.to raise_error('alpha must respond to to_f')
end end

42
spec/args/paragraph_spec.rb

@ -7,7 +7,7 @@ describe Squib::Args::Paragraph do
context 'str validator' do context 'str validator' do
it 'converts everything to string' do it 'converts everything to string' do
para.load!( {str: 5} ) para.load!( { str: 5 } )
expect(para.str).to eq ['5'] expect(para.str).to eq ['5']
end end
end end
@ -25,7 +25,7 @@ describe Squib::Args::Paragraph do
end end
it 'uses specified font when given' do it 'uses specified font when given' do
para.load!( {font: 'MyFont 8'}) para.load!( { font: 'MyFont 8' })
expect(para.font).to eq ['MyFont 8'] expect(para.font).to eq ['MyFont 8']
end end
end end
@ -53,100 +53,100 @@ describe Squib::Args::Paragraph do
context 'wrap validator' do context 'wrap validator' do
it 'converts to pango wrap word' do it 'converts to pango wrap word' do
para.load!( { wrap: 'word'} ) para.load!( { wrap: 'word' } )
expect(para.wrap).to eq [Pango::WRAP_WORD] expect(para.wrap).to eq [Pango::WRAP_WORD]
end end
it 'converts to pango wrap char' do it 'converts to pango wrap char' do
para.load!( { wrap: 'WORD_ChAr'} ) para.load!( { wrap: 'WORD_ChAr' } )
expect(para.wrap).to eq [Pango::WRAP_WORD_CHAR] expect(para.wrap).to eq [Pango::WRAP_WORD_CHAR]
end end
it 'converts to pango wrap char on true' do it 'converts to pango wrap char on true' do
para.load!( { wrap: true} ) para.load!( { wrap: true } )
expect(para.wrap).to eq [Pango::WRAP_WORD_CHAR] expect(para.wrap).to eq [Pango::WRAP_WORD_CHAR]
end end
it 'converts to pango wrap char with false' do it 'converts to pango wrap char with false' do
para.load!( { wrap: false} ) para.load!( { wrap: false } )
expect(para.wrap).to eq [Pango::WRAP_CHAR] expect(para.wrap).to eq [Pango::WRAP_CHAR]
end end
it 'raises an exception on anything else' do it 'raises an exception on anything else' do
expect { para.load!( {wrap: 'foo' }) }.to raise_error(ArgumentError, 'wrap must be one of: word, char, word_char, true, or false') expect { para.load!( { wrap: 'foo' }) }.to raise_error(ArgumentError, 'wrap must be one of: word, char, word_char, true, or false')
end end
end end
context 'ellipsize validator' do context 'ellipsize validator' do
it 'converts to pango on none and false' do it 'converts to pango on none and false' do
para.load!( { ellipsize: 'none'} ) para.load!( { ellipsize: 'none' } )
expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_NONE] expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_NONE]
end end
it 'converts to pango with start' do it 'converts to pango with start' do
para.load!( { ellipsize: :StArt} ) para.load!( { ellipsize: :StArt } )
expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_START] expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_START]
end end
it 'converts to pango middle' do it 'converts to pango middle' do
para.load!( { ellipsize: 'middle'} ) para.load!( { ellipsize: 'middle' } )
expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_MIDDLE] expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_MIDDLE]
end end
it 'converts to pango end' do it 'converts to pango end' do
para.load!( { ellipsize: 'END'} ) para.load!( { ellipsize: 'END' } )
expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_END] expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_END]
end end
it 'raises an exception on anything else' do it 'raises an exception on anything else' do
expect { para.load!( {ellipsize: 'foo' }) }.to raise_error(ArgumentError, 'ellipsize must be one of: none, start, middle, end, true, or false') expect { para.load!( { ellipsize: 'foo' }) }.to raise_error(ArgumentError, 'ellipsize must be one of: none, start, middle, end, true, or false')
end end
end end
context 'justify validator' do context 'justify validator' do
it 'allows nil' do it 'allows nil' do
para.load!( { justify: nil} ) para.load!( { justify: nil } )
expect(para.justify).to eq [nil] expect(para.justify).to eq [nil]
end end
it 'can be true' do it 'can be true' do
para.load!( { justify: true} ) para.load!( { justify: true } )
expect(para.justify).to eq [true] expect(para.justify).to eq [true]
end end
it 'can be false' do it 'can be false' do
para.load!( { justify: false} ) para.load!( { justify: false } )
expect(para.justify).to eq [false] expect(para.justify).to eq [false]
end end
it 'raises an exception on anything else' do it 'raises an exception on anything else' do
expect { para.load!( {justify: 'false' }) }.to raise_error(ArgumentError, 'justify must be one of: nil, true, or false') expect { para.load!( { justify: 'false' }) }.to raise_error(ArgumentError, 'justify must be one of: nil, true, or false')
end end
end end
context 'spacing validator' do context 'spacing validator' do
it 'allows nil' do it 'allows nil' do
para.load!( { spacing: nil} ) para.load!( { spacing: nil } )
expect(para.spacing).to eq [nil] expect(para.spacing).to eq [nil]
end end
it 'is converted to Pango space' do it 'is converted to Pango space' do
para.load!( { spacing: 519} ) para.load!( { spacing: 519 } )
expect(para.spacing).to eq [Pango::SCALE * 519.0] expect(para.spacing).to eq [Pango::SCALE * 519.0]
end end
it 'raises an exception if not a float' do it 'raises an exception if not a float' do
expect { para.load!( {spacing: /foo/ }) }.to raise_error(ArgumentError, 'spacing must be a number or nil') expect { para.load!( { spacing: /foo/ }) }.to raise_error(ArgumentError, 'spacing must be a number or nil')
end end
end end
context 'valign validator' do context 'valign validator' do
it 'converts top' do it 'converts top' do
para.load!( { valign: :top} ) para.load!( { valign: :top } )
expect(para.valign).to eq ['top'] expect(para.valign).to eq ['top']
end end
it 'raises an exception if not one of the three' do it 'raises an exception if not one of the three' do
expect { para.load!( {valign: 'foo' }) }.to raise_error(ArgumentError, 'valign must be one of: top, middle, bottom') expect { para.load!( { valign: 'foo' }) }.to raise_error(ArgumentError, 'valign must be one of: top, middle, bottom')
end end
end end

20
spec/args/save_batch_spec.rb

@ -6,12 +6,12 @@ describe Squib::Args::SaveBatch do
context 'dir' do context 'dir' do
it 'is created if not exists (and warns)' do it 'is created if not exists (and warns)' do
opts = {dir: 'tocreate'} opts = { dir: 'tocreate' }
Dir.chdir(output_dir) do Dir.chdir(output_dir) do
FileUtils.rm_rf('tocreate', secure: true) FileUtils.rm_rf('tocreate', secure: true)
expect(Squib.logger).to receive(:warn).with("Dir 'tocreate' does not exist, creating it.").once expect(Squib.logger).to receive(:warn).with("Dir 'tocreate' does not exist, creating it.").once
save_batch.load! opts save_batch.load! opts
expect(save_batch).to have_attributes({dir: ['tocreate']}) expect(save_batch).to have_attributes({ dir: ['tocreate'] })
expect(Dir.exists? 'tocreate').to be true expect(Dir.exists? 'tocreate').to be true
end end
end end
@ -21,29 +21,29 @@ describe Squib::Args::SaveBatch do
it 'does nothing by default' do it 'does nothing by default' do
opts = {} opts = {}
save_batch.load! opts save_batch.load! opts
expect(save_batch[0]).to have_attributes({rotate: false, angle: 0}) expect(save_batch[0]).to have_attributes({ rotate: false, angle: 0 })
end end
it 'rotates by pi/2 with true' do it 'rotates by pi/2 with true' do
opts = {rotate: true} opts = { rotate: true }
save_batch.load! opts save_batch.load! opts
expect(save_batch[0]).to have_attributes({rotate: true, angle: Math::PI / 2}) expect(save_batch[0]).to have_attributes({ rotate: true, angle: Math::PI / 2 })
end end
it 'rotates by pi/2' do it 'rotates by pi/2' do
opts = {rotate: :clockwise} opts = { rotate: :clockwise }
save_batch.load! opts save_batch.load! opts
expect(save_batch[0]).to have_attributes({rotate: true, angle: Math::PI / 2}) expect(save_batch[0]).to have_attributes({ rotate: true, angle: Math::PI / 2 })
end end
it 'rotates by pi/2 with counterclockwise' do it 'rotates by pi/2 with counterclockwise' do
opts = {rotate: :counterclockwise} opts = { rotate: :counterclockwise }
save_batch.load! opts save_batch.load! opts
expect(save_batch[0]).to have_attributes({rotate: true, angle: 3 * Math::PI / 2}) expect(save_batch[0]).to have_attributes({ rotate: true, angle: 3 * Math::PI / 2 })
end end
it 'raises error on a number' do it 'raises error on a number' do
opts = {rotate: 5.0} opts = { rotate: 5.0 }
expect { save_batch.load!(opts) }.to raise_error('invalid option to rotate: only [true, false, :clockwise, :counterclockwise]') expect { save_batch.load!(opts) }.to raise_error('invalid option to rotate: only [true, false, :clockwise, :counterclockwise]')
end end
end end

18
spec/args/scale_box_spec.rb

@ -6,7 +6,7 @@ describe Squib::Args::ScaleBox do
context 'unit conversion' do context 'unit conversion' do
it 'converts units on all args' do it 'converts units on all args' do
args = {x: ['1in', '2in'], y: 300, width: '1in', height: '1in'} args = { x: ['1in', '2in'], y: 300, width: '1in', height: '1in' }
box.load!(args, expand_by: 2) box.load!(args, expand_by: 2)
expect(box).to have_attributes( expect(box).to have_attributes(
x: [300, 600], x: [300, 600],
@ -19,7 +19,7 @@ describe Squib::Args::ScaleBox do
context 'validation' do context 'validation' do
it 'replaces with deck width and height' do it 'replaces with deck width and height' do
args = {width: :deck, height: :deck} args = { width: :deck, height: :deck }
deck = OpenStruct.new(width: 123, height: 456) deck = OpenStruct.new(width: 123, height: 456)
box = Squib::Args::Box.new(deck) box = Squib::Args::Box.new(deck)
box.load!(args, expand_by: 1) box.load!(args, expand_by: 1)
@ -27,41 +27,41 @@ describe Squib::Args::ScaleBox do
end end
it 'allows :native' do it 'allows :native' do
args = {width: :native, height: :native} args = { width: :native, height: :native }
box.load!(args, expand_by: 1) box.load!(args, expand_by: 1)
expect(box).to have_attributes(width: [:native], height: [:native]) expect(box).to have_attributes(width: [:native], height: [:native])
end end
it 'allows native to be a string' do it 'allows native to be a string' do
args = {width: 'native'} args = { width: 'native' }
box.load!(args, expand_by: 1) box.load!(args, expand_by: 1)
expect(box).to have_attributes(width: [:native], height: [:native]) expect(box).to have_attributes(width: [:native], height: [:native])
end end
it 'allows :scale on width if height has to_f' do it 'allows :scale on width if height has to_f' do
args = {width: :scale, height: 75} args = { width: :scale, height: 75 }
box.load!(args, expand_by: 1) box.load!(args, expand_by: 1)
expect(box).to have_attributes(width: [:scale], height: [75]) expect(box).to have_attributes(width: [:scale], height: [75])
end end
it 'allows :scale on width if height has to_f' do it 'allows :scale on width if height has to_f' do
args = {width: 75, height: :scale} args = { width: 75, height: :scale }
box.load!(args, expand_by: 1) box.load!(args, expand_by: 1)
expect(box).to have_attributes(width: [75], height: [:scale]) expect(box).to have_attributes(width: [75], height: [:scale])
end end
it 'disallows both :scale' do it 'disallows both :scale' do
args = {width: :scale, height: :scale} args = { width: :scale, height: :scale }
expect { box.load!(args, expand_by: 1) }.to raise_error('if width is :scale, height must be a number') expect { box.load!(args, expand_by: 1) }.to raise_error('if width is :scale, height must be a number')
end end
it 'disallows non-to_f on width' do it 'disallows non-to_f on width' do
args = {width: :foo} args = { width: :foo }
expect { box.load!(args, expand_by: 1) }.to raise_error('width must be a number, :scale, :native, or :deck') expect { box.load!(args, expand_by: 1) }.to raise_error('width must be a number, :scale, :native, or :deck')
end end
it 'disallows non-to_f on height' do it 'disallows non-to_f on height' do
args = {height: :foo} args = { height: :foo }
expect { box.load!(args, expand_by: 1) }.to raise_error('height must be a number, :scale, :native, or :deck') expect { box.load!(args, expand_by: 1) }.to raise_error('height must be a number, :scale, :native, or :deck')
end end

8
spec/args/sheet_spec.rb

@ -4,7 +4,7 @@ require 'squib/args/sheet'
describe Squib::Args::Sheet do describe Squib::Args::Sheet do
context 'dsl overrides' do context 'dsl overrides' do
subject(:sheet) { Squib::Args::Sheet.new({}, {file: 'foo'}) } subject(:sheet) { Squib::Args::Sheet.new({}, { file: 'foo' }) }
it 'works when specified' do it 'works when specified' do
sheet.load!({}) # go right to defaults sheet.load!({}) # go right to defaults
@ -29,13 +29,13 @@ describe Squib::Args::Sheet do
end end
it 'computes properly on non-integer' do it 'computes properly on non-integer' do
opts = {columns: 1, rows: :infinite} opts = { columns: 1, rows: :infinite }
sheet.load! opts sheet.load! opts
expect(sheet).to have_attributes( columns: 1, rows: 4 ) expect(sheet).to have_attributes( columns: 1, rows: 4 )
end end
it 'computes properly on unspecified rows' do it 'computes properly on unspecified rows' do
opts = {columns: 1} opts = { columns: 1 }
sheet.load! opts sheet.load! opts
expect(sheet).to have_attributes( columns: 1, rows: 4 ) expect(sheet).to have_attributes( columns: 1, rows: 4 )
end end
@ -47,7 +47,7 @@ describe Squib::Args::Sheet do
end end
it 'fails on a non-integer column' do it 'fails on a non-integer column' do
opts = {columns: :infinite} opts = { columns: :infinite }
expect { sheet.load!(opts) }.to raise_error('columns must be an integer') expect { sheet.load!(opts) }.to raise_error('columns must be an integer')
end end

6
spec/args/transform_spec.rb

@ -3,11 +3,11 @@ require 'squib/args/transform'
describe Squib::Args::Box do describe Squib::Args::Box do
subject(:trans) { Squib::Args::Transform.new } subject(:trans) { Squib::Args::Transform.new }
let(:expected_defaults) { {x: [0], y: [0], crop_width: [:native], crop_height: [:native] } } let(:expected_defaults) { { x: [0], y: [0], crop_width: [:native], crop_height: [:native] } }
context 'validation' do context 'validation' do
it 'replaces with deck width and height' do it 'replaces with deck width and height' do
args = {crop_width: :deck, crop_height: :deck} args = { crop_width: :deck, crop_height: :deck }
deck = OpenStruct.new(width: 123, height: 456) deck = OpenStruct.new(width: 123, height: 456)
trans = Squib::Args::Transform.new(deck) trans = Squib::Args::Transform.new(deck)
trans.load!(args, expand_by: 1) trans.load!(args, expand_by: 1)
@ -15,7 +15,7 @@ describe Squib::Args::Box do
end end
it 'has radius override x_radius and y_radius' do it 'has radius override x_radius and y_radius' do
args = {crop_corner_x_radius: 1, crop_corner_y_radius: 2, crop_corner_radius: 3} args = { crop_corner_x_radius: 1, crop_corner_y_radius: 2, crop_corner_radius: 3 }
trans.load!(args, expand_by: 2) trans.load!(args, expand_by: 2)
expect(trans).to have_attributes(crop_corner_x_radius: [3, 3], crop_corner_y_radius: [3, 3]) expect(trans).to have_attributes(crop_corner_x_radius: [3, 3], crop_corner_y_radius: [3, 3])
end end

12
spec/layout_parser_spec.rb

@ -4,7 +4,7 @@ describe Squib::LayoutParser do
it 'loads a normal layout with no extends' do it 'loads a normal layout with no extends' do
layout = Squib::LayoutParser.load_layout(layout_file('no-extends.yml')) layout = Squib::LayoutParser.load_layout(layout_file('no-extends.yml'))
expect(layout).to eq({'frame' => { expect(layout).to eq({ 'frame' => {
'x' => 38, 'x' => 38,
'valign' => :middle, 'valign' => :middle,
'str' => 'blah', 'str' => 'blah',
@ -16,7 +16,7 @@ describe Squib::LayoutParser do
it 'loads with a single extends' do it 'loads with a single extends' do
layout = Squib::LayoutParser.load_layout(layout_file('single-extends.yml')) layout = Squib::LayoutParser.load_layout(layout_file('single-extends.yml'))
expect(layout).to eq({'frame' => { expect(layout).to eq({ 'frame' => {
'x' => 38, 'x' => 38,
'y' => 38, 'y' => 38,
}, },
@ -32,7 +32,7 @@ describe Squib::LayoutParser do
it 'applies the extends regardless of order' do it 'applies the extends regardless of order' do
layout = Squib::LayoutParser.load_layout(layout_file('pre-extends.yml')) layout = Squib::LayoutParser.load_layout(layout_file('pre-extends.yml'))
expect(layout).to eq({'frame' => { expect(layout).to eq({ 'frame' => {
'x' => 38, 'x' => 38,
'y' => 38, 'y' => 38,
}, },
@ -48,7 +48,7 @@ describe Squib::LayoutParser do
it 'applies the single-level extends multiple times' do it 'applies the single-level extends multiple times' do
layout = Squib::LayoutParser.load_layout(layout_file('single-level-multi-extends.yml')) layout = Squib::LayoutParser.load_layout(layout_file('single-level-multi-extends.yml'))
expect(layout).to eq({'frame' => { expect(layout).to eq({ 'frame' => {
'x' => 38, 'x' => 38,
'y' => 38, 'y' => 38,
}, },
@ -70,7 +70,7 @@ describe Squib::LayoutParser do
it 'applies multiple extends in a single rule' do it 'applies multiple extends in a single rule' do
layout = Squib::LayoutParser.load_layout(layout_file('multi-extends-single-entry.yml')) layout = Squib::LayoutParser.load_layout(layout_file('multi-extends-single-entry.yml'))
expect(layout).to eq({'aunt' => { expect(layout).to eq({ 'aunt' => {
'a' => 101, 'a' => 101,
'b' => 102, 'b' => 102,
'c' => 103, 'c' => 103,
@ -94,7 +94,7 @@ describe Squib::LayoutParser do
it 'applies multi-level extends' do it 'applies multi-level extends' do
layout = Squib::LayoutParser.load_layout(layout_file('multi-level-extends.yml')) layout = Squib::LayoutParser.load_layout(layout_file('multi-level-extends.yml'))
expect(layout).to eq({'frame' => { expect(layout).to eq({ 'frame' => {
'x' => 38, 'x' => 38,
'y' => 38, 'y' => 38,
}, },

Loading…
Cancel
Save