Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pdf_generator.ex #8

Merged
merged 3 commits into from
Aug 10, 2016
Merged

Update pdf_generator.ex #8

merged 3 commits into from
Aug 10, 2016

Conversation

edipox
Copy link
Contributor

@edipox edipox commented Jul 16, 2016

Add html_file to the returned value.

Use case: someone wants to remove the html temporary file

Add html_file to the returned value. 

Use case: someone wants to remove the html temporary file
@gutschilla
Copy link
Owner

@edipox Thanks for your PR! Usually one shouldn't care about temporary files (your OS should do) so explicit deleting isn't usually necessary.

On the other hand there's no real reason not to be able to delete that file but I'd rather see an option to the call than changing it's return value signature from a 2-element tuple to a 3-element tuple as this would surely break someone's code (at least mine) when pattern-matching the result of generate as in

{:ok, file} = PdfGenerator.generate(...)

So I'd rather suggest an option delete_temporay: :html that does just that.

Tell what you think

@edipox
Copy link
Contributor Author

edipox commented Jul 19, 2016

Yeah, you are totally right. I didn't think about code breaking issues.

This is my situation: pdf generation per concurrent request. So I can't let the OS delete the files, because it could be too late and the disk space could end. And I can't delete all the .html files after each request because another request could be reading a file while I am deleting it.
But your suggestion will work perfectly!
Thank you

@edipox
Copy link
Contributor Author

edipox commented Jul 28, 2016

@gutschilla I did what you suggested. Could you take a look?

@@ -133,6 +135,11 @@ defmodule PdfGenerator do
executable, arguments, [in: "", out: :string, err: :string]
)

case Keyword.get(options, :delete_temporary) do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could be rewritten as

if Keyword.get(options, :delete_temporary) == :html do
   File.rm html_file
end

In my opinion, no need for a nil -> nil case

@gutschilla
Copy link
Owner

Thanks a lot for your patch and thanks as well for removing all these spaces at line endings. Would you please take a look at my small-ish line comment?

@edipox
Copy link
Contributor Author

edipox commented Aug 9, 2016

@gutschilla Done!
The end line spaces were removed by this Atom package: https://github.com/atom/whitespace each time you save a file the package remove spaces at line endings automatically

@gutschilla
Copy link
Owner

Beautiful! Thanks a lot for your contribution!

@gutschilla gutschilla merged commit f7412c9 into gutschilla:master Aug 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants