Repository: phoenixframework/phoenix
Pull request #3164 (2018-11-14 15:25:36)

Guides updates for Phoenix 1.4


Patch:
diff --git a/guides/adding_pages.md b/guides/adding_pages.md
index 4ac4f68a2..1157a1e03 100644
--- a/guides/adding_pages.md
+++ b/guides/adding_pages.md
@@ -109,7 +109,7 @@ defmodule HelloWeb.Router do
   end
 
   scope "/", HelloWeb do
-    pipe_through :browser # Use the default browser stack
+    pipe_through :browser
 
     get "/", PageController, :index
   end
@@ -134,7 +134,7 @@ The `scope "/"` block of our `router.ex` file should now look like this:
 
 ```elixir
 scope "/", HelloWeb do
-  pipe_through :browser # Use the default browser stack
+  pipe_through :browser
 
   get "/", PageController, :index
   get "/hello", HelloController, :index
@@ -189,7 +189,7 @@ Templates are scoped to a view, which are scoped to controller. Phoenix creates
 Let's do that now. Create `lib/hello_web/templates/hello/index.html.eex` and make it look like this:
 
 ```html
-<div class="jumbotron">
+<div class="phx-hero">
   <h2>Hello World, from Phoenix!</h2>
 </div>
 ```
@@ -218,7 +218,7 @@ For this exercise, we're going to re-use the `HelloController` we just created a
 
 ```elixir
 scope "/", HelloWeb do
-  pipe_through :browser # Use the default browser stack.
+  pipe_through :browser
 
   get "/", PageController, :index
   get "/hello", HelloController, :index
@@ -262,7 +262,7 @@ To do that, we'll use the special EEx tags for executing Elixir expressions - `<
 And this is what the template should look like:
 
 ```html
-<div class="jumbotron">
+<div class="phx-hero">
   <h2>Hello World, from <%= @messenger %>!</h2>
 </div>
 ```
diff --git a/guides/contexts.md b/guides/contexts.md
index 1ef674e47..996bc7312 100644
--- a/guides/contexts.md
+++ b/guides/contexts.md
@@ -79,7 +79,7 @@ Phoenix generated the web files as expected in `lib/hello_web/`. We can also see
 
 ```elixir
   scope "/", HelloWeb do
-    pipe_through :browser # Use the default browser stack
+    pipe_through :browser
 
     get "/", PageController, :index
 +   resources "/users", UserController
@@ -497,7 +497,7 @@ Next, let's wire up our session routes in `lib/hello_web/router.ex`:
 
 ```elixir
   scope "/", HelloWeb do
-    pipe_through :browser # Use the default browser stack
+    pipe_through :browser
 
     get "/", PageController, :index
     resources "/users", UserController
diff --git a/guides/ecto.md b/guides/ecto.md
index 46b0f461a..08b5a1387 100644
--- a/guides/ecto.md
+++ b/guides/ecto.md
@@ -415,7 +415,7 @@ SELECT u0."email" FROM "users" AS u0 []
 ["user1@example.com", "user2@example.com"]
 ```
 
-First, we imported `Ecto.Query`, which imports the `from` macro of Ecto's Query DSL. Next, we built a query which selects all the the email addresses in our user's table. Let's try another example.
+First, we imported `Ecto.Query`, which imports the `from` macro of Ecto's Query DSL. Next, we built a query which selects all the email addresses in our user's table. Let's try another example.
 
 ```console
 iex)> Repo.one(from u in User, where: ilike(u.email, "%1%"),
diff --git a/guides/routing.md b/guides/routing.md
index eb4195963..8ca73f303 100644
--- a/guides/routing.md
+++ b/guides/routing.md
@@ -21,7 +21,7 @@ defmodule HelloWeb.Router do
   end
 
   scope "/", HelloWeb do
-    pipe_through :browser # Use the default browser stack
+    pipe_through :browser
 
     get "/", PageController, :index
   end
@@ -92,7 +92,7 @@ Let's add a resource to our `lib/hello_web/router.ex` file like this:
 
 ```elixir
 scope "/", HelloWeb do
-  pipe_through :browser # Use the default browser stack
+  pipe_through :browser
 
   get "/", PageController, :index
   resources "/users", UserController
@@ -797,7 +797,6 @@ defmodule HelloWeb.Router do
   ...
 
   scope "/reviews" do
-    # Use the default browser stack.
     pipe_through [:browser, :review_checks, :other_great_stuff]
 
     resources "/", HelloWeb.ReviewController
@@ -873,13 +872,17 @@ We mount socket handlers in our endpoint at `lib/hello_web/endpoint.ex`. Socket
 
 ```elixir
 defmodule HelloWeb.Endpoint do
-  use Phoenix.Endpoint
+  use Phoenix.Endpoint, otp_app: :hello
 
-  socket "/socket", HelloWeb.UserSocket
+  socket "/socket", HelloWeb.UserSocket,
+    websocket: true,
+    longpoll: false
   ...
 end
 ```
 
+By default, Phoenix supports both websockets and longpoll when invoking Phoenix.Endpoint.socket/3 in your endpoint. Here we're specifying that incoming socket connections can be made via a WebSocket connection.
+
 Next, we need to open our `lib/hello_web/channels/user_socket.ex` file and use the `channel/3` macro to define our channel routes. The routes will match a topic pattern to a channel to handle events. If we have a channel module called `RoomChannel` and a topic called `"rooms:*"`, the code to do this is straightforward.
 
 ```elixir
@@ -893,16 +896,10 @@ end
 
 Topics are just string identifiers. The form we are using here is a convention which allows us to define topics and subtopics in the same string - "topic:subtopic". The `*` is a wildcard character which allows us to match on any subtopic, so `"rooms:lobby"` and `"rooms:kitchen"` would both match this route.
 
-Phoenix abstracts the socket transport layer and includes two transport mechanisms out of the box - WebSockets and Long-Polling. If we wanted to make sure that our channel is handled by only one type of transport, we could specify that using the `via` option, like this.
-
-```elixir
-channel "rooms:*", HelloWeb.RoomChannel, via: [Phoenix.Transports.WebSocket]
-```
-
 Each socket can handle requests for multiple channels.
 
 ```elixir
-channel "rooms:*", HelloWeb.RoomChannel, via: [Phoenix.Transports.WebSocket]
+channel "rooms:*", HelloWeb.RoomChannel
 channel "foods:*", HelloWeb.FoodChannel
 ```
 
diff --git a/guides/templates.md b/guides/templates.md
index b8380bb5b..437f03a58 100644
--- a/guides/templates.md
+++ b/guides/templates.md
@@ -23,7 +23,7 @@ defmodule HelloWeb.Router do
   ...
 
   scope "/", HelloWeb do
-    pipe_through :browser # Use the default browser stack
+    pipe_through :browser
 
     get "/", PageController, :index
     get "/test", PageController, :test
@@ -88,7 +88,7 @@ end
 We have a route. We created a new controller action. We have made modifications to the main application view. Now all we need is a new template to display the string we get from `handler_info/1`. Let's create a new one at `lib/hello_web/templates/page/test.html.eex`.
 
 ```html
-<div class="jumbotron">
+<div class="phx-hero">
   <p><%= handler_info(@conn) %></p>
 </div>
 ```
@@ -110,7 +110,7 @@ Now that we have a function, visible to our template, that returns a list of key
 We can add a header and a list comprehension like this.
 
 ```html
-<div class="jumbotron">
+<div class="phx-hero">
   <p><%= handler_info(@conn) %></p>
 
   <h3>Keys for the conn Struct</h3>
@@ -147,7 +147,7 @@ We need to change `key` to `@key` here because this is a new template, not part
 Now that we have a template, we simply render it within our list comprehension in the `test.html.eex` template.
 
 ```html
-<div class="jumbotron">
+<div class="phx-hero">
   <p><%= handler_info(@conn) %></p>
 
   <h3>Keys for the conn Struct</h3>
@@ -169,7 +169,7 @@ Let's move our template into a shared view.
 `key.html.eex` is currently rendered by the `HelloWeb.PageView` module, but we use a render call which assumes that the current schema is what we want to render with. We could make that explicit, and re-write it like this:
 
 ```html
-<div class="jumbotron">
+<div class="phx-hero">
   ...
 
   <%= for key <- connection_keys(@conn) do %>
diff --git a/guides/up_and_running.md b/guides/up_and_running.md
index c010a5679..82d703507 100644
--- a/guides/up_and_running.md
+++ b/guides/up_and_running.md
@@ -26,8 +26,8 @@ mix phx.new hello
 * creating hello/config/dev.exs
 * creating hello/config/prod.exs
 ...
-* creating hello/lib/hello_web/views/layout_view.ex
-* creating hello/lib/hello_web/views/page_view.ex
+* creating hello/assets/static/images/phoenix.png
+* creating hello/assets/static/favicon.ico
 
 Fetch and install dependencies? [Yn]
 ```
@@ -40,7 +40,7 @@ Fetch and install dependencies? [Yn] Y
 * running mix deps.compile
 * running cd assets && npm install && node node_modules/webpack/bin/webpack.js --mode development
 
-We are all set! Go into your application by running:
+We are almost there! The following steps are missing:
 
     $ cd hello
 
@@ -69,6 +69,8 @@ Now we'll create our database:
 
 ```
 $ mix ecto.create
+Compiling 13 files (.ex)
+Generated hello app
 The database for Hello.Repo has been created
 ```
 
@@ -78,8 +80,10 @@ And finally, we'll start the Phoenix server:
 
 ```console
 $ mix phx.server
-[info] Running HelloWeb.Endpoint with Cowboy using http://0.0.0.0:4000
-19:30:43 - info: compiled 6 files into 2 files, copied 3 in 2.1 sec
+[info] Running HelloWeb.Endpoint with cowboy 2.5.0 at http://localhost:4000
+
+Webpack is watching the files…
+...
 ```
 
 If we choose not to have Phoenix install our dependencies when we generate a new application, the `phx.new` task will prompt us to take the necessary steps when we do want to install them.
diff --git a/guides/views.md b/guides/views.md
index ae2911e3d..0d7291432 100644
--- a/guides/views.md
+++ b/guides/views.md
@@ -73,7 +73,7 @@ When we `use HelloWeb, :view`, we get other conveniences as well. Since `view/0`
 Let's open up the `lib/hello_web/templates/page/index.html.eex` and locate this stanza.
 
 ```html
-<div class="jumbotron">
+<div class="phx-hero">
   <h2><%= gettext("Welcome to %{name}!", name: "Phoenix") %></h2>
   <p class="lead">A productive web framework that<br>does not compromise speed and maintainability.</p>
 </div>
@@ -82,7 +82,7 @@ Let's open up the `lib/hello_web/templates/page/index.html.eex` and locate this
 Then let's add a line with a link back to the same page. (The objective is to see how path helpers respond in a template, not to add any functionality.)
 
 ```html
-<div class="jumbotron">
+<div class="phx-hero">
   <h2><%= gettext("Welcome to %{name}!", name: "Phoenix") %></h2>
   <p class="lead">A productive web framework that<br>does not compromise speed and maintainability.</p>
   <p><a href="<%= Routes.page_path(@conn, :index) %>">Link back to this page</a></p>
@@ -250,7 +250,7 @@ Great, so we have a `render/2` function that takes a template and an `assigns` m
         <span class="logo"></span>
       </div>
 
-      <div class="jumbotron">
+      <div class="phx-hero">
         <p>Sorry, the page you are looking for does not exist.</p>
       </div>
 
diff --git a/lib/phoenix/router/route.ex b/lib/phoenix/router/route.ex
index fcda6bba5..0a8ad59c9 100644
--- a/lib/phoenix/router/route.ex
+++ b/lib/phoenix/router/route.ex
@@ -77,8 +77,8 @@ defmodule Phoenix.Router.Route do
 
   defp build_path_and_binding(%Route{path: path} = route) do
     {params, segments} = case route.kind do
-      :forward -> build_path_match(path <> "/*_forward_path_info")
-      :match   -> build_path_match(path)
+      :forward -> Plug.Router.Utils.build_path_match(path <> "/*_forward_path_info")
+      :match   -> Plug.Router.Utils.build_path_match(path)
     end
 
     binding = for var <- params, var != :_forward_path_info do
@@ -118,7 +118,7 @@ defmodule Phoenix.Router.Route do
   end
 
   defp build_dispatch(%Route{kind: :forward} = route) do
-    {_params, fwd_segments} = build_path_match(route.path)
+    {_params, fwd_segments} = Plug.Router.Utils.build_path_match(route.path)
 
     quote do
       {
@@ -160,7 +160,7 @@ defmodule Phoenix.Router.Route do
   `path` contains a dynamic segment.
   """
   def forward_path_segments(path, plug, phoenix_forwards) do
-    case build_path_match(path) do
+    case Plug.Router.Utils.build_path_match(path) do
       {[], path_segments} ->
         if phoenix_forwards[plug] do
           raise ArgumentError, "#{inspect plug} has already been forwarded to. A module can only be forwarded a single time."
@@ -170,14 +170,4 @@ defmodule Phoenix.Router.Route do
         raise ArgumentError, "dynamic segment \"#{path}\" not allowed when forwarding. Use a static path instead."
     end
   end
-
-  if Code.ensure_loaded?(Plug.Router.Utils) do
-    defp build_path_match(path) do
-      Plug.Router.Utils.build_path_match(path)
-    end
-  else
-    defp build_path_match(path) do
-      Plug.Router.Compiler.build_path_match(path)
-    end
-  end
 end


Test patch:
diff --git a/guides/testing/testing.md b/guides/testing/testing.md
index 19f477cca..4041246b3 100644
--- a/guides/testing/testing.md
+++ b/guides/testing/testing.md
@@ -466,7 +466,7 @@ defmodule HelloWeb.Router do
   ...
 
   scope "/", Hello do
-    pipe_through :browser # Use the default browser stack
+    pipe_through :browser
 
     get "/", PageController, :index
     resources "/users", UserController
diff --git a/guides/testing/testing_controllers.md b/guides/testing/testing_controllers.md
index 0f5e5ec23..909bd674c 100644
--- a/guides/testing/testing_controllers.md
+++ b/guides/testing/testing_controllers.md
@@ -177,7 +177,7 @@ defmodule HelloWeb.Router do
   end
 
   scope "/", HelloWeb do
-    pipe_through :browser # Use the default browser stack
+    pipe_through :browser
 
     get "/", PageController, :index
   end
diff --git a/guides/testing/testing_schemas.md b/guides/testing/testing_schemas.md
index 2d0f4046e..5159297ba 100644
--- a/guides/testing/testing_schemas.md
+++ b/guides/testing/testing_schemas.md
@@ -497,7 +497,7 @@ defmodule HelloWeb.Router do
   ...
 
   scope "/", HelloWeb do
-    pipe_through :browser # Use the default browser stack
+    pipe_through :browser
 
     get "/", PageController, :index
     resources "/users", UserController