👮 fix spacing inside hashes
parent
137e3f91cd
commit
5e09e0f1e1
|
|
@ -17,7 +17,7 @@ module Squib
|
|||
# DSL method. See http://squib.readthedocs.org
|
||||
def save_pdf(opts = {})
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ module Squib
|
|||
def save_sheet(opts = {})
|
||||
range = Args::CardRange.new(opts[:range], deck_size: size)
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ module Squib
|
|||
def showcase(opts = {})
|
||||
range = Args::CardRange.new(opts[:range], deck_size: size)
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ module Squib
|
|||
def hand(opts = {})
|
||||
range = Args::CardRange.new(opts[:range], deck_size: size)
|
||||
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)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ module Squib
|
|||
def ellipse(opts = {})
|
||||
range = Args::CardRange.new(opts[:range], deck_size: size)
|
||||
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]) }
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ module Squib
|
|||
def text(opts = {})
|
||||
range = Args::CardRange.new(opts[:range], deck_size: size)
|
||||
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)
|
||||
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)
|
||||
yield(embed) if block_given? #store the opts for later use
|
||||
extents = Array.new(@cards.size)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ module Squib
|
|||
key = Args::EmbedKey.new.validate_key(opts[:key])
|
||||
range = Args::CardRange.new(opts[:range], deck_size: @deck_size)
|
||||
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)
|
||||
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)
|
||||
|
|
@ -76,7 +76,7 @@ module Squib
|
|||
key = Args::EmbedKey.new.validate_key(opts[:key])
|
||||
range = Args::CardRange.new(opts[:range], deck_size: @deck_size)
|
||||
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)
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -105,8 +105,8 @@ module Squib
|
|||
x = Pango.pixels(rect.x) + search[:rule][:adjust].dx[@index]
|
||||
y = Pango.pixels(rect.y) + search[:rule][:adjust].dy[@index]
|
||||
h = rule[:box].height[@index]
|
||||
draw_calls << {x: x, y: y, h: h, # defer drawing until we've valigned
|
||||
draw: search[:rule][:draw]}
|
||||
draw_calls << { x: x, y: y, h: h, # defer drawing until we've valigned
|
||||
draw: search[:rule][:draw] }
|
||||
end
|
||||
return draw_calls
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
require 'squib'
|
||||
|
||||
data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
|
||||
'level' => [1, 2, 3]}
|
||||
data = { 'name' => ['Thief', 'Grifter', 'Mastermind'],
|
||||
'level' => [1, 2, 3] }
|
||||
|
||||
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||
background color: :white
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
require 'squib'
|
||||
|
||||
data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
|
||||
data = { 'name' => ['Thief', 'Grifter', 'Mastermind'],
|
||||
'type' => ['Thug', 'Thinker', 'Thinker'],
|
||||
'level' => [1, 2, 3]}
|
||||
'level' => [1, 2, 3] }
|
||||
|
||||
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||
# Default range is :all
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# encoding: UTF-8
|
||||
require 'squib'
|
||||
|
||||
data = {'name' => ['Thief', 'Grifter', 'Mastermind'],
|
||||
'level' => [1, 2, 3]}
|
||||
data = { 'name' => ['Thief', 'Grifter', 'Mastermind'],
|
||||
'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."
|
||||
|
||||
Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ require 'squib/args/box'
|
|||
|
||||
describe Squib::Args::Box do
|
||||
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
|
||||
expect(box).not_to respond_to(:x, :y, :width, :height)
|
||||
|
|
@ -20,13 +20,13 @@ describe Squib::Args::Box do
|
|||
end
|
||||
|
||||
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).not_to respond_to(:foo)
|
||||
end
|
||||
|
||||
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) }
|
||||
it 'expands box' do
|
||||
expect(box).to have_attributes({
|
||||
|
|
@ -81,7 +81,7 @@ describe Squib::Args::Box do
|
|||
end
|
||||
|
||||
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)
|
||||
box.load!(args, expand_by: 2, layout: layout)
|
||||
expect(box).to have_attributes(
|
||||
|
|
@ -94,7 +94,7 @@ describe Squib::Args::Box do
|
|||
context 'unit conversion' 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)
|
||||
expect(box).to have_attributes(
|
||||
x: [300, 600],
|
||||
|
|
@ -108,7 +108,7 @@ describe Squib::Args::Box do
|
|||
|
||||
context 'validation' 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)
|
||||
box = Squib::Args::Box.new(deck)
|
||||
box.load!(args, expand_by: 1)
|
||||
|
|
@ -116,7 +116,7 @@ describe Squib::Args::Box do
|
|||
end
|
||||
|
||||
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)
|
||||
expect(box).to have_attributes(x_radius: [3, 3], y_radius: [3, 3])
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ require 'spec_helper'
|
|||
require 'squib/args/draw'
|
||||
|
||||
describe Squib::Args::Draw do
|
||||
let(:custom_colors) { {'foo' => 'abc'} }
|
||||
let(:custom_colors) { { 'foo' => 'abc' } }
|
||||
subject(:draw) {Squib::Args::Draw.new(custom_colors)}
|
||||
|
||||
context 'unit conversion' do
|
||||
|
||||
it 'converts units on stroke width' do
|
||||
args = {stroke_width: '2in'}
|
||||
args = { stroke_width: '2in' }
|
||||
draw.load!(args, expand_by: 2)
|
||||
expect(draw).to have_attributes(stroke_width: [600, 600])
|
||||
end
|
||||
|
|
@ -16,7 +16,7 @@ describe Squib::Args::Draw do
|
|||
end
|
||||
|
||||
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
|
||||
draw.load!({}) # go right to defaults
|
||||
|
|
@ -28,7 +28,7 @@ describe Squib::Args::Draw do
|
|||
context 'validation' do
|
||||
|
||||
it 'converts to Cairo options' do
|
||||
args = {join: 'bevel', cap: 'round'}
|
||||
args = { join: 'bevel', cap: 'round' }
|
||||
draw.load!(args)
|
||||
expect(draw).to have_attributes(
|
||||
join: [Cairo::LINE_JOIN_BEVEL],
|
||||
|
|
@ -37,62 +37,62 @@ describe Squib::Args::Draw do
|
|||
end
|
||||
|
||||
it 'parses dash options' do
|
||||
args = {dash: '3 4 5'}
|
||||
args = { dash: '3 4 5' }
|
||||
draw.load!(args)
|
||||
expect(draw).to have_attributes(dash: [[3, 4, 5]])
|
||||
end
|
||||
|
||||
it 'parses more complex dash options' do
|
||||
args = {dash: '30.5, 90, 5'}
|
||||
args = { dash: '30.5, 90, 5' }
|
||||
draw.load!(args)
|
||||
expect(draw).to have_attributes(dash: [[30.5, 90, 5]])
|
||||
end
|
||||
|
||||
it 'does unit conversion on dash options' do
|
||||
args = {dash: '3in 4in 5in'}
|
||||
args = { dash: '3in 4in 5in' }
|
||||
draw.load!(args)
|
||||
expect(draw).to have_attributes(dash: [[900, 1200, 1500]])
|
||||
end
|
||||
|
||||
it 'converts line caps to Cairo constants' do
|
||||
args = {cap: :SQUARE}
|
||||
args = { cap: :SQUARE }
|
||||
draw.load! args
|
||||
expect(draw).to have_attributes( cap: [Cairo::LINE_CAP_SQUARE] )
|
||||
end
|
||||
|
||||
it 'converts line join' do
|
||||
args = {join: 'round'}
|
||||
args = { join: 'round' }
|
||||
draw.load! args
|
||||
expect(draw).to have_attributes( join: [Cairo::LINE_JOIN_ROUND] )
|
||||
end
|
||||
|
||||
it 'allows fill_first stroke_strategy' do
|
||||
args = {stroke_strategy: :FILL_first}
|
||||
args = { stroke_strategy: :FILL_first }
|
||||
draw.load! args
|
||||
expect(draw).to have_attributes( stroke_strategy: [:fill_first] )
|
||||
end
|
||||
|
||||
it 'allows stroke_first stroke_strategy' do
|
||||
args = {stroke_strategy: ' stroke_FIRST '}
|
||||
args = { stroke_strategy: ' stroke_FIRST ' }
|
||||
draw.load! args
|
||||
expect(draw).to have_attributes( stroke_strategy: [:stroke_first] )
|
||||
end
|
||||
|
||||
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")
|
||||
end
|
||||
|
||||
context 'custom colors' do
|
||||
|
||||
it 'looks up custom colors in the config' do
|
||||
draw.load!({color: 'foo'})
|
||||
draw.load!({ color: 'foo' })
|
||||
expect(draw.color).to eq ['abc']
|
||||
end
|
||||
|
||||
it 'passes on through for non-custom color' do
|
||||
draw = Squib::Args::Draw.new(custom_colors)
|
||||
draw.load!({color: 'bar'})
|
||||
draw.load!({ color: 'bar' })
|
||||
expect(draw.color).to eq ['bar']
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ describe Squib::Args::InputFile do
|
|||
context 'validate_file' 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)
|
||||
expect(ifile).to have_attributes(file: [File.expand_path(__FILE__)])
|
||||
end
|
||||
|
||||
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!")
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -2,19 +2,19 @@ require 'spec_helper'
|
|||
require 'squib/args/paint'
|
||||
|
||||
describe Squib::Args::Draw do
|
||||
let(:custom_colors) { {'foo' => 'abc'} }
|
||||
let(:custom_colors) { { 'foo' => 'abc' } }
|
||||
subject(:paint) {Squib::Args::Paint.new(custom_colors)}
|
||||
|
||||
context 'alpha' do
|
||||
|
||||
it 'can be a float' do
|
||||
args = {alpha: 0.6}
|
||||
args = { alpha: 0.6 }
|
||||
paint.load!(args)
|
||||
expect(paint.alpha).to eq [0.6]
|
||||
end
|
||||
|
||||
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')
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ describe Squib::Args::Paragraph do
|
|||
|
||||
context 'str validator' do
|
||||
it 'converts everything to string' do
|
||||
para.load!( {str: 5} )
|
||||
para.load!( { str: 5 } )
|
||||
expect(para.str).to eq ['5']
|
||||
end
|
||||
end
|
||||
|
|
@ -25,7 +25,7 @@ describe Squib::Args::Paragraph do
|
|||
end
|
||||
|
||||
it 'uses specified font when given' do
|
||||
para.load!( {font: 'MyFont 8'})
|
||||
para.load!( { font: 'MyFont 8' })
|
||||
expect(para.font).to eq ['MyFont 8']
|
||||
end
|
||||
end
|
||||
|
|
@ -53,100 +53,100 @@ describe Squib::Args::Paragraph do
|
|||
|
||||
context 'wrap validator' do
|
||||
it 'converts to pango wrap word' do
|
||||
para.load!( { wrap: 'word'} )
|
||||
para.load!( { wrap: 'word' } )
|
||||
expect(para.wrap).to eq [Pango::WRAP_WORD]
|
||||
end
|
||||
|
||||
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]
|
||||
end
|
||||
|
||||
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]
|
||||
end
|
||||
|
||||
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]
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
context 'ellipsize validator' 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]
|
||||
end
|
||||
|
||||
it 'converts to pango with start' do
|
||||
para.load!( { ellipsize: :StArt} )
|
||||
para.load!( { ellipsize: :StArt } )
|
||||
expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_START]
|
||||
end
|
||||
|
||||
it 'converts to pango middle' do
|
||||
para.load!( { ellipsize: 'middle'} )
|
||||
para.load!( { ellipsize: 'middle' } )
|
||||
expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_MIDDLE]
|
||||
end
|
||||
|
||||
it 'converts to pango end' do
|
||||
para.load!( { ellipsize: 'END'} )
|
||||
para.load!( { ellipsize: 'END' } )
|
||||
expect(para.ellipsize).to eq [Pango::Layout::ELLIPSIZE_END]
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
context 'justify validator' do
|
||||
it 'allows nil' do
|
||||
para.load!( { justify: nil} )
|
||||
para.load!( { justify: nil } )
|
||||
expect(para.justify).to eq [nil]
|
||||
end
|
||||
|
||||
it 'can be true' do
|
||||
para.load!( { justify: true} )
|
||||
para.load!( { justify: true } )
|
||||
expect(para.justify).to eq [true]
|
||||
end
|
||||
|
||||
it 'can be false' do
|
||||
para.load!( { justify: false} )
|
||||
para.load!( { justify: false } )
|
||||
expect(para.justify).to eq [false]
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
context 'spacing validator' do
|
||||
it 'allows nil' do
|
||||
para.load!( { spacing: nil} )
|
||||
para.load!( { spacing: nil } )
|
||||
expect(para.spacing).to eq [nil]
|
||||
end
|
||||
it 'is converted to Pango space' do
|
||||
para.load!( { spacing: 519} )
|
||||
para.load!( { spacing: 519 } )
|
||||
expect(para.spacing).to eq [Pango::SCALE * 519.0]
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
context 'valign validator' do
|
||||
it 'converts top' do
|
||||
para.load!( { valign: :top} )
|
||||
para.load!( { valign: :top } )
|
||||
expect(para.valign).to eq ['top']
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ describe Squib::Args::SaveBatch do
|
|||
|
||||
context 'dir' do
|
||||
it 'is created if not exists (and warns)' do
|
||||
opts = {dir: 'tocreate'}
|
||||
opts = { dir: 'tocreate' }
|
||||
Dir.chdir(output_dir) do
|
||||
FileUtils.rm_rf('tocreate', secure: true)
|
||||
expect(Squib.logger).to receive(:warn).with("Dir 'tocreate' does not exist, creating it.").once
|
||||
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
|
||||
end
|
||||
end
|
||||
|
|
@ -21,29 +21,29 @@ describe Squib::Args::SaveBatch do
|
|||
it 'does nothing by default' do
|
||||
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
|
||||
|
||||
it 'rotates by pi/2 with true' do
|
||||
opts = {rotate: true}
|
||||
opts = { rotate: true }
|
||||
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
|
||||
|
||||
it 'rotates by pi/2' do
|
||||
opts = {rotate: :clockwise}
|
||||
opts = { rotate: :clockwise }
|
||||
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
|
||||
|
||||
it 'rotates by pi/2 with counterclockwise' do
|
||||
opts = {rotate: :counterclockwise}
|
||||
opts = { rotate: :counterclockwise }
|
||||
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
|
||||
|
||||
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]')
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ describe Squib::Args::ScaleBox do
|
|||
|
||||
context 'unit conversion' 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)
|
||||
expect(box).to have_attributes(
|
||||
x: [300, 600],
|
||||
|
|
@ -19,7 +19,7 @@ describe Squib::Args::ScaleBox do
|
|||
|
||||
context 'validation' 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)
|
||||
box = Squib::Args::Box.new(deck)
|
||||
box.load!(args, expand_by: 1)
|
||||
|
|
@ -27,41 +27,41 @@ describe Squib::Args::ScaleBox do
|
|||
end
|
||||
|
||||
it 'allows :native' do
|
||||
args = {width: :native, height: :native}
|
||||
args = { width: :native, height: :native }
|
||||
box.load!(args, expand_by: 1)
|
||||
expect(box).to have_attributes(width: [:native], height: [:native])
|
||||
end
|
||||
|
||||
it 'allows native to be a string' do
|
||||
args = {width: 'native'}
|
||||
args = { width: 'native' }
|
||||
box.load!(args, expand_by: 1)
|
||||
expect(box).to have_attributes(width: [:native], height: [:native])
|
||||
end
|
||||
|
||||
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)
|
||||
expect(box).to have_attributes(width: [:scale], height: [75])
|
||||
end
|
||||
|
||||
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)
|
||||
expect(box).to have_attributes(width: [75], height: [:scale])
|
||||
end
|
||||
|
||||
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')
|
||||
end
|
||||
|
||||
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')
|
||||
end
|
||||
|
||||
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')
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ require 'squib/args/sheet'
|
|||
describe Squib::Args::Sheet 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
|
||||
sheet.load!({}) # go right to defaults
|
||||
|
|
@ -29,13 +29,13 @@ describe Squib::Args::Sheet do
|
|||
end
|
||||
|
||||
it 'computes properly on non-integer' do
|
||||
opts = {columns: 1, rows: :infinite}
|
||||
opts = { columns: 1, rows: :infinite }
|
||||
sheet.load! opts
|
||||
expect(sheet).to have_attributes( columns: 1, rows: 4 )
|
||||
end
|
||||
|
||||
it 'computes properly on unspecified rows' do
|
||||
opts = {columns: 1}
|
||||
opts = { columns: 1 }
|
||||
sheet.load! opts
|
||||
expect(sheet).to have_attributes( columns: 1, rows: 4 )
|
||||
end
|
||||
|
|
@ -47,7 +47,7 @@ describe Squib::Args::Sheet do
|
|||
end
|
||||
|
||||
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')
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@ require 'squib/args/transform'
|
|||
|
||||
describe Squib::Args::Box do
|
||||
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
|
||||
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)
|
||||
trans = Squib::Args::Transform.new(deck)
|
||||
trans.load!(args, expand_by: 1)
|
||||
|
|
@ -15,7 +15,7 @@ describe Squib::Args::Box do
|
|||
end
|
||||
|
||||
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)
|
||||
expect(trans).to have_attributes(crop_corner_x_radius: [3, 3], crop_corner_y_radius: [3, 3])
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ describe Squib::LayoutParser do
|
|||
|
||||
it 'loads a normal layout with no extends' do
|
||||
layout = Squib::LayoutParser.load_layout(layout_file('no-extends.yml'))
|
||||
expect(layout).to eq({'frame' => {
|
||||
expect(layout).to eq({ 'frame' => {
|
||||
'x' => 38,
|
||||
'valign' => :middle,
|
||||
'str' => 'blah',
|
||||
|
|
@ -16,7 +16,7 @@ describe Squib::LayoutParser do
|
|||
|
||||
it 'loads with a single extends' do
|
||||
layout = Squib::LayoutParser.load_layout(layout_file('single-extends.yml'))
|
||||
expect(layout).to eq({'frame' => {
|
||||
expect(layout).to eq({ 'frame' => {
|
||||
'x' => 38,
|
||||
'y' => 38,
|
||||
},
|
||||
|
|
@ -32,7 +32,7 @@ describe Squib::LayoutParser do
|
|||
|
||||
it 'applies the extends regardless of order' do
|
||||
layout = Squib::LayoutParser.load_layout(layout_file('pre-extends.yml'))
|
||||
expect(layout).to eq({'frame' => {
|
||||
expect(layout).to eq({ 'frame' => {
|
||||
'x' => 38,
|
||||
'y' => 38,
|
||||
},
|
||||
|
|
@ -48,7 +48,7 @@ describe Squib::LayoutParser do
|
|||
|
||||
it 'applies the single-level extends multiple times' do
|
||||
layout = Squib::LayoutParser.load_layout(layout_file('single-level-multi-extends.yml'))
|
||||
expect(layout).to eq({'frame' => {
|
||||
expect(layout).to eq({ 'frame' => {
|
||||
'x' => 38,
|
||||
'y' => 38,
|
||||
},
|
||||
|
|
@ -70,7 +70,7 @@ describe Squib::LayoutParser do
|
|||
|
||||
it 'applies multiple extends in a single rule' do
|
||||
layout = Squib::LayoutParser.load_layout(layout_file('multi-extends-single-entry.yml'))
|
||||
expect(layout).to eq({'aunt' => {
|
||||
expect(layout).to eq({ 'aunt' => {
|
||||
'a' => 101,
|
||||
'b' => 102,
|
||||
'c' => 103,
|
||||
|
|
@ -94,7 +94,7 @@ describe Squib::LayoutParser do
|
|||
|
||||
it 'applies multi-level extends' do
|
||||
layout = Squib::LayoutParser.load_layout(layout_file('multi-level-extends.yml'))
|
||||
expect(layout).to eq({'frame' => {
|
||||
expect(layout).to eq({ 'frame' => {
|
||||
'x' => 38,
|
||||
'y' => 38,
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue