Skip to content

Commit

Permalink
[gh315] Update - 2
Browse files Browse the repository at this point in the history
  • Loading branch information
andyduong1920 committed Mar 10, 2023
1 parent 91206ab commit f402949
Show file tree
Hide file tree
Showing 15 changed files with 478 additions and 476 deletions.
2 changes: 1 addition & 1 deletion lib/nimble_template/addons/variants/phoenix/api/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.Config do
# For production, don't forget to configure the url host
# to something meaningful, Phoenix uses this information
# when generating URLs.
#
# Note we also include the path to a cache manifest
# containing the digested version of static files. This
# manifest is generated by the `mix phx.digest` task,
Expand Down
76 changes: 40 additions & 36 deletions lib/nimble_template/addons/variants/phoenix/api/error_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,46 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.ErrorView do

@impl true
def do_apply!(%Project{} = project, _opts) do
project
|> delete_files!()
|> copy_files!()
end

defp delete_files!(%Project{web_path: web_path} = project) do
File.rm!("#{web_path}/views/error_helpers.ex")

project
end

defp copy_files!(
%Project{
base_module: base_module,
web_module: web_module,
web_path: web_path,
web_test_path: web_test_path
} = project
) do
binding = [
web_module: web_module,
base_module: base_module
]

files = [
{:eex, "lib/otp_app_web/views/error_helpers.ex.eex", "#{web_path}/views/error_helpers.ex"},
{:eex, "lib/otp_app_web/views/api/error_view.ex.eex", "#{web_path}/views/api/error_view.ex"},
{:eex, "test/otp_app_web/views/error_helpers_test.exs",
"#{web_test_path}/views/error_helpers_test.exs"},
{:eex, "test/otp_app_web/views/api/error_view_test.exs",
"#{web_test_path}/views/api/error_view_test.exs"},
{:eex, "test/support/view_case.ex.eex", "test/support/view_case.ex"}
]

Generator.copy_file!(files, binding)

# TODO: Revisit on the next PR
project
end
# def do_apply!(%Project{} = project, _opts) do
# project
# |> delete_files!()
# |> copy_files!()
# end

# defp delete_files!(%Project{web_path: web_path} = project) do
# File.rm!("#{web_path}/views/error_helpers.ex")

# project
# end

# defp copy_files!(
# %Project{
# base_module: base_module,
# web_module: web_module,
# web_path: web_path,
# web_test_path: web_test_path
# } = project
# ) do
# binding = [
# web_module: web_module,
# base_module: base_module
# ]

# files = [
# {:eex, "lib/otp_app_web/views/error_helpers.ex.eex", "#{web_path}/views/error_helpers.ex"},
# {:eex, "lib/otp_app_web/views/api/error_view.ex.eex", "#{web_path}/views/api/error_view.ex"},
# {:eex, "test/otp_app_web/views/error_helpers_test.exs",
# "#{web_test_path}/views/error_helpers_test.exs"},
# {:eex, "test/otp_app_web/views/api/error_view_test.exs",
# "#{web_test_path}/views/api/error_view_test.exs"},
# {:eex, "test/support/view_case.ex.eex", "test/support/view_case.ex"}
# ]

# Generator.copy_file!(files, binding)

# project
# end
end
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,26 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.FallbackController do
"""
def controller do
quote do
use Phoenix.Controller, namespace: #{web_module}
use Phoenix.Controller,
formats: [:html, :json],
layouts: [html: #{web_module}.Layouts]
import Plug.Conn
import #{web_module}.Gettext
alias #{web_module}.ParamsValidator
alias #{web_module}.Router.Helpers, as: Routes
""",
"""
def controller do
quote do
use Phoenix.Controller, namespace: #{web_module}
use Phoenix.Controller,
formats: [:html, :json],
layouts: [html: #{web_module}.Layouts]
import Plug.Conn
import #{web_module}.Gettext
alias #{web_module}.ParamsValidator
alias #{web_module}.Router.Helpers, as: Routes
action_fallback #{web_module}.Api.FallbackController
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.ParamsValidation do
"""
def controller do
quote do
use Phoenix.Controller, namespace: #{web_module}
use Phoenix.Controller,
formats: [:html, :json],
layouts: [html: #{web_module}.Layouts]
import Plug.Conn
import #{web_module}.Gettext
alias #{web_module}.Router.Helpers, as: Routes
""",
"""
def controller do
quote do
use Phoenix.Controller, namespace: #{web_module}
use Phoenix.Controller,
formats: [:html, :json],
layouts: [html: #{web_module}.Layouts]
import Plug.Conn
import #{web_module}.Gettext
alias #{web_module}.ParamsValidator
alias #{web_module}.Router.Helpers, as: Routes
"""
)

Expand Down
2 changes: 1 addition & 1 deletion lib/nimble_template/addons/variants/phoenix/oban.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Oban do
Generator.inject_content!(
"config/test.exs",
"""
config :logger, level: :warn
config :logger, level: :warning
""",
"""
Expand Down
Loading

0 comments on commit f402949

Please sign in to comment.