Got all the specs passing!
parent
c227340323
commit
efe146e1e2
|
|
@ -4,17 +4,17 @@ module Squib
|
||||||
def save_pdf(opts = {})
|
def save_pdf(opts = {})
|
||||||
p = needs(opts, [:file_to_save, :prefix, :margin, :gap, :trim])
|
p = needs(opts, [:file_to_save, :prefix, :margin, :gap, :trim])
|
||||||
width = 11 * @dpi ; height = 8.5 * @dpi #TODO: allow this to be specified too
|
width = 11 * @dpi ; height = 8.5 * @dpi #TODO: allow this to be specified too
|
||||||
cc = Cairo::Context.new(Cairo::PDFSurface.new("#{dir}/#{file}", width, height))
|
cc = Cairo::Context.new(Cairo::PDFSurface.new("#{p[:dir]}/#{p[:file]}", width, height))
|
||||||
x = p[:margin] ; y = p[:margin]
|
x = p[:margin] ; y = p[:margin]
|
||||||
@cards.each_with_index do |card, i|
|
@cards.each_with_index do |card, i|
|
||||||
surface = trim(card.cairo_surface, p[:trim], @width, @height)
|
surface = trim(card.cairo_surface, p[:trim], @width, @height)
|
||||||
cc.set_source(surface, x, y)
|
cc.set_source(surface, x, y)
|
||||||
cc.paint
|
cc.paint
|
||||||
x += surface.width + gap
|
x += surface.width + p[:gap]
|
||||||
if x > (width - surface.width - margin)
|
if x > (width - surface.width - p[:margin])
|
||||||
x = p[:margin]
|
x = p[:margin]
|
||||||
y += surface.height + p[:gap]
|
y += surface.height + p[:gap]
|
||||||
if y > (height - surface.height - margin)
|
if y > (height - surface.height - p[:margin])
|
||||||
x = p[:margin] ; y = p[:margin]
|
x = p[:margin] ; y = p[:margin]
|
||||||
cc.show_page #next page
|
cc.show_page #next page
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ module Squib
|
||||||
opts[:file] = [opts[:file]] * @cards.size if expand_singletons
|
opts[:file] = [opts[:file]] * @cards.size if expand_singletons
|
||||||
files = [opts[:file]].flatten
|
files = [opts[:file]].flatten
|
||||||
files.each do |file|
|
files.each do |file|
|
||||||
unless File.exists? file || allow_non_exist
|
unless File.exists?(file) || allow_non_exist
|
||||||
raise "File #{File.expand_path(file)} does not exist!"
|
raise "File #{File.expand_path(file)} does not exist!"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -53,7 +53,6 @@ module Squib
|
||||||
module_function :fileify
|
module_function :fileify
|
||||||
|
|
||||||
def dirify(opts, allow_create=false)
|
def dirify(opts, allow_create=false)
|
||||||
puts opts[:dir]
|
|
||||||
return opts if Dir.exists?(opts[:dir])
|
return opts if Dir.exists?(opts[:dir])
|
||||||
if allow_create
|
if allow_create
|
||||||
Squib.logger.warn "Dir #{opts[:dir]} does not exist, creating it."
|
Squib.logger.warn "Dir #{opts[:dir]} does not exist, creating it."
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@ require 'squib'
|
||||||
|
|
||||||
describe Squib do
|
describe Squib do
|
||||||
|
|
||||||
# it "should execute all examples with no errors" do
|
it "should execute all examples with no errors" do
|
||||||
# samples = File.expand_path('../samples', File.dirname(__FILE__))
|
samples = File.expand_path('../samples', File.dirname(__FILE__))
|
||||||
# Dir["#{samples}/**/*.rb"].each do |sample|
|
Dir["#{samples}/**/*.rb"].each do |sample|
|
||||||
# Dir.chdir(samples) do #to save to _output
|
Dir.chdir(samples) do #to save to _output
|
||||||
# require_relative "../samples/#{File.basename(sample)}"
|
require_relative "../samples/#{File.basename(sample)}"
|
||||||
# end
|
end
|
||||||
# end
|
end
|
||||||
# end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
Loading…
Reference in New Issue