Skip to content

Commit

Permalink
Merge pull request #152 from mojotech/cpj/phx1_5_support
Browse files Browse the repository at this point in the history
Official support for Phoenix 1.5
  • Loading branch information
cpjolicoeur committed Apr 24, 2020
2 parents 9b6babc + 5f399a5 commit e6c5e87
Show file tree
Hide file tree
Showing 157 changed files with 23,938 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .credo.exs
Expand Up @@ -21,7 +21,7 @@
# You can give explicit globs or simply directories.
# In the latter case `**/*.{ex,exs}` will be used.
#
included: ["lib/", "src/", "test/", "web/", "apps/"],
included: ["lib/", "src/", "test/mix/", "test/torch", "web/", "apps/"],
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
},
#
Expand Down
14 changes: 12 additions & 2 deletions bin/test
Expand Up @@ -5,6 +5,8 @@ MIX_ENV=test mix credo --strict --ignore design,consistency || { echo 'Elixir co
MIX_ENV=test mix docs || { echo 'Elixir HTML docs were not generated!'; exit 1; }
MIX_ENV=test mix test || { echo 'Elixir tests on Torch failed!'; exit 1; }

TEST_ROOT="$(pwd)/test"

if [ $CI ]; then
if [ $TRAVIS ]; then
echo "----------------------------------------------------------"
Expand All @@ -20,6 +22,14 @@ if [ $CI ]; then
fi

# Run integration tests
cd test/support/apps/example && {
bin/test || { echo 'Integration tests on regular Phoenix project failed!'; exit 1; }
cd "$TEST_ROOT/support/apps/phx1_3" && {
bin/test || { echo 'Integration tests on regular Phoenix 1.3 project failed!'; exit 1; }
}

cd "$TEST_ROOT/support/apps/phx1_4" && {
bin/test || { echo 'Integration tests on regular Phoenix 1.4 project failed!'; exit 1; }
}

cd "$TEST_ROOT/support/apps/phx1_5" && {
bin/test || { echo 'Integration tests on regular Phoenix 1.5 project failed!'; exit 1; }
}
29 changes: 28 additions & 1 deletion lib/mix/tasks/torch.install.ex
Expand Up @@ -27,8 +27,35 @@ defmodule Mix.Tasks.Torch.Install do

%{format: format, otp_app: otp_app} = Mix.Torch.parse_config!("torch.install", args)

case Application.load(:phoenix) do
:ok ->
:ok

{:error, {:already_loaded, :phoenix}} ->
:ok

{:error, reason} ->
Mix.raise(
"mix torch.install could not complete due to Phoenix not being loaded: #{reason}"
)
end

phoenix_version = Application.spec(:phoenix, :vsn)

Mix.Torch.copy_from("priv/templates/#{format}", [
{"layout.html.#{format}", "lib/#{otp_app}_web/templates/layout/torch.html.#{format}"}
{template_file(phoenix_version, format),
"lib/#{otp_app}_web/templates/layout/torch.html.#{format}"}
])
end

defp template_file(phoenix_version, format) when is_list(phoenix_version),
do: phoenix_version |> to_string() |> template_file(format)

defp template_file(phoenix_version, format) when is_binary(phoenix_version) do
if Version.match?(phoenix_version, ">= 1.5.0") do
"layout.phx1_5.html.#{format}"
else
"layout.html.#{format}"
end
end
end
2 changes: 1 addition & 1 deletion mix.exs
Expand Up @@ -40,7 +40,7 @@ defmodule Torch.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:phoenix, ">= 1.3.0 and < 1.5.0"},
{:phoenix, ">= 1.3.0 and < 1.6.0"},
{:phoenix_html, "~> 2.10"},
{:gettext, "~> 0.16"},
{:scrivener_ecto, ">= 1.2.1"},
Expand Down
37 changes: 37 additions & 0 deletions priv/templates/eex/layout.phx1_5.html.eex
@@ -0,0 +1,37 @@
<html>
<head>
<title>Admin</title>
<!-- Uncomment to just use the bare bones torch styles rather than the theme -->
<!--<link rel="stylesheet" href="<%= Routes.static_path(@conn, "/torch/base.css") %>">-->
<link rel="stylesheet" href="<%= Routes.static_path(@conn, "/torch/theme.css") %>">
</head>

<body class="<%= Torch.PageView.body_classes(@conn) %>">
<header>
<section id="torch-account-info">
<div class="torch-container">
<a href="/">user@example.com</a>
<a href="/">Logout</a>
</div>
</section>

<section id="torch-nav">
<div class="torch-container">
<div class="torch-logo">
<a href="/">
<h3>Torch</h3>
</a>
</div>
<nav class="torch-nav">
<!-- nav links here -->
</nav>
</div>
</section>
</header>

<%= Torch.FlashView.render("_flash_messages.html", assigns) %>
<%= @inner_content %>
<script src="<%= Routes.static_path(@conn, "/torch/torch.js") %>"></script>
</body>
</html>

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -4,7 +4,7 @@ mix deps.get || { echo 'Dependencies could not be fetched!'; exit 1; }
MIX_ENV=test mix ecto.drop || { echo 'Database could not be dropped'; exit 1; }
MIX_ENV=test mix torch.install || { echo 'Torch could not be installed!'; exit 1; }
MIX_ENV=test mix torch.gen.html Blog Post posts title:string published:boolean published_at:datetime views:integer || { echo 'Torch files not generated!'; exit 1; }
cp ../../routers/modified.ex lib/example_web/router.ex
cp ../../routers/phx1_3_modified.ex lib/example_web/router.ex
mix test || { echo 'Tests failed!'; exit 1; }

# Clean up generated files
Expand All @@ -17,7 +17,7 @@ rm -rf lib/example_web/templates/layout/torch.html.eex
rm -rf lib/example_web/templates/post/
rm -rf lib/example_web/views/post_view.ex
rm -rf test/example_web/controllers/post_controller_test.exs
cp ../../routers/original.ex lib/example_web/router.ex
cp ../../routers/phx1_3_original.ex lib/example_web/router.ex

echo 'Tests succeeded!'
exit 0
exit 0
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -13,7 +13,6 @@ config :logger, level: :warn
{whoami, _} = System.cmd("whoami", [])
whoami = String.replace(whoami, "\n", "")

# Configure your database
config :example, Example.Repo,
adapter: Ecto.Adapters.Postgres,
username: System.get_env("DATABASE_POSTGRESQL_USERNAME") || whoami,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit e6c5e87

Please sign in to comment.