diff --git a/CHANGELOG.md b/CHANGELOG.md index 357999f..0ff24eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ Features: * The `csv` method now supports all of the Ruby CSV options (e.g. `col_sep`, `quote_char`). These options simply get passed through to Ruby, so as they change in Ruby, so the support changes in Squib. (#149) Special thanks to Qgel's initial pull request (#146). * New `use_layout` method will allow you to load a layout file as a DSL method instead of in the constructor. Useful in conjunction with build groups! (#141) +Bugs: +* The `save_pdf` method will flush to file upon exit so that the PDF is available immediately. (#150, thanks for the bug report Qgel!) + Chores: * Switched to `require_relative` internally throughout the codebase to be more pry-friendly (#130) * Rewrote the entire API doc and placed it on [squib.readthedocs.org](http://squib.readthedocs.org). :tada: diff --git a/lib/squib/graphics/save_doc.rb b/lib/squib/graphics/save_doc.rb index 628922d..af82b3d 100644 --- a/lib/squib/graphics/save_doc.rb +++ b/lib/squib/graphics/save_doc.rb @@ -43,6 +43,7 @@ module Squib end end end + cc.target.finish end # :nodoc: diff --git a/spec/data/samples/custom_config.rb.txt b/spec/data/samples/custom_config.rb.txt index 46262a3..0cc07a6 100644 --- a/spec/data/samples/custom_config.rb.txt +++ b/spec/data/samples/custom_config.rb.txt @@ -55,3 +55,4 @@ cairo: set_source([MockDouble, 0, 0]) cairo: paint([]) cairo: reset_clip([]) cairo: translate([-75, -75]) +surface: finish([]) diff --git a/spec/data/samples/saves.rb.txt b/spec/data/samples/saves.rb.txt index 5c51e97..571d5a7 100644 --- a/spec/data/samples/saves.rb.txt +++ b/spec/data/samples/saves.rb.txt @@ -634,6 +634,7 @@ cairo: paint([]) cairo: reset_clip([]) cairo: translate([-2343, -1131]) cairo: show_page([]) +surface: finish([]) cairo: scale([0.24, 0.24]) cairo: translate([75, 75]) cairo: rectangle([0, 0, 825, 1125]) @@ -650,6 +651,7 @@ cairo: paint([]) cairo: reset_clip([]) cairo: translate([-900, -75]) cairo: show_page([]) +surface: finish([]) surface: write_to_png(["_output/saves_notrim_01.png"]) cairo: set_source([MockDouble, -37, -37]) cairo: paint([]) diff --git a/spec/graphics/graphics_save_doc_spec.rb b/spec/graphics/graphics_save_doc_spec.rb index bb0f793..38d0e5c 100644 --- a/spec/graphics/graphics_save_doc_spec.rb +++ b/spec/graphics/graphics_save_doc_spec.rb @@ -4,7 +4,8 @@ require 'squib' describe Squib::Deck, '#save_pdf' do context 'typical inputs' do - let(:cxt) { double(Cairo::Context) } + let(:cxt) { double(Cairo::Context) } + let(:target) { double(Cairo::PDFSurface) } def expect_card_place(x, y) expect(cxt).to receive(:translate).with(x, y).once @@ -41,6 +42,8 @@ describe Squib::Deck, '#save_pdf' do expect_card_place(2343, 1131) expect(cxt).to receive(:show_page).once expect_card_place(75, 75) + expect(cxt).to receive(:target).and_return(target) + expect(target).to receive(:finish).once args = { file: 'foo.pdf', dir: '_out', margin: 75, gap: 5, trim: 37 } deck.save_pdf(args) @@ -59,6 +62,9 @@ describe Squib::Deck, '#save_pdf' do expect_card_place(831, 75) expect_card_place(1587, 75) + expect(cxt).to receive(:target).and_return(target) + expect(target).to receive(:finish).once + deck.save_pdf(args) end diff --git a/spec/samples/samples_regression_spec.rb b/spec/samples/samples_regression_spec.rb index 4326074..e0f4c9d 100644 --- a/spec/samples/samples_regression_spec.rb +++ b/spec/samples/samples_regression_spec.rb @@ -3,7 +3,7 @@ require 'squib' require 'pp' describe 'Squib samples' do - + around(:each) do |example| Dir.chdir(samples_dir) do example.run diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5654e17..3dcfce1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -128,7 +128,7 @@ def mock_cairo(strio) allow(font).to receive(m) { |*args| strio << scrub_hex("pango font: #{m}(#{args})\n") } end - %w(write_to_png).each do |m| + %w(write_to_png finish).each do |m| allow(surface).to receive(m) { |*args| strio << scrub_hex("surface: #{m}(#{args})\n") } end