From b639f628621b041df307c08fc835f28b03144a18 Mon Sep 17 00:00:00 2001 From: crespire Date: Fri, 30 Dec 2022 23:03:28 -0500 Subject: [PATCH 1/5] feat: Add keep_temp flag --- lib/wicked_pdf.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/wicked_pdf.rb b/lib/wicked_pdf.rb index fc7a3811..d4c0d788 100644 --- a/lib/wicked_pdf.rb +++ b/lib/wicked_pdf.rb @@ -43,7 +43,8 @@ def pdf_from_string(string, options = {}) string_file.write_in_chunks(string) pdf_from_html_file(string_file.path, options) ensure - string_file.close if string_file + close_method = options.key?(:keep_temp) ? :close : :close! + string_file.send(close_method) end def pdf_from_url(url, options = {}) # rubocop:disable Metrics/CyclomaticComplexity From 22df87401ee77188dab719b03e3c506b8518cc97 Mon Sep 17 00:00:00 2001 From: crespire Date: Mon, 21 Aug 2023 20:44:07 -0400 Subject: [PATCH 2/5] Change option name and ensure block --- lib/wicked_pdf.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/wicked_pdf.rb b/lib/wicked_pdf.rb index d4c0d788..2f9d2097 100644 --- a/lib/wicked_pdf.rb +++ b/lib/wicked_pdf.rb @@ -43,8 +43,11 @@ def pdf_from_string(string, options = {}) string_file.write_in_chunks(string) pdf_from_html_file(string_file.path, options) ensure - close_method = options.key?(:keep_temp) ? :close : :close! - string_file.send(close_method) + if options[:delete_temporary_files] + string_file.close! + else + string_file.close + end end def pdf_from_url(url, options = {}) # rubocop:disable Metrics/CyclomaticComplexity From 0f29199afb728d4cf89723d1fb6c2027ec679782 Mon Sep 17 00:00:00 2001 From: crespire Date: Mon, 21 Aug 2023 20:46:59 -0400 Subject: [PATCH 3/5] Make sure string_file is not nil --- lib/wicked_pdf.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/wicked_pdf.rb b/lib/wicked_pdf.rb index 2f9d2097..15503275 100644 --- a/lib/wicked_pdf.rb +++ b/lib/wicked_pdf.rb @@ -43,9 +43,9 @@ def pdf_from_string(string, options = {}) string_file.write_in_chunks(string) pdf_from_html_file(string_file.path, options) ensure - if options[:delete_temporary_files] + if options[:delete_temporary_files] && string_file string_file.close! - else + elsif string_file string_file.close end end From 6aeac26ee7a76a51463e9d0265f3aa0365bc51b7 Mon Sep 17 00:00:00 2001 From: crespire Date: Tue, 22 Aug 2023 11:18:44 -0400 Subject: [PATCH 4/5] Update Readme to reference new option --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b2e794db..f5cf54ec 100644 --- a/README.md +++ b/README.md @@ -287,6 +287,9 @@ If you need to just create a pdf and not display it: # create a pdf from a string pdf = WickedPdf.new.pdf_from_string('

Hello There!

') +# create a pdf from a string using delete temporary files option +pdf = WickedPdf.new.pdf_from_string('

Delete temporary files

', delete_temporary_files: true) + # create a pdf file from a html file without converting it to string # Path must be absolute path pdf = WickedPdf.new.pdf_from_html_file('/your/absolute/path/here') @@ -294,14 +297,14 @@ pdf = WickedPdf.new.pdf_from_html_file('/your/absolute/path/here') # create a pdf from a URL pdf = WickedPdf.new.pdf_from_url('https://github.com/mileszs/wicked_pdf') -# create a pdf from string using templates, layouts and content option for header or footer +# create a pdf from string using templates, layouts, and content option for header or footer pdf = WickedPdf.new.pdf_from_string( render_to_string('templates/pdf', layout: 'pdfs/layout_pdf.html'), footer: { content: render_to_string( - 'templates/footer', - layout: 'pdfs/layout_pdf.html' - ) + 'templates/footer', + layout: 'pdfs/layout_pdf.html' + ) } ) From 511afae868313aed6e44bef42bcaef4a16e5d70f Mon Sep 17 00:00:00 2001 From: crespire Date: Tue, 22 Aug 2023 14:06:51 -0400 Subject: [PATCH 5/5] Move option documentation --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f5cf54ec..bed73f9b 100644 --- a/README.md +++ b/README.md @@ -259,7 +259,8 @@ class ThingsController < ApplicationController disable_toc_links: true, disable_back_links:true, xsl_style_sheet: 'file.xsl'}, # optional XSLT stylesheet to use for styling table of contents - progress: proc { |output| puts output } # proc called when console output changes + progress: proc { |output| puts output }, # proc called when console output changes + delete_temporary_files: true # explicitly delete temporary files, default false end end end @@ -287,9 +288,6 @@ If you need to just create a pdf and not display it: # create a pdf from a string pdf = WickedPdf.new.pdf_from_string('

Hello There!

') -# create a pdf from a string using delete temporary files option -pdf = WickedPdf.new.pdf_from_string('

Delete temporary files

', delete_temporary_files: true) - # create a pdf file from a html file without converting it to string # Path must be absolute path pdf = WickedPdf.new.pdf_from_html_file('/your/absolute/path/here')