Skip to content

Commit

Permalink
Merge pull request #1068 from crespire/feat/keep_temp_flag
Browse files Browse the repository at this point in the history
feat: Add :delete_temporary_files flag
  • Loading branch information
unixmonkey authored Aug 23, 2023
2 parents 3b99205 + 511afae commit 6b3b90f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -294,14 +295,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'
)
}
)

Expand Down
6 changes: 5 additions & 1 deletion lib/wicked_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ 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
if options[:delete_temporary_files] && string_file
string_file.close!
elsif string_file
string_file.close
end
end

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

0 comments on commit 6b3b90f

Please sign in to comment.