-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add ability to remove default args via config #314
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -147,15 +147,37 @@ defmodule ChromicPDF.ChromeRunner do | |||||
# https://github.com/bitcrowd/chromic_pdf/issues/76 | ||||||
defp args(extra, opts) do | ||||||
default_args() | ||||||
|> remove_conflicting_args(opts[:chrome_args]) | ||||||
|> append_if("--no-sandbox", no_sandbox?(opts)) | ||||||
|> append_if(to_string(opts[:chrome_args]), !!opts[:chrome_args]) | ||||||
|> append_chrome_args_if(opts[:chrome_args]) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the implementation could use another round of polishing :)
Suggested change
Maybe go for a unified handler function. 3 Clauses, remove = List.wrap(Keyword.get(extended, :remove, [])) |
||||||
|> Kernel.++(List.wrap(extra)) | ||||||
|> append_if("2>/dev/null 3<&0 4>&1", discard_stderr?(opts)) | ||||||
end | ||||||
|
||||||
defp append_if(list, _value, false), do: list | ||||||
defp append_if(list, value, true), do: list ++ [value] | ||||||
|
||||||
defp append_chrome_args_if(list, ""), do: list | ||||||
|
||||||
defp append_chrome_args_if(list, chrome_args) when is_binary(chrome_args) do | ||||||
append_if(list, chrome_args, true) | ||||||
end | ||||||
|
||||||
defp append_chrome_args_if(list, [{_, _} | _] = chrome_args) do | ||||||
append = Keyword.get(chrome_args, :append) | ||||||
|
||||||
append_if(list, append, !!append) | ||||||
end | ||||||
|
||||||
defp append_chrome_args_if(list, _), do: list | ||||||
|
||||||
defp no_sandbox?(opts), do: Keyword.get(opts, :no_sandbox, false) | ||||||
defp discard_stderr?(opts), do: Keyword.get(opts, :discard_stderr, true) | ||||||
|
||||||
defp remove_conflicting_args(defaults, [{_, _} | _] = chrome_args) do | ||||||
conflicting = Keyword.get(chrome_args, :remove, []) | ||||||
Enum.reject(defaults, &Enum.member?(conflicting, &1)) | ||||||
end | ||||||
|
||||||
defp remove_conflicting_args(defaults, _), do: defaults | ||||||
end |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -226,7 +226,7 @@ defmodule ChromicPDF.Supervisor do | |||||
@type local_chrome_option :: | ||||||
{:no_sandbox, boolean()} | ||||||
| {:discard_stderr, boolean()} | ||||||
| {:chrome_args, binary()} | ||||||
| {:chrome_args, binary() | map()} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. # above
@type extended_chrome_args :: [{:append, binary() | [binary()]} | {:remove, binary() | [binary()]}]
Suggested change
|
||||||
| {:chrome_executable, binary()} | ||||||
|
||||||
@typedoc """ | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be liberal in what the API can accept; a
List.wrap/1
somewhere will allow you to accept strings or lists for either of the options, and then we don't need this note in the docs.