diff --git a/Gemfile.lock b/Gemfile.lock index f53e996..af661ec 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,9 +8,20 @@ PATH GEM remote: https://rubygems.org/ specs: + Ascii85 (1.1.0) + afm (0.2.2) diff-lcs (1.5.1) + hashery (2.1.2) matrix (0.4.2) pdf-core (0.9.0) + pdf-inspector (1.3.0) + pdf-reader (>= 1.0, < 3.0.a) + pdf-reader (2.12.0) + Ascii85 (~> 1.0) + afm (~> 0.2.1) + hashery (~> 2.0) + ruby-rc4 + ttfunk prawn (2.4.0) pdf-core (~> 0.9.0) ttfunk (~> 1.7) @@ -28,6 +39,7 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-support (3.13.0) + ruby-rc4 (0.1.5) ttfunk (1.7.0) PLATFORMS @@ -35,6 +47,7 @@ PLATFORMS ruby DEPENDENCIES + pdf-inspector (~> 1.0) phlex-pdf! rake (~> 13.0) rspec (~> 3.0) diff --git a/lib/phlex/pdf.rb b/lib/phlex/pdf.rb index 9284cec..dff299b 100644 --- a/lib/phlex/pdf.rb +++ b/lib/phlex/pdf.rb @@ -10,7 +10,7 @@ class PDF def document = @document - def call(document = self.class.blank, &block) + def call(document, &block) @document = document around_template do if block_given? @@ -45,8 +45,7 @@ def after_template end def to_pdf(...) - call - @document.render(...) + self.class.blank.tap{ |doc| call doc }.render(...) end def yield_content(&block) diff --git a/phlex-pdf.gemspec b/phlex-pdf.gemspec index 078c4d4..05d0448 100644 --- a/phlex-pdf.gemspec +++ b/phlex-pdf.gemspec @@ -36,6 +36,8 @@ Gem::Specification.new do |spec| spec.add_dependency "prawn", "~> 2.0" spec.add_dependency "matrix", "~> 0.4" + spec.add_development_dependency("pdf-inspector", "~> 1.0") + # For more information and examples about making a new gem, check out our # guide at: https://bundler.io/guides/creating_gem.html end diff --git a/spec/phlex/pdf_spec.rb b/spec/phlex/pdf_spec.rb index 928c222..a6d1804 100644 --- a/spec/phlex/pdf_spec.rb +++ b/spec/phlex/pdf_spec.rb @@ -87,7 +87,18 @@ def view_template end RSpec.describe Phlex::PDF do + let(:pages) do + PDF::Inspector::Page.analyze(PDFDocument.new.to_pdf).pages + end + it "generates a PDF" do - PDFDocument.new.to_pdf + expect(pages.size).to eq(3) + expect(pages[0][:strings]).to include("Hi", "There") + expect(pages[1][:strings]).to include("Friendly", "Pal") + expect(pages[2][:strings]).to include("Whats", "Up") + + pages.each do |page| + expect(page[:strings]).to include("Header", "Rendered from Proc.new", "Rendered from proc", "Rendered from lambda", "Rendered from ->", "Rendered from Method", "Rendered from lambda", "Rendered from ->", "Rendered from Method", "Hello Brad", "Danger!", "Don't Panic!") + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 135a94f..c457671 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "phlex/pdf" +require "pdf/inspector" RSpec.configure do |config| # Enable flags like --only-failures and --next-failure