Repository: phoenixframework/phoenix
Pull request #3062 (2018-09-17 13:43:52)

Only use css-loader syntax when generate with Webpack
This fixes "no route found for GET /css/phoenix.css" from phoenix
installed with --no-webpack option. Use `:append` from the generator
instead of css-loader for static template generation.

This is the improvement of https://github.com/phoenixframework/phoenix/pull/2779 so it could go with version 1.4.


Patch:
diff --git a/guides/errors.md b/guides/errors.md
index fb5536ec3..e44a9e7a9 100644
--- a/guides/errors.md
+++ b/guides/errors.md
@@ -2,7 +2,7 @@
 
 Phoenix provides an `ErrorView`, `lib/hello_web/views/error_view.ex`, to render errors in our applications. The full module name will include the name of our application, as in `Hello.ErrorView`.
 
-Phoenix will detect any 400 or 500 status level errors in our application and use the `render/2` function in our `ErrorView` to render an appropriate error template. Any errors which don't match an existing clause of `render/2` will be caught by `template_not_found/2`.
+Phoenix will detect any 400 or 500 status level errors in our application and use the `render/2` function in our `ErrorView` to render an appropriate error template. We get default implementations for 404 and 500 HTML errors, but we can add any clauses to `render/2` that we might need. Any errors which don't match an existing clause of `render/2` will be caught by `template_not_found/2`.
 
 We can also customize the implementation of any of these functions however we like.
 
@@ -12,17 +12,18 @@ Here's what the `ErrorView` looks like.
 defmodule Hello.ErrorView do
   use Hello.Web, :view
 
-  # If you want to customize a particular status code
-  # for a certain format, you may uncomment below.
-  # def render("500.html", _assigns) do
-  #   "Internal Server Error"
-  # end
-
-  # By default, Phoenix returns the status message from
-  # the template name. For example, "404.html" becomes
-  # "Not Found".
-  def template_not_found(template, _assigns) do
-    Phoenix.Controller.status_message_from_template(template)
+  def render("404.html", _assigns) do
+    "Page not found"
+  end
+
+  def render("500.html", _assigns) do
+    "Server internal error"
+  end
+
+  # In case no render clause matches or no
+  # template is found, let's render it as 500
+  def template_not_found(_template, assigns) do
+    render("500.html", assigns)
   end
 end
 ```
diff --git a/installer/lib/phx_new/single.ex b/installer/lib/phx_new/single.ex
index edf3a7d09..a79b4240d 100644
--- a/installer/lib/phx_new/single.ex
+++ b/installer/lib/phx_new/single.ex
@@ -68,10 +68,10 @@ defmodule Phx.New.Single do
   template :bare, []
 
   template :static, [
-    {:text,   "phx_assets/app.css",        :project, "priv/static/css/app.css"},
-    {:append, "phx_assets/phoenix.css",    :project, "priv/static/css/app.css"},
-    {:text,   "phx_assets/bare/app.js",    :project, "priv/static/js/app.js"},
-    {:text,   "phx_assets/robots.txt",     :project, "priv/static/robots.txt"},
+    {:text, "phx_assets/app.css",     :project, "priv/static/css/app.css"},
+    {:text, "phx_assets/phoenix.css", :project, "priv/static/css/phoenix.css"},
+    {:text, "phx_assets/bare/app.js", :project, "priv/static/js/app.js"},
+    {:text, "phx_assets/robots.txt",  :project, "priv/static/robots.txt"},
   ]
 
   def prepare_project(%Project{app: app} = project) when not is_nil(app) do
diff --git a/installer/lib/phx_new/web.ex b/installer/lib/phx_new/web.ex
index 71c690e75..26c8c21b2 100644
--- a/installer/lib/phx_new/web.ex
+++ b/installer/lib/phx_new/web.ex
@@ -63,10 +63,10 @@ defmodule Phx.New.Web do
   template :bare, []
 
   template :static, [
-    {:text,   "phx_assets/app.css",        :web, "priv/static/css/app.css"},
-    {:append, "phx_assets/phoenix.css",    :web, "priv/static/css/app.css"},
-    {:text,   "phx_assets/bare/app.js",    :web, "priv/static/js/app.js"},
-    {:text,   "phx_assets/robots.txt",     :web, "priv/static/robots.txt"},
+    {:text, "phx_assets/app.css",     :web, "priv/static/css/app.css"},
+    {:text, "phx_assets/phoenix.css", :web, "priv/static/css/phoenix.css"},
+    {:text, "phx_assets/bare/app.js", :web, "priv/static/js/app.js"},
+    {:text, "phx_assets/robots.txt",  :web, "priv/static/robots.txt"},
   ]
 
   def prepare_project(%Project{app: app} = project) when not is_nil(app) do
diff --git a/installer/templates/phx_web/endpoint.ex b/installer/templates/phx_web/endpoint.ex
index f0bb92ff7..7fbf42447 100644
--- a/installer/templates/phx_web/endpoint.ex
+++ b/installer/templates/phx_web/endpoint.ex
@@ -7,7 +7,7 @@ defmodule <%= endpoint_module %> do
 
   # Serve at "/" the static files from "priv/static" directory.
   #
-  # You should set gzip to true if you are running phx.digest
+  # You should set gzip to true if you are running phoenix.digest
   # when deploying your static files in production.
   plug Plug.Static,
     at: "/", from: :<%= web_app_name %>, gzip: false,


Test patch:
diff --git a/installer/test/phx_new_test.exs b/installer/test/phx_new_test.exs
index 0f163c446..de14d6628 100644
--- a/installer/test/phx_new_test.exs
+++ b/installer/test/phx_new_test.exs
@@ -93,6 +93,7 @@ defmodule Mix.Tasks.Phx.NewTest do
       assert_file "phx_blog/assets/static/favicon.ico"
       assert_file "phx_blog/assets/static/images/phoenix.png"
       assert_file "phx_blog/assets/css/app.css"
+      assert_file "phx_blog/assets/css/phoenix.css"
       assert_file "phx_blog/assets/js/app.js",
                   ~s[import socket from "./socket"]
       assert_file "phx_blog/assets/js/socket.js",
@@ -104,6 +105,7 @@ defmodule Mix.Tasks.Phx.NewTest do
       end
 
       refute File.exists? "phx_blog/priv/static/css/app.css"
+      refute File.exists? "phx_blog/priv/static/css/phoenix.css"
       refute File.exists? "phx_blog/priv/static/js/phoenix.js"
       refute File.exists? "phx_blog/priv/static/js/app.js"
 
@@ -160,6 +162,7 @@ defmodule Mix.Tasks.Phx.NewTest do
 
       # No webpack & No HTML
       refute_file "phx_blog/priv/static/css/app.css"
+      refute_file "phx_blog/priv/static/css/phoenix.css"
       refute_file "phx_blog/priv/static/favicon.ico"
       refute_file "phx_blog/priv/static/images/phoenix.png"
       refute_file "phx_blog/priv/static/js/phoenix.js"
@@ -218,6 +221,7 @@ defmodule Mix.Tasks.Phx.NewTest do
       assert_file "phx_blog/.gitignore"
       assert_file "phx_blog/.gitignore", ~r/\n$/
       assert_file "phx_blog/priv/static/css/app.css"
+      assert_file "phx_blog/priv/static/css/phoenix.css"
       assert_file "phx_blog/priv/static/favicon.ico"
       assert_file "phx_blog/priv/static/images/phoenix.png"
       assert_file "phx_blog/priv/static/js/phoenix.js"
diff --git a/installer/test/phx_new_umbrella_test.exs b/installer/test/phx_new_umbrella_test.exs
index 8a8db80a5..cab25f772 100644
--- a/installer/test/phx_new_umbrella_test.exs
+++ b/installer/test/phx_new_umbrella_test.exs
@@ -126,6 +126,7 @@ defmodule Mix.Tasks.Phx.New.UmbrellaTest do
       assert_file web_path(@app, "assets/static/favicon.ico")
       assert_file web_path(@app, "assets/static/images/phoenix.png")
       assert_file web_path(@app, "assets/css/app.css")
+      assert_file web_path(@app, "assets/css/phoenix.css")
       assert_file web_path(@app, "assets/js/app.js"),
                   ~s[import socket from "./socket"]
       assert_file web_path(@app, "assets/js/socket.js"),
@@ -137,6 +138,7 @@ defmodule Mix.Tasks.Phx.New.UmbrellaTest do
       end
 
       refute File.exists?(web_path(@app, "priv/static/css/app.css"))
+      refute File.exists?(web_path(@app, "priv/static/css/phoenix.css"))
       refute File.exists?(web_path(@app, "priv/static/js/phoenix.js"))
       refute File.exists?(web_path(@app, "priv/static/js/app.js"))
 
@@ -205,6 +207,7 @@ defmodule Mix.Tasks.Phx.New.UmbrellaTest do
 
       # No webpack & No HTML
       refute_file web_path(@app, "priv/static/css/app.css")
+      refute_file web_path(@app, "priv/static/css/phoenix.css")
       refute_file web_path(@app, "priv/static/favicon.ico")
       refute_file web_path(@app, "priv/static/images/phoenix.png")
       refute_file web_path(@app, "priv/static/js/phoenix.js")
@@ -264,6 +267,7 @@ defmodule Mix.Tasks.Phx.New.UmbrellaTest do
       assert_file web_path(@app, ".gitignore")
       assert_file( web_path(@app, ".gitignore"),  ~r/\n$/)
       assert_file web_path(@app, "priv/static/css/app.css")
+      assert_file web_path(@app, "priv/static/css/phoenix.css")
       assert_file web_path(@app, "priv/static/favicon.ico")
       assert_file web_path(@app, "priv/static/images/phoenix.png")
       assert_file web_path(@app, "priv/static/js/phoenix.js")
@@ -497,6 +501,7 @@ defmodule Mix.Tasks.Phx.New.UmbrellaTest do
         assert_file "another/assets/static/favicon.ico"
         assert_file "another/assets/static/images/phoenix.png"
         assert_file "another/assets/css/app.css"
+        assert_file "another/assets/css/phoenix.css"
         assert_file "another/assets/js/app.js",
                     ~s[import socket from "./socket"]
         assert_file "another/assets/js/socket.js",
@@ -508,6 +513,7 @@ defmodule Mix.Tasks.Phx.New.UmbrellaTest do
         end
 
         refute File.exists? "another/priv/static/css/app.css"
+        refute File.exists? "another/priv/static/css/phoenix.css"
         refute File.exists? "another/priv/static/js/phoenix.js"
         refute File.exists? "another/priv/static/js/app.js"