Skip to content

Commit

Permalink
bump dependencies; version 0.3.6, minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gutschilla committed Aug 9, 2017
1 parent 7ed07a6 commit 2cdeb15
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 37 deletions.
8 changes: 4 additions & 4 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Changes

- 0.3.5
- add `generate_binray` and `generate_binary!` that immediately return the
- add `generate_binary` and `generate_binary!` that immediately return the
PDF binary instead of an `{:ok, filename}` tuple.
- add `generate!` to immediately return the filename
- some more tests
- minor change `delete_temporary` must be truthy. (the old supported value
`:html` will stil work) and will delete both intermediate HTML And PDF
files in ``generate_binary` and `generate_binary!`
`:html` will still work) and will delete both intermediate HTML And PDF
files in `generate_binary` and `generate_binary!`
- 0.3.4
- BUGFIX: fix merge confusion to **realy** support `xvfb-run` or other
- BUGFIX: fix merge confusion to **really** support `xvfb-run` or other
command prefixes to wkhtmltopdf
- support explicit deletion of temporary files thanks to
[Edipo Vinicius da Silva](https://github.com/edipox)
Expand Down
31 changes: 12 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,18 @@ A wrapper for wkhtmltopdf (HTML to PDF) and PDFTK (adds in encryption) for use
in Elixir projects. If available, it will use xvfb-run (x virtual frame buffer)
to use wkhtmltopdf on systems that have no X installed, e.g. a server.

# New in 0.3.4 and 0.3.5

- master
- improve REAMDE
- add option to pick output pdf filename
- 0.3.5
- add `generate_binary` and `generate_binary!` that immediately return the
PDF binary instead of an `{:ok, filename}` tuple.
- add `generate!` to immediately return the filename
- some more tests
- minor change `delete_temporary` must be truthy. (the old supported value
`:html` will still work) and will delete both intermediate HTML And PDF
files in `generate_binary` and `generate_binary!`
- 0.3.4
- BUGFIX: fix merge confusion to **really** support `xvfb-run` or other
command prefixes to wkhtmltopdf
- support explicit deletion of temporary files thanks to
[Edipo Vinicius da Silva](https://github.com/edipox)
- Improve README
# New in 0.3.6 - Custom filenames and maintenance

- 0.3.6
- bumped dependencies:
* porcelain 2.0.3 to support newer erlangs and remove warnings
* ex_doc 0.16 to remove warnings, remove from runtime
* removed explixit earmark
- add option to pick output pdf filename, thanks
to [praveenperera](https://github.com/praveenperera)
- improved README on heroku, corrected typpos. Thanks
to [jbhatab](https://github.com/jbhatab)
and [maggy96](https://github.com/maggy96)

For a proper changelog, see [CHANGES](CHANGES.md)

Expand Down
21 changes: 14 additions & 7 deletions lib/pdf_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ defmodule PdfGenerator do

def generate( html, options ) do
wkhtml_path = PdfGenerator.PathAgent.get.wkhtml_path
filebase = generate_filebase(options[:filename])
filebase = generate_filebase(options[:filename])
html_file = filebase <> ".html"
pdf_file = filebase <> ".pdf"
File.write html_file, html
Expand All @@ -127,15 +127,11 @@ defmodule PdfGenerator do

executable = wkhtml_path
arguments = List.flatten( [ shell_params, html_file, pdf_file ] )
command_prefix = Keyword.get( options, :command_prefix ) || Application.get_env( :pdf_generator, :command_prefix )
command_prefix = get_command_prefix( options )

# allow for xvfb-run wkhtmltopdf arg1 arg2
# or sudo wkhtmltopdf ...
{ executable, arguments } =
case command_prefix do
nil -> { executable, arguments }
cmd -> { cmd, [executable] ++ arguments }
end
{ executable, arguments } = make_command_tuple(command_prefix, executable, arguments)

%Result{ out: _output, status: status, err: error } = Porcelain.exec(
executable, arguments, [in: "", out: :string, err: :string]
Expand All @@ -157,6 +153,17 @@ defmodule PdfGenerator do
end
end

def get_command_prefix(options) do
Keyword.get( options, :command_prefix ) || Application.get_env( :pdf_generator, :command_prefix )
end

def make_command_tuple(_command_prefix = nil, wkhtml_executable, arguments) do
{ wkhtml_executable, arguments }
end
def make_command_tuple(command_prefix, wkhtml_executable, arguments) do
{ command_prefix, [wkhtml_executable] ++ arguments }
end

defp generate_filebase(nil), do: generate_filebase(Misc.Random.string)
defp generate_filebase(filename), do: Path.join(System.tmp_dir, filename)

Expand Down
7 changes: 3 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule PdfGenerator.Mixfile do
[
app: :pdf_generator,
name: "PDF Generator",
version: "0.3.5",
version: "0.3.6",
elixir: ">= 1.0.0",
deps: deps(),
description: description(),
Expand Down Expand Up @@ -46,12 +46,11 @@ defmodule PdfGenerator.Mixfile do
defp deps do
[
# communication with external programs
{:porcelain, "~> 2.0"},
{:porcelain, "~> 2.0.3"},
# a helper
{:misc_random, ">=0.2.6" },
# generate docs
{:earmark, "~> 0.1", only: :dev},
{:ex_doc, "~> 0.7", only: :dev}
{:ex_doc, "~> 0.16", only: :dev, runtime: false}
]
end
end
6 changes: 3 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%{"earmark": {:hex, :earmark, "0.1.19", "ffec54f520a11b711532c23d8a52b75a74c09697062d10613fa2dbdf8a9db36e", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.11.2", "8ac82c6144a27faca6a623eeebfbf5a791bc20a54ce29a9c02e499536d253d9b", [:mix], [{:earmark, "~> 0.1.17 or ~> 0.2", [hex: :earmark, optional: true]}]},
%{"earmark": {:hex, :earmark, "1.2.3", "206eb2e2ac1a794aa5256f3982de7a76bf4579ff91cb28d0e17ea2c9491e46a4", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.16.2", "3b3e210ebcd85a7c76b4e73f85c5640c011d2a0b2f06dcdf5acdb2ae904e5084", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]},
"misc_random": {:hex, :misc_random, "0.2.6", "959981142c96005731ed8b7df2440f5563a31c3a159edd5769fe28c77e3e0af7", [:mix], []},
"porcelain": {:hex, :porcelain, "2.0.1", "9c3db2b47d8cf6879c0d9ac79db8657333974a88faff09e856569e00c1b5e119", [:mix], []},
"porcelain": {:hex, :porcelain, "2.0.3", "2d77b17d1f21fed875b8c5ecba72a01533db2013bd2e5e62c6d286c029150fdc", [:mix], []},
"random": {:git, "https://github.com/gutschilla/elixir-helper-random.git", "fb801765651e8e6fa02866803592eade96b6c4d7", []},
"zarex": {:hex, :zarex, "0.3.0", "e19145de2127671f3d3f4bdb6bb60a0d70830836a01a79ba63428a5bbe3a16e0", [:mix], []}}

0 comments on commit 2cdeb15

Please sign in to comment.