Skip to content

Commit 6b3b90f

Browse files
authored
Merge pull request #1068 from crespire/feat/keep_temp_flag
feat: Add :delete_temporary_files flag
2 parents 3b99205 + 511afae commit 6b3b90f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

README.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ class ThingsController < ApplicationController
259259
disable_toc_links: true,
260260
disable_back_links:true,
261261
xsl_style_sheet: 'file.xsl'}, # optional XSLT stylesheet to use for styling table of contents
262-
progress: proc { |output| puts output } # proc called when console output changes
262+
progress: proc { |output| puts output }, # proc called when console output changes
263+
delete_temporary_files: true # explicitly delete temporary files, default false
263264
end
264265
end
265266
end
@@ -294,14 +295,14 @@ pdf = WickedPdf.new.pdf_from_html_file('/your/absolute/path/here')
294295
# create a pdf from a URL
295296
pdf = WickedPdf.new.pdf_from_url('https://github.com/mileszs/wicked_pdf')
296297

297-
# create a pdf from string using templates, layouts and content option for header or footer
298+
# create a pdf from string using templates, layouts, and content option for header or footer
298299
pdf = WickedPdf.new.pdf_from_string(
299300
render_to_string('templates/pdf', layout: 'pdfs/layout_pdf.html'),
300301
footer: {
301302
content: render_to_string(
302-
'templates/footer',
303-
layout: 'pdfs/layout_pdf.html'
304-
)
303+
'templates/footer',
304+
layout: 'pdfs/layout_pdf.html'
305+
)
305306
}
306307
)
307308

lib/wicked_pdf.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ def pdf_from_string(string, options = {})
4343
string_file.write_in_chunks(string)
4444
pdf_from_html_file(string_file.path, options)
4545
ensure
46-
string_file.close if string_file
46+
if options[:delete_temporary_files] && string_file
47+
string_file.close!
48+
elsif string_file
49+
string_file.close
50+
end
4751
end
4852

4953
def pdf_from_url(url, options = {}) # rubocop:disable Metrics/CyclomaticComplexity

0 commit comments

Comments
 (0)