From 2873a9a028b00e286b89460461c00b1b474d87e7 Mon Sep 17 00:00:00 2001 From: Tobias Maier Date: Sun, 30 Dec 2012 11:46:51 +0100 Subject: [PATCH] Add handling of format change at multi page pdf File variable can be "filename-*.ext". So later following image manipulations will affect all layers. --- lib/image_sorcery.rb | 4 ++++ spec/image_sorcery_examples_spec.rb | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/image_sorcery.rb b/lib/image_sorcery.rb index aef1683..88e5f38 100644 --- a/lib/image_sorcery.rb +++ b/lib/image_sorcery.rb @@ -91,6 +91,10 @@ def replace_file(format) File.delete @file @file = File.join File.dirname(@file), File.basename(@file, File.extname(@file)) + "." + format @filename_changed = true + + unless File.exists? @file + @file = File.join File.dirname(@file), File.basename(@file, File.extname(@file)) + "-*." + format + end end def convert_to_command(tokens) diff --git a/spec/image_sorcery_examples_spec.rb b/spec/image_sorcery_examples_spec.rb index cd0f8ce..7760337 100644 --- a/spec/image_sorcery_examples_spec.rb +++ b/spec/image_sorcery_examples_spec.rb @@ -61,12 +61,22 @@ end it "should create file with new extension" do - File.exists?("./spec/fixtures/pdf-sample-2.png").should be_true + + case new_instance_method + when "new" + File.exists?("./spec/fixtures/pdf-sample-2-0.png").should be_true + File.exists?("./spec/fixtures/pdf-sample-2-1.png").should be_true + when "gm" + File.exists?("./spec/fixtures/pdf-sample-2.png").should be_true + end end its(:identify) { should include "PNG 595x842" } its(:filename_changed?) { should be_true } + + its(:file) { should eq "./spec/fixtures/pdf-sample-2.png" } if new_instance_method == "gm" + its(:file) { should eq "./spec/fixtures/pdf-sample-2-*.png" } if new_instance_method == "new" end end end