Skip to content

Commit

Permalink
Fix binary-id generator location in config/config.exs
Browse files Browse the repository at this point in the history
Previously the config for the phoenix generators was appended to the
file. This is technically not a problem, however the comment for the
`import_config "#{Mix.env}.exs" explicitly states that it should be at
the bottom of the file.

Before:

    # Import environment specific config. This must remain at the bottom
    # of this file so it overrides the configuration defined above.
    import_config "#{Mix.env}.exs"

    # Configure phoenix generators
    config :phoenix, :generators,
      binary_id: true

After:

    # Configure phoenix generators
    config :phoenix, :generators,
      binary_id: true

    # Import environment specific config. This must remain at the bottom
    # of this file so it overrides the configuration defined above.
    import_config "#{Mix.env}.exs"

The spacing in the template is deliberate to ensure there is only a
single space between the blocks.
  • Loading branch information
Gazler committed Jun 11, 2016
1 parent 0370571 commit f7bca54
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions installer/lib/phoenix_new.ex
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ defmodule Mix.Tasks.Phoenix.New do
:error -> adapter_config
end


generator_config =
case get_generator_config(adapter_config) do
[] -> nil
generator_config ->
"""
# Configure phoenix generators
config :phoenix, :generators#{kw_to_config(generator_config)}
"""
end

binding = [application_name: app,
application_module: mod,
phoenix_dep: phoenix_dep(phoenix_path),
Expand All @@ -214,6 +226,7 @@ defmodule Mix.Tasks.Phoenix.New do
adapter_module: adapter_module,
adapter_config: adapter_config,
hex?: Code.ensure_loaded?(Hex),
generator_config: generator_config,
namespaced?: Macro.camelize(app) != mod]

copy_from path, binding, @new
Expand Down Expand Up @@ -274,21 +287,10 @@ defmodule Mix.Tasks.Phoenix.New do
adapter: #{inspect binding[:adapter_module]}#{kw_to_config adapter_config[:prod]},
pool_size: 20
"""

case generator_config(adapter_config) do
[] ->
:ok
generator_config ->
append_to path, "config/config.exs", """
# Configure phoenix generators
config :phoenix, :generators#{kw_to_config(generator_config)}
"""
end
end
end

defp generator_config(adapter_config) do
defp get_generator_config(adapter_config) do
adapter_config
|> Keyword.take([:binary_id, :migration, :sample_binary_id])
|> Enum.filter(fn {_, value} -> not is_nil(value) end)
Expand Down
2 changes: 1 addition & 1 deletion installer/templates/new/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ config :<%= application_name %>, <%= application_module %>.Endpoint,
config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id]

<%= generator_config %>
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env}.exs"

0 comments on commit f7bca54

Please sign in to comment.