👮 fix space after comma
parent
a768561e91
commit
8a9552126c
2
Rakefile
2
Rakefile
|
|
@ -10,7 +10,7 @@ task default: [:install, :spec]
|
||||||
# Useful for hooking up with SublimeText.
|
# Useful for hooking up with SublimeText.
|
||||||
# e.g. rake sample[basic.rb]
|
# e.g. rake sample[basic.rb]
|
||||||
desc 'Run a specific sample'
|
desc 'Run a specific sample'
|
||||||
task :run,[:file] => :install do |t, args|
|
task :run, [:file] => :install do |t, args|
|
||||||
args.with_defaults(file: 'basic.rb')
|
args.with_defaults(file: 'basic.rb')
|
||||||
Dir.chdir('samples') do
|
Dir.chdir('samples') do
|
||||||
args[:file] << ".rb" unless args[:file].end_with? '.rb'
|
args[:file] << ".rb" unless args[:file].end_with? '.rb'
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,13 @@ module Squib
|
||||||
s.default_sheet = s.sheets[input.sheet[0]]
|
s.default_sheet = s.sheets[input.sheet[0]]
|
||||||
data = {}
|
data = {}
|
||||||
s.first_column.upto(s.last_column) do |col|
|
s.first_column.upto(s.last_column) do |col|
|
||||||
header = s.cell(s.first_row,col).to_s
|
header = s.cell(s.first_row, col).to_s
|
||||||
header.strip! if import.strip?
|
header.strip! if import.strip?
|
||||||
data[header] = []
|
data[header] = []
|
||||||
(s.first_row + 1).upto(s.last_row) do |row|
|
(s.first_row + 1).upto(s.last_row) do |row|
|
||||||
cell = s.cell(row,col)
|
cell = s.cell(row, col)
|
||||||
# Roo hack for avoiding unnecessary .0's on whole integers (https://github.com/roo-rb/roo/issues/139)
|
# Roo hack for avoiding unnecessary .0's on whole integers (https://github.com/roo-rb/roo/issues/139)
|
||||||
cell = s.excelx_value(row,col) if s.excelx_type(row,col) == [:numeric_or_formula, 'General']
|
cell = s.excelx_value(row, col) if s.excelx_type(row, col) == [:numeric_or_formula, 'General']
|
||||||
cell.strip! if cell.respond_to?(:strip) && import.strip?
|
cell.strip! if cell.respond_to?(:strip) && import.strip?
|
||||||
cell = yield(header, cell) if block_given?
|
cell = yield(header, cell) if block_given?
|
||||||
data[header] << cell
|
data[header] << cell
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ module Squib
|
||||||
new_val = val.map.with_index{ |v, i| send(method, v, i) }
|
new_val = val.map.with_index{ |v, i| send(method, v, i) }
|
||||||
instance_variable_set(attribute, new_val)
|
instance_variable_set(attribute, new_val)
|
||||||
else
|
else
|
||||||
instance_variable_set(attribute,send(method, val))
|
instance_variable_set(attribute, send(method, val))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ module Squib
|
||||||
@progress_bar.start("Saving PDF to #{file}", range.size) do |bar|
|
@progress_bar.start("Saving PDF to #{file}", range.size) do |bar|
|
||||||
range.each do |i|
|
range.each do |i|
|
||||||
card = @cards[i]
|
card = @cards[i]
|
||||||
cc.translate(x,y)
|
cc.translate(x, y)
|
||||||
cc.rectangle(sheet.trim, sheet.trim, card_width, card_height)
|
cc.rectangle(sheet.trim, sheet.trim, card_width, card_height)
|
||||||
cc.clip
|
cc.clip
|
||||||
case card.backend.downcase.to_sym
|
case card.backend.downcase.to_sym
|
||||||
|
|
@ -23,7 +23,7 @@ module Squib
|
||||||
when :svg
|
when :svg
|
||||||
card.cairo_surface.finish
|
card.cairo_surface.finish
|
||||||
cc.save
|
cc.save
|
||||||
cc.scale(0.8,0.8) # I really don't know why I needed to do this at all. But 0.8 is the magic number to get this to scale right
|
cc.scale(0.8, 0.8) # I really don't know why I needed to do this at all. But 0.8 is the magic number to get this to scale right
|
||||||
cc.render_rsvg_handle(RSVG::Handle.new_from_file(card.svgfile), nil)
|
cc.render_rsvg_handle(RSVG::Handle.new_from_file(card.svgfile), nil)
|
||||||
cc.restore
|
cc.restore
|
||||||
else
|
else
|
||||||
|
|
@ -31,14 +31,14 @@ module Squib
|
||||||
end
|
end
|
||||||
bar.increment
|
bar.increment
|
||||||
cc.reset_clip
|
cc.reset_clip
|
||||||
cc.translate(-x,-y)
|
cc.translate(-x, -y)
|
||||||
x += card.width + sheet.gap - 2*sheet.trim
|
x += card.width + sheet.gap - 2*sheet.trim
|
||||||
if x > (sheet.width - card_width - sheet.margin)
|
if x > (sheet.width - card_width - sheet.margin)
|
||||||
x = sheet.margin
|
x = sheet.margin
|
||||||
y += card.height + sheet.gap - 2*sheet.trim
|
y += card.height + sheet.gap - 2*sheet.trim
|
||||||
if y > (sheet.height - card_height - sheet.margin)
|
if y > (sheet.height - card_height - sheet.margin)
|
||||||
cc.show_page # next page
|
cc.show_page # next page
|
||||||
x,y = sheet.margin,sheet.margin
|
x, y = sheet.margin, sheet.margin
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -92,7 +92,7 @@ module Squib
|
||||||
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)
|
||||||
cc = Cairo::Context.new(tmp)
|
cc = Cairo::Context.new(tmp)
|
||||||
cc.set_source(surface,-1*trim, -1*trim)
|
cc.set_source(surface, -1*trim, -1*trim)
|
||||||
cc.paint
|
cc.paint
|
||||||
surface = tmp
|
surface = tmp
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -52,9 +52,9 @@ module Squib
|
||||||
tmp_cc.transform(matrix) # flips the coordinate system
|
tmp_cc.transform(matrix) # flips the coordinate system
|
||||||
top_y = src.height # top of the reflection
|
top_y = src.height # top of the reflection
|
||||||
bottom_y = src.height * (1.0 - rpercent) + roffset # bottom of the reflection
|
bottom_y = src.height * (1.0 - rpercent) + roffset # bottom of the reflection
|
||||||
gradient = Cairo::LinearPattern.new(0,top_y, 0,bottom_y)
|
gradient = Cairo::LinearPattern.new(0, top_y, 0, bottom_y)
|
||||||
gradient.add_color_stop_rgba(0.0, 0,0,0, rstrength) # start a little reflected
|
gradient.add_color_stop_rgba(0.0, 0, 0, 0, rstrength) # start a little reflected
|
||||||
gradient.add_color_stop_rgba(1.0, 0,0,0, 0.0) # fade to nothing
|
gradient.add_color_stop_rgba(1.0, 0, 0, 0, 0.0) # fade to nothing
|
||||||
tmp_cc.set_source(src, 0, 0)
|
tmp_cc.set_source(src, 0, 0)
|
||||||
tmp_cc.mask(gradient)
|
tmp_cc.mask(gradient)
|
||||||
return tmp_cc.target
|
return tmp_cc.target
|
||||||
|
|
@ -74,7 +74,7 @@ module Squib
|
||||||
dest_cxt.translate 0, src.height / 2.0 * (1.0 - factor)
|
dest_cxt.translate 0, src.height / 2.0 * (1.0 - factor)
|
||||||
dest_cxt.scale factor * scale, factor
|
dest_cxt.scale factor * scale, factor
|
||||||
dest_cxt.set_source src, 0, 0
|
dest_cxt.set_source src, 0, 0
|
||||||
dest_cxt.rounded_rectangle i, 0, out_thickness, src.height, 0,0
|
dest_cxt.rounded_rectangle i, 0, out_thickness, src.height, 0, 0
|
||||||
dest_cxt.fill
|
dest_cxt.fill
|
||||||
dest_cxt.restore
|
dest_cxt.restore
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,9 @@ module Squib
|
||||||
parent_keys.each do |parent_key|
|
parent_keys.each do |parent_key|
|
||||||
from_extends = yml[key].merge(recurse_extends(yml, parent_key, visited)) do |key, child_val, parent_val|
|
from_extends = yml[key].merge(recurse_extends(yml, parent_key, visited)) do |key, child_val, parent_val|
|
||||||
if child_val.to_s.strip.start_with?('+=')
|
if child_val.to_s.strip.start_with?('+=')
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -12,7 +12,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||||
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
|
||||||
svg range: 1..2, file: 'spanner.svg', x: 620, y: 218
|
svg range: 1..2, file: 'spanner.svg', x: 620, y: 218
|
||||||
|
|
||||||
save prefix: 'basic_', format: :png
|
save prefix: 'basic_', format: :png
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ end
|
||||||
Squib::Deck.new(width: 3000, height: 1500) do
|
Squib::Deck.new(width: 3000, height: 1500) do
|
||||||
colors = (Cairo::Color.constants - %i(HEX_RE Base RGB CMYK HSV X11))
|
colors = (Cairo::Color.constants - %i(HEX_RE Base RGB CMYK HSV X11))
|
||||||
colors.sort_by! {|c| Cairo::Color.parse(c).to_s}
|
colors.sort_by! {|c| Cairo::Color.parse(c).to_s}
|
||||||
x,y,w,h = 0,0,300,50
|
x, y, w, h = 0, 0, 300, 50
|
||||||
colors.each_with_index do |color, i|
|
colors.each_with_index do |color, i|
|
||||||
rect x: x, y: y, width: w, height: h, fill_color: color
|
rect x: x, y: y, width: w, height: h, fill_color: color
|
||||||
text str: color.to_s, x: x + 5, y: y+13, font: 'Sans Bold 16',
|
text str: color.to_s, x: x + 5, y: y+13, font: 'Sans Bold 16',
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,6 @@ Squib::Deck.new do
|
||||||
use_layout file: 'custom-layout.yml'
|
use_layout file: 'custom-layout.yml'
|
||||||
use_layout file: 'custom-layout2.yml'
|
use_layout file: 'custom-layout2.yml'
|
||||||
text str: 'The Title', layout: :title # from custom-layout.yml
|
text str: 'The Title', layout: :title # from custom-layout.yml
|
||||||
text str: 'The Subtitle',layout: :subtitle # redefined in custom-layout2.yml
|
text str: 'The Subtitle', layout: :subtitle # redefined in custom-layout2.yml
|
||||||
save_png prefix: 'layout3_'
|
save_png prefix: 'layout3_'
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ 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
|
||||||
|
|
@ -26,7 +26,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 3) do
|
||||||
text range: -2..-1, str: 'Grifter and Mastermind only!', x: 25, y: 650
|
text range: -2..-1, str: 'Grifter and Mastermind only!', x: 25, y: 650
|
||||||
|
|
||||||
# We can use Arrays too!
|
# We can use Arrays too!
|
||||||
text range: [0,2], str: 'Thief and Mastermind only!!', x: 25, y:300
|
text range: [0, 2], str: 'Thief and Mastermind only!!', x: 25, y:300
|
||||||
|
|
||||||
# Just about everything in Squib can be given an array that
|
# Just about everything in Squib can be given an array that
|
||||||
# corresponds to the deck's cards. This allows for each card to be styled differently
|
# corresponds to the deck's cards. This allows for each card to be styled differently
|
||||||
|
|
@ -38,13 +38,13 @@ 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
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ describe Squib::Graphics::CairoContextWrapper do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
dbl = double(Cairo::LinearPattern)
|
dbl = double(Cairo::LinearPattern)
|
||||||
mtx = double(Cairo::Matrix)
|
mtx = double(Cairo::Matrix)
|
||||||
expect(Cairo::LinearPattern).to receive(:new).with(1,2,3,4).and_return(dbl)
|
expect(Cairo::LinearPattern).to receive(:new).with(1, 2, 3, 4).and_return(dbl)
|
||||||
expect(dbl).to receive(:add_color_stop).with(0.0, 'blue')
|
expect(dbl).to receive(:add_color_stop).with(0.0, 'blue')
|
||||||
expect(dbl).to receive(:add_color_stop).with(1.0, 'red')
|
expect(dbl).to receive(:add_color_stop).with(1.0, 'red')
|
||||||
expect(cairo).to receive(:matrix).and_return(mtx)
|
expect(cairo).to receive(:matrix).and_return(mtx)
|
||||||
|
|
@ -50,7 +50,7 @@ describe Squib::Graphics::CairoContextWrapper do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
dbl = double(Cairo::RadialPattern)
|
dbl = double(Cairo::RadialPattern)
|
||||||
mtx = double(Cairo::Matrix)
|
mtx = double(Cairo::Matrix)
|
||||||
expect(Cairo::RadialPattern).to receive(:new).with(1,2,5,3,4,6).and_return(dbl)
|
expect(Cairo::RadialPattern).to receive(:new).with(1, 2, 5, 3, 4, 6).and_return(dbl)
|
||||||
expect(dbl).to receive(:add_color_stop).with(0.0, 'blue')
|
expect(dbl).to receive(:add_color_stop).with(0.0, 'blue')
|
||||||
expect(dbl).to receive(:add_color_stop).with(1.0, 'red')
|
expect(dbl).to receive(:add_color_stop).with(1.0, 'red')
|
||||||
expect(cairo).to receive(:matrix).and_return(mtx)
|
expect(cairo).to receive(:matrix).and_return(mtx)
|
||||||
|
|
@ -68,7 +68,7 @@ describe Squib::Graphics::CairoContextWrapper do
|
||||||
it 'on radial patterns' do
|
it 'on radial patterns' do
|
||||||
dbl = double(Cairo::RadialPattern)
|
dbl = double(Cairo::RadialPattern)
|
||||||
mtx = double(Cairo::Matrix)
|
mtx = double(Cairo::Matrix)
|
||||||
expect(Cairo::RadialPattern).to receive(:new).with(1,2,5,3,4,6).and_return(dbl)
|
expect(Cairo::RadialPattern).to receive(:new).with(1, 2, 5, 3, 4, 6).and_return(dbl)
|
||||||
expect(dbl).to receive(:add_color_stop).with(0.0, '#def')
|
expect(dbl).to receive(:add_color_stop).with(0.0, '#def')
|
||||||
expect(dbl).to receive(:add_color_stop).with(1.0, '#112233')
|
expect(dbl).to receive(:add_color_stop).with(1.0, '#112233')
|
||||||
expect(cairo).to receive(:matrix).and_return(mtx)
|
expect(cairo).to receive(:matrix).and_return(mtx)
|
||||||
|
|
@ -80,7 +80,7 @@ describe Squib::Graphics::CairoContextWrapper do
|
||||||
it 'on linear patterns' do
|
it 'on linear patterns' do
|
||||||
dbl = double(Cairo::LinearPattern)
|
dbl = double(Cairo::LinearPattern)
|
||||||
mtx = double(Cairo::Matrix)
|
mtx = double(Cairo::Matrix)
|
||||||
expect(Cairo::LinearPattern).to receive(:new).with(1,2,3,4).and_return(dbl)
|
expect(Cairo::LinearPattern).to receive(:new).with(1, 2, 3, 4).and_return(dbl)
|
||||||
expect(dbl).to receive(:add_color_stop).with(0.0, '#def')
|
expect(dbl).to receive(:add_color_stop).with(0.0, '#def')
|
||||||
expect(dbl).to receive(:add_color_stop).with(1.0, '#112233')
|
expect(dbl).to receive(:add_color_stop).with(1.0, '#112233')
|
||||||
expect(cairo).to receive(:matrix).and_return(mtx)
|
expect(cairo).to receive(:matrix).and_return(mtx)
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ describe Squib::Deck, '#save_pdf' do
|
||||||
expect(cxt).to receive(:set_source) # place the card
|
expect(cxt).to receive(:set_source) # place the card
|
||||||
.with(instance_of(Cairo::ImageSurface), 0, 0).once
|
.with(instance_of(Cairo::ImageSurface), 0, 0).once
|
||||||
expect(cxt).to receive(:paint).once # paint placed card
|
expect(cxt).to receive(:paint).once # paint placed card
|
||||||
expect(cxt).to receive(:translate).with(-x,-y).once
|
expect(cxt).to receive(:translate).with(-x, -y).once
|
||||||
expect(cxt).to receive(:reset_clip).once
|
expect(cxt).to receive(:reset_clip).once
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ describe Squib::LayoutParser do
|
||||||
'b' => 106,
|
'b' => 106,
|
||||||
},
|
},
|
||||||
'child' => {
|
'child' => {
|
||||||
'extends' => ['uncle','aunt'],
|
'extends' => ['uncle', 'aunt'],
|
||||||
'a' => 107, # my own
|
'a' => 107, # my own
|
||||||
'b' => 102, # from the younger aunt
|
'b' => 102, # from the younger aunt
|
||||||
'c' => 103, # from aunt
|
'c' => 103, # from aunt
|
||||||
|
|
|
||||||
|
|
@ -1,155 +1,155 @@
|
||||||
require 'simplecov'
|
require 'simplecov'
|
||||||
require 'coveralls'
|
require 'coveralls'
|
||||||
# require 'byebug'
|
# require 'byebug'
|
||||||
|
|
||||||
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
|
||||||
SimpleCov::Formatter::HTMLFormatter,
|
SimpleCov::Formatter::HTMLFormatter,
|
||||||
Coveralls::SimpleCov::Formatter
|
Coveralls::SimpleCov::Formatter
|
||||||
])
|
])
|
||||||
SimpleCov.start
|
SimpleCov.start
|
||||||
|
|
||||||
require 'squib'
|
require 'squib'
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.mock_with :rspec do |mocks|
|
config.mock_with :rspec do |mocks|
|
||||||
mocks.verify_partial_doubles = true
|
mocks.verify_partial_doubles = true
|
||||||
end
|
end
|
||||||
config.tty = true
|
config.tty = true
|
||||||
config.color = true
|
config.color = true
|
||||||
end
|
end
|
||||||
|
|
||||||
def tmp_dir
|
def tmp_dir
|
||||||
"#{File.expand_path(File.dirname(__FILE__))}/../tmp"
|
"#{File.expand_path(File.dirname(__FILE__))}/../tmp"
|
||||||
end
|
end
|
||||||
|
|
||||||
def samples_dir
|
def samples_dir
|
||||||
File.expand_path("#{File.dirname(__FILE__)}/../samples")
|
File.expand_path("#{File.dirname(__FILE__)}/../samples")
|
||||||
end
|
end
|
||||||
|
|
||||||
def layout_file(str)
|
def layout_file(str)
|
||||||
"#{File.expand_path(File.dirname(__FILE__))}/data/layouts/#{str}"
|
"#{File.expand_path(File.dirname(__FILE__))}/data/layouts/#{str}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def sample_file(file)
|
def sample_file(file)
|
||||||
"#{File.expand_path(File.dirname(__FILE__))}/../samples/#{file}"
|
"#{File.expand_path(File.dirname(__FILE__))}/../samples/#{file}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def sample_regression_file(file)
|
def sample_regression_file(file)
|
||||||
"#{File.expand_path(File.dirname(__FILE__))}/data/samples/#{file}.txt"
|
"#{File.expand_path(File.dirname(__FILE__))}/data/samples/#{file}.txt"
|
||||||
end
|
end
|
||||||
|
|
||||||
def csv_file(file)
|
def csv_file(file)
|
||||||
"#{File.expand_path(File.dirname(__FILE__))}/data/csv/#{file}"
|
"#{File.expand_path(File.dirname(__FILE__))}/data/csv/#{file}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def xlsx_file(file)
|
def xlsx_file(file)
|
||||||
"#{File.expand_path(File.dirname(__FILE__))}/data/xlsx/#{file}"
|
"#{File.expand_path(File.dirname(__FILE__))}/data/xlsx/#{file}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def project_template(file)
|
def project_template(file)
|
||||||
"#{File.expand_path(File.dirname(__FILE__))}/../lib/squib/project_template/#{file}"
|
"#{File.expand_path(File.dirname(__FILE__))}/../lib/squib/project_template/#{file}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def conf(file)
|
def conf(file)
|
||||||
"#{File.expand_path(File.dirname(__FILE__))}/data/conf/#{file}"
|
"#{File.expand_path(File.dirname(__FILE__))}/data/conf/#{file}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def overwrite_sample(sample_name, log)
|
def overwrite_sample(sample_name, log)
|
||||||
# Use this to overwrite the regression with current state
|
# Use this to overwrite the regression with current state
|
||||||
File.open(sample_regression_file(sample_name), 'w+:UTF-8') do |f|
|
File.open(sample_regression_file(sample_name), 'w+:UTF-8') do |f|
|
||||||
f.write(log.string)
|
f.write(log.string)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def scrub_hex(str)
|
def scrub_hex(str)
|
||||||
str.gsub(/0x\w{1,8}/,'')
|
str.gsub(/0x\w{1,8}/, '')
|
||||||
.gsub(/ptr=\w{1,8}/,'')
|
.gsub(/ptr=\w{1,8}/, '')
|
||||||
.gsub(/#<Pango::FontDescription:.*>/,'')
|
.gsub(/#<Pango::FontDescription:.*>/, '')
|
||||||
.gsub(/#<Cairo::ImageSurface:.*>/,'ImageSurface')
|
.gsub(/#<Cairo::ImageSurface:.*>/, 'ImageSurface')
|
||||||
.gsub(/#<Cairo::LinearPattern:.*>/,'LinearPattern')
|
.gsub(/#<Cairo::LinearPattern:.*>/, 'LinearPattern')
|
||||||
.gsub(/#<Cairo::RadialPattern:.*>/,'RadialPattern')
|
.gsub(/#<Cairo::RadialPattern:.*>/, 'RadialPattern')
|
||||||
.gsub(/#<Cairo::Matrix:.*>/,'Matrix')
|
.gsub(/#<Cairo::Matrix:.*>/, 'Matrix')
|
||||||
.gsub(/#<RSVG::Handle.*>/,'RSVG::Handle')
|
.gsub(/#<RSVG::Handle.*>/, 'RSVG::Handle')
|
||||||
.gsub(/#<RSpec::Mocks::Double:.*>/,'MockDouble')
|
.gsub(/#<RSpec::Mocks::Double:.*>/, 'MockDouble')
|
||||||
.gsub(/#<Double .*>/,'MockDouble')
|
.gsub(/#<Double .*>/, 'MockDouble')
|
||||||
.gsub(/RGB:\w{1,8}/,'RGB:')
|
.gsub(/RGB:\w{1,8}/, 'RGB:')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Build a mock cairo instance that allows basically any method
|
# Build a mock cairo instance that allows basically any method
|
||||||
# and logs that call to the string buffer
|
# and logs that call to the string buffer
|
||||||
def mock_cairo(strio)
|
def mock_cairo(strio)
|
||||||
cxt = double(Cairo::Context)
|
cxt = double(Cairo::Context)
|
||||||
surface = double(Cairo::ImageSurface)
|
surface = double(Cairo::ImageSurface)
|
||||||
pango = double(Pango::Layout)
|
pango = double(Pango::Layout)
|
||||||
|
|
||||||
font = double(Pango::FontDescription)
|
font = double(Pango::FontDescription)
|
||||||
iter = double('pango_iter')
|
iter = double('pango_iter')
|
||||||
pango_cxt = double('pango_cxt')
|
pango_cxt = double('pango_cxt')
|
||||||
allow(Squib.logger).to receive(:warn) {}
|
allow(Squib.logger).to receive(:warn) {}
|
||||||
allow(ProgressBar).to receive(:create).and_return(Squib::DoNothing.new)
|
allow(ProgressBar).to receive(:create).and_return(Squib::DoNothing.new)
|
||||||
allow(Cairo::ImageSurface).to receive(:new).and_return(surface)
|
allow(Cairo::ImageSurface).to receive(:new).and_return(surface)
|
||||||
allow(surface).to receive(:width).and_return(100)
|
allow(surface).to receive(:width).and_return(100)
|
||||||
allow(surface).to receive(:height).and_return(101)
|
allow(surface).to receive(:height).and_return(101)
|
||||||
allow(surface).to receive(:ink_extents).and_return([0,0,100,100])
|
allow(surface).to receive(:ink_extents).and_return([0, 0, 100, 100])
|
||||||
allow(Cairo::Context).to receive(:new).and_return(cxt)
|
allow(Cairo::Context).to receive(:new).and_return(cxt)
|
||||||
allow(cxt).to receive(:create_pango_layout).and_return(pango)
|
allow(cxt).to receive(:create_pango_layout).and_return(pango)
|
||||||
allow(cxt).to receive(:target).and_return(surface)
|
allow(cxt).to receive(:target).and_return(surface)
|
||||||
allow(cxt).to receive(:matrix).and_return(Cairo::Matrix.new(1,0,0,1,0,0))
|
allow(cxt).to receive(:matrix).and_return(Cairo::Matrix.new(1, 0, 0, 1, 0, 0))
|
||||||
allow(pango).to receive(:height).and_return(25)
|
allow(pango).to receive(:height).and_return(25)
|
||||||
allow(pango).to receive(:width).and_return(25)
|
allow(pango).to receive(:width).and_return(25)
|
||||||
allow(pango).to receive(:index_to_pos).and_return(Pango::Rectangle.new(0,0,0,0))
|
allow(pango).to receive(:index_to_pos).and_return(Pango::Rectangle.new(0, 0, 0, 0))
|
||||||
allow(pango).to receive(:extents).and_return([Pango::Rectangle.new(0,0,0,0)]*2)
|
allow(pango).to receive(:extents).and_return([Pango::Rectangle.new(0, 0, 0, 0)]*2)
|
||||||
allow(pango).to receive(:iter).and_return(iter)
|
allow(pango).to receive(:iter).and_return(iter)
|
||||||
allow(pango).to receive(:alignment).and_return(Pango::Layout::Alignment::LEFT)
|
allow(pango).to receive(:alignment).and_return(Pango::Layout::Alignment::LEFT)
|
||||||
allow(pango).to receive(:text).and_return("foo")
|
allow(pango).to receive(:text).and_return("foo")
|
||||||
allow(pango).to receive(:context).and_return(pango_cxt)
|
allow(pango).to receive(:context).and_return(pango_cxt)
|
||||||
allow(pango_cxt).to receive(:font_options=)
|
allow(pango_cxt).to receive(:font_options=)
|
||||||
allow(iter).to receive(:next_char!).and_return(false)
|
allow(iter).to receive(:next_char!).and_return(false)
|
||||||
allow(iter).to receive(:char_extents).and_return(Pango::Rectangle.new(5,5,5,5))
|
allow(iter).to receive(:char_extents).and_return(Pango::Rectangle.new(5, 5, 5, 5))
|
||||||
allow(iter).to receive(:index).and_return(1000)
|
allow(iter).to receive(:index).and_return(1000)
|
||||||
allow(Pango::FontDescription).to receive(:new).and_return(font)
|
allow(Pango::FontDescription).to receive(:new).and_return(font)
|
||||||
allow(Cairo::PDFSurface).to receive(:new).and_return(nil)
|
allow(Cairo::PDFSurface).to receive(:new).and_return(nil)
|
||||||
|
|
||||||
%w(save set_source_color paint restore translate rotate move_to
|
%w(save set_source_color paint restore translate rotate move_to
|
||||||
update_pango_layout width height show_pango_layout rounded_rectangle
|
update_pango_layout width height show_pango_layout rounded_rectangle
|
||||||
set_line_width stroke fill set_source scale render_rsvg_handle circle
|
set_line_width stroke fill set_source scale render_rsvg_handle circle
|
||||||
triangle line_to operator= show_page clip transform mask rectangle
|
triangle line_to operator= show_page clip transform mask rectangle
|
||||||
reset_clip antialias= curve_to matrix= pango_layout_path stroke_preserve
|
reset_clip antialias= curve_to matrix= pango_layout_path stroke_preserve
|
||||||
fill_preserve close_path set_dash set_line_cap set_line_join).each do |m|
|
fill_preserve close_path set_dash set_line_cap set_line_join).each do |m|
|
||||||
allow(cxt).to receive(m) { |*args| strio << scrub_hex("cairo: #{m}(#{args})\n") }
|
allow(cxt).to receive(m) { |*args| strio << scrub_hex("cairo: #{m}(#{args})\n") }
|
||||||
end
|
end
|
||||||
|
|
||||||
%w(font_description= text= width= height= wrap= ellipsize= alignment=
|
%w(font_description= text= width= height= wrap= ellipsize= alignment=
|
||||||
justify= spacing= markup= ellipsized?).each do |m|
|
justify= spacing= markup= ellipsized?).each do |m|
|
||||||
allow(pango).to receive(m) {|*args| strio << scrub_hex("pango: #{m}(#{args})\n") }
|
allow(pango).to receive(m) {|*args| strio << scrub_hex("pango: #{m}(#{args})\n") }
|
||||||
end
|
end
|
||||||
|
|
||||||
%w(size=).each do |m|
|
%w(size=).each do |m|
|
||||||
allow(font).to receive(m) { |*args| strio << scrub_hex("pango font: #{m}(#{args})\n") }
|
allow(font).to receive(m) { |*args| strio << scrub_hex("pango font: #{m}(#{args})\n") }
|
||||||
end
|
end
|
||||||
|
|
||||||
%w(write_to_png).each do |m|
|
%w(write_to_png).each do |m|
|
||||||
allow(surface).to receive(m) { |*args| strio << scrub_hex("surface: #{m}(#{args})\n") }
|
allow(surface).to receive(m) { |*args| strio << scrub_hex("surface: #{m}(#{args})\n") }
|
||||||
end
|
end
|
||||||
|
|
||||||
%w(next_char!).each do |m|
|
%w(next_char!).each do |m|
|
||||||
allow(iter).to receive(m) { |*args| strio << scrub_hex("pango_iter: #{m}(#{args})\n") }
|
allow(iter).to receive(m) { |*args| strio << scrub_hex("pango_iter: #{m}(#{args})\n") }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Refine Squib to allow setting the logger and progress bar
|
# Refine Squib to allow setting the logger and progress bar
|
||||||
module Squib
|
module Squib
|
||||||
def logger=(l)
|
def logger=(l)
|
||||||
@logger = l
|
@logger = l
|
||||||
end
|
end
|
||||||
module_function :logger=
|
module_function :logger=
|
||||||
|
|
||||||
class Deck
|
class Deck
|
||||||
attr_accessor :progress_bar
|
attr_accessor :progress_bar
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def output_dir
|
def output_dir
|
||||||
File.expand_path('../samples/_output', File.dirname(__FILE__))
|
File.expand_path('../samples/_output', File.dirname(__FILE__))
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue