From dec0773bd2ba3cbf222598be2598e55918b8b85c Mon Sep 17 00:00:00 2001 From: Douglas Pouk Date: Tue, 13 Apr 2021 13:52:36 -0500 Subject: [PATCH 1/2] bug fix rail 5.2 --- CHANGELOG | 2 ++ lib/prawnto/template_handler/compile_support.rb | 5 +---- lib/prawnto/version.rb | 4 ++-- prawnto.gemspec | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 CHANGELOG diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..f79f74e --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,2 @@ +## 0.1.1 +* Fixed undefined Mime::PDF for Rails 5. diff --git a/lib/prawnto/template_handler/compile_support.rb b/lib/prawnto/template_handler/compile_support.rb index 1a01660..e4c103a 100644 --- a/lib/prawnto/template_handler/compile_support.rb +++ b/lib/prawnto/template_handler/compile_support.rb @@ -52,7 +52,7 @@ def set_cache_control end def set_content_type - @controller.response.content_type ||= Mime::PDF + @controller.response.content_type ||= Mime::EXTENSION_LOOKUP['pdf'] end def set_disposition @@ -65,6 +65,3 @@ def set_disposition end end - - - diff --git a/lib/prawnto/version.rb b/lib/prawnto/version.rb index e7e2523..23c8952 100644 --- a/lib/prawnto/version.rb +++ b/lib/prawnto/version.rb @@ -1,3 +1,3 @@ module Prawnto - VERSION = '0.1.1' -end \ No newline at end of file + VERSION = '0.1.2' +end diff --git a/prawnto.gemspec b/prawnto.gemspec index 7c7ca65..2c4cc01 100644 --- a/prawnto.gemspec +++ b/prawnto.gemspec @@ -21,5 +21,5 @@ Gem::Specification.new do |s| # specify any dependencies here; for example: # s.add_development_dependency "rspec" s.add_runtime_dependency "prawn" - s.add_runtime_dependency 'rails', '>=2.1' + s.add_runtime_dependency 'rails', '>=5.0' end From 2b8f62480ec6944fa2e08ba88afd09fdce0a8ad3 Mon Sep 17 00:00:00 2001 From: Douglas Pouk Date: Thu, 12 Dec 2024 14:54:06 -0600 Subject: [PATCH 2/2] 0.1.3 fix local PDF instance --- CHANGELOG | 4 +++- lib/prawnto/template_handlers/base.rb | 10 +++++++--- lib/prawnto/version.rb | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f79f74e..3a69455 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,2 +1,4 @@ +## 0.1.3 +* Make PDF document persistent across the view rendering process - fixes layout and partials using separate 'pdf' local instance ## 0.1.1 -* Fixed undefined Mime::PDF for Rails 5. +* Fixed undefined Mime::PDF for Rails 5. diff --git a/lib/prawnto/template_handlers/base.rb b/lib/prawnto/template_handlers/base.rb index b8145dc..c2949a4 100644 --- a/lib/prawnto/template_handlers/base.rb +++ b/lib/prawnto/template_handlers/base.rb @@ -6,8 +6,14 @@ class Base < (base_class_for_template_handler_required? ? ::ActionView::Template include ::ActionView::TemplateHandlers::Compilable if template_should_include_compilable? def self.call(template) + ## + # DVB + # Let's make the prawn pdf document persistent across layouts + # and partials through an instance variable + "@pdf ||= Prawn::Document.new(@prawnto_options[:prawn]);" + "_prawnto_compile_setup;" + - "pdf = Prawn::Document.new(@prawnto_options[:prawn]);" + + # "pdf = Prawn::Document.new(@prawnto_options[:prawn]);" + + "pdf = @pdf;" + "#{template.source}\n" + "pdf.render;" end @@ -20,5 +26,3 @@ def compile(template) end end end - - diff --git a/lib/prawnto/version.rb b/lib/prawnto/version.rb index 23c8952..e9a54bf 100644 --- a/lib/prawnto/version.rb +++ b/lib/prawnto/version.rb @@ -1,3 +1,3 @@ module Prawnto - VERSION = '0.1.2' + VERSION = '0.1.3' end