diff --git a/guides/authentication/api_authentication.md b/guides/authentication/api_authentication.md
index d9de5b06e3..48d3327e7c 100644
--- a/guides/authentication/api_authentication.md
+++ b/guides/authentication/api_authentication.md
@@ -63,7 +63,7 @@ To make sure our new functions work, let's write tests. Open up `test/my_app/acc
If you run the tests, they will actually fail. Something similar to this:
-```elixir
+```console
1) test create_user_api_token/1 and fetch_user_by_api_token/1 creates and verify token (Demo.AccountsTest)
test/demo/accounts_test.exs:21
** (FunctionClauseError) no function clause matching in Demo.Accounts.UserToken.days_for_context/1
diff --git a/guides/components.md b/guides/components.md
index f78aa38a3d..83e6710e8c 100644
--- a/guides/components.md
+++ b/guides/components.md
@@ -56,7 +56,7 @@ We declared the attributes we accept via the `attr/3` macro provided by `Phoenix
Next we need to update `show.html.heex`:
-```elixir
+```heex
<.greet messenger={@messenger} />
@@ -92,7 +92,7 @@ Next, let's fully understand the expressive power behind the HEEx template langu
Function components and templates files are powered by [the HEEx template language](https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html#sigil_H/2), which stands for "HTML+EEx". EEx is an Elixir library that uses `<%= expression %>` to execute Elixir expressions and interpolate their results into the template. This is frequently used to display assigns we have set by way of the `@` shortcut. In your controller, if you invoke:
```elixir
- render(conn, :show, username: "joe")
+render(conn, :show, username: "joe")
```
Then you can access said username in the templates as `<%= @username %>`. In addition to displaying assigns and functions, we can use pretty much any Elixir expression. For example, in order to have conditionals:
diff --git a/guides/contexts.md b/guides/contexts.md
index 333eaa209f..273b35517c 100644
--- a/guides/contexts.md
+++ b/guides/contexts.md
@@ -361,7 +361,6 @@ $ mix ecto.gen.migration create_product_categories
Next, let's open up the new migration file and add the following code to the `change` function:
```elixir
-
defmodule Hello.Repo.Migrations.CreateProductCategories do
use Ecto.Migration
@@ -521,7 +520,7 @@ With our `category_opts` function in place, we can open up `lib/hello_web/contro
We added a `category_select` above our save button. Now let's try it out. Next, let's show the product's categories in the product show template. Add the following code to the list in `lib/hello_web/controllers/product_html/show.html.heex`:
-```heex
+```diff
<.list>
...
+ <:item title="Categories">
diff --git a/guides/deployment/fly.md b/guides/deployment/fly.md
index b2513090c9..723414cb33 100644
--- a/guides/deployment/fly.md
+++ b/guides/deployment/fly.md
@@ -88,7 +88,7 @@ $ fly deploy
Note: On Apple Silicon (M1) computers, docker runs cross-platform builds using qemu which might not always work. If you get a segmentation fault error like the following:
-```
+```console
=> [build 7/17] RUN mix deps.get --only
=> => # qemu: uncaught target signal 11 (Segmentation fault) - core dumped
```
diff --git a/guides/deployment/gigalixir.md b/guides/deployment/gigalixir.md
index 4844ec4003..8b13f3887a 100644
--- a/guides/deployment/gigalixir.md
+++ b/guides/deployment/gigalixir.md
@@ -163,8 +163,8 @@ For a free tier database, update your `Repo` config with:
```elixir
ssl: true,
ssl_opts: [
- verify: :verify_none,
- cacerts: :public_key.cacerts_get()
+ verify: :verify_none,
+ cacerts: :public_key.cacerts_get()
]
```
diff --git a/guides/ecto.md b/guides/ecto.md
index a06b778d11..777a271cd5 100644
--- a/guides/ecto.md
+++ b/guides/ecto.md
@@ -245,7 +245,7 @@ iex> changeset.errors
Now, let's make `number_of_pets` optional. In order to do this, we simply remove it from the list in the `changeset/2` function, in `Hello.User`.
```elixir
- |> validate_required([:name, :email, :bio])
+|> validate_required([:name, :email, :bio])
```
Now casting the changeset should tell us that only `name`, `email`, and `bio` can't be blank. We can test that by running `recompile()` inside IEx and then rebuilding our changeset.
@@ -529,7 +529,7 @@ Let's open up our `mix.exs` file and do that now.
defmodule HelloPhoenix.MixProject do
use Mix.Project
- . . .
+ ...
# Specifies your project dependencies.
#
# Type `mix help deps` for examples and options.
diff --git a/guides/howto/custom_error_pages.md b/guides/howto/custom_error_pages.md
index 2b14c1081b..3bd1ffbe89 100644
--- a/guides/howto/custom_error_pages.md
+++ b/guides/howto/custom_error_pages.md
@@ -53,7 +53,7 @@ config :hello, HelloWeb.Endpoint,
http: [port: 4000],
debug_errors: false,
code_reloader: true,
- . . .
+ ...
```
After modifying our config file, we need to restart our server in order for this change to take effect. After restarting the server, let's go to [http://localhost:4000/such/a/wrong/path](http://localhost:4000/such/a/wrong/path) for a running local application and see what we get.
diff --git a/guides/howto/file_uploads.md b/guides/howto/file_uploads.md
index 2d5e63fb66..e0dd621b74 100644
--- a/guides/howto/file_uploads.md
+++ b/guides/howto/file_uploads.md
@@ -30,7 +30,7 @@ Here is the form from `lib/hello_web/controllers/product_html/product_form.html.
```heex
<.simple_form :let={f} for={@changeset} action={@action} multipart>
-. . .
+...
```
### Add a file input
@@ -38,7 +38,7 @@ Here is the form from `lib/hello_web/controllers/product_html/product_form.html.
Once you have a multipart form, you need a `file` input. Here's how you would do that, also in `product_form.html.heex`:
```heex
-. . .
+...
<.input field={f[:photo]} type="file" label="Photo" />
<:actions>
@@ -71,10 +71,10 @@ Since you generated an HTML resource, you can now start your server with `mix ph
Before you begin, add `IO.inspect product_params` to the top of your `ProductController.create/2` action in `lib/hello_web/controllers/product_controller.ex`. This will show the `product_params` in your development log so you can get a better sense of what's happening.
```elixir
-. . .
+...
def create(conn, %{"product" => product_params}) do
IO.inspect product_params
-. . .
+...
```
When you do that, this is what your `product_params` will output in the log:
diff --git a/guides/json_and_apis.md b/guides/json_and_apis.md
index 5994229dc5..e2705c9a3e 100644
--- a/guides/json_and_apis.md
+++ b/guides/json_and_apis.md
@@ -52,7 +52,7 @@ The API scope uses the `:api` pipeline, which will run specific steps such as en
Then we need to update our repository by running migrations:
```console
-mix ecto.migrate
+$ mix ecto.migrate
```
### Trying out the JSON API
@@ -62,13 +62,13 @@ Before we go ahead and change those files, let's take a look at how our API beha
First, we need to start the server:
```console
-mix phx.server
+$ mix phx.server
```
Next, let's make a smoke test to check our API is working with:
```console
-curl -i http://localhost:4000/api/urls
+$ curl -i http://localhost:4000/api/urls
```
If everything went as planned we should get a `200` response:
@@ -88,11 +88,11 @@ x-request-id: Fuyg-wMl4S-hAfsAAAUk
We didn't get any data because we haven't populated the database with any yet. So let's add some links:
```console
-curl -iX POST http://localhost:4000/api/urls \
+$ curl -iX POST http://localhost:4000/api/urls \
-H 'Content-Type: application/json' \
-d '{"url": {"link":"https://phoenixframework.org", "title":"Phoenix Framework"}}'
-curl -iX POST http://localhost:4000/api/urls \
+$ curl -iX POST http://localhost:4000/api/urls \
-H 'Content-Type: application/json' \
-d '{"url": {"link":"https://elixir-lang.org", "title":"Elixir"}}'
```
@@ -100,19 +100,19 @@ curl -iX POST http://localhost:4000/api/urls \
Now we can retrieve all links:
```console
-curl -i http://localhost:4000/api/urls
+$ curl -i http://localhost:4000/api/urls
```
Or we can just retrieve a link by its `id`:
```console
-curl -i http://localhost:4000/api/urls/1
+$ curl -i http://localhost:4000/api/urls/1
```
Next, we can update a link with:
```console
-curl -iX PUT http://localhost:4000/api/urls/2 \
+$ curl -iX PUT http://localhost:4000/api/urls/2 \
-H 'Content-Type: application/json' \
-d '{"url": {"title":"Elixir Programming Language"}}'
```
@@ -122,7 +122,7 @@ The response should be a `200` with the updated link in the body.
Finally, we need to try out the removal of a link:
```console
-curl -iX DELETE http://localhost:4000/api/urls/2 \
+$ curl -iX DELETE http://localhost:4000/api/urls/2 \
-H 'Content-Type: application/json'
```
@@ -291,7 +291,7 @@ As we can see, it will convert the errors into a data structure, which will be r
As you can see, the changeset requires both link and title to be given. This means we can try posting a url with no link and title and see how our API responds:
```console
-curl -iX POST http://localhost:4000/api/urls \
+$ curl -iX POST http://localhost:4000/api/urls \
-H 'Content-Type: application/json' \
-d '{"url": {}}'
@@ -310,7 +310,7 @@ for the REST API.
From your terminal run:
```console
-mix help phx.new
+$ mix help phx.new
```
The output should contain the following:
diff --git a/guides/mix_tasks.md b/guides/mix_tasks.md
index 565a001472..8abe3594ae 100644
--- a/guides/mix_tasks.md
+++ b/guides/mix_tasks.md
@@ -583,13 +583,13 @@ Don't forget to add your new repo to your supervision tree
Notice that this task has updated `config/config.exs`. If we take a look, we'll see this extra configuration block for our new repo.
```elixir
-. . .
+...
config :hello, OurCustom.Repo,
username: "user",
password: "pass",
hostname: "localhost",
database: "hello_repo",
-. . .
+...
```
Of course, we'll need to change the login credentials to match what our database expects. We'll also need to change the config for other environments.
@@ -597,7 +597,7 @@ Of course, we'll need to change the login credentials to match what our database
We certainly should follow the instructions and add our new repo to our supervision tree. In our `Hello` application, we would open up `lib/hello/application.ex`, and add our repo as a worker to the `children` list.
```elixir
-. . .
+...
children = [
Hello.Repo,
# Our custom repo
@@ -605,7 +605,7 @@ children = [
# Start the endpoint when the application starts
HelloWeb.Endpoint,
]
-. . .
+...
```
### `mix ecto.gen.migration`
@@ -638,7 +638,7 @@ Notice that there is a single function `change/0` which will handle both forward
What we want to do is create a `comments` table with a `body` column, a `word_count` column, and timestamp columns for `inserted_at` and `updated_at`.
```elixir
-. . .
+...
def change do
create table(:comments) do
add :body, :string
@@ -646,7 +646,7 @@ def change do
timestamps()
end
end
-. . .
+...
```
Again, we can run this task with the `-r` flag and another repo if we need to.
@@ -707,13 +707,13 @@ $ mix ecto.migrate -n 2
The `--step` option will behave the same way.
```console
-mix ecto.migrate --step 2
+$ mix ecto.migrate --step 2
```
The `--to` option will run all migrations up to and including given version.
```console
-mix ecto.migrate --to 20150317170448
+$ mix ecto.migrate --to 20150317170448
```
### `mix ecto.rollback`
diff --git a/guides/routing.md b/guides/routing.md
index 59a8f8fd38..30710bac0d 100644
--- a/guides/routing.md
+++ b/guides/routing.md
@@ -228,7 +228,7 @@ end
When we run `mix phx.routes` now, in addition to the routes we saw for `users` above, we get the following set of routes:
-```elixir
+```console
...
GET /users/:user_id/posts HelloWeb.PostController :index
GET /users/:user_id/posts/:id/edit HelloWeb.PostController :edit
diff --git a/lib/mix/tasks/phx.gen.embedded.ex b/lib/mix/tasks/phx.gen.embedded.ex
index 977cac2efa..4e82eec674 100644
--- a/lib/mix/tasks/phx.gen.embedded.ex
+++ b/lib/mix/tasks/phx.gen.embedded.ex
@@ -4,7 +4,9 @@ defmodule Mix.Tasks.Phx.Gen.Embedded do
@moduledoc """
Generates an embedded Ecto schema for casting/validating data outside the DB.
- mix phx.gen.embedded Blog.Post title:string views:integer
+ ```console
+ $ mix phx.gen.embedded Blog.Post title:string views:integer
+ ```
The first argument is the schema module followed by the schema attributes.
@@ -18,7 +20,9 @@ defmodule Mix.Tasks.Phx.Gen.Embedded do
where type are the types supported by Ecto. Omitting
the type makes it default to `:string`:
- mix phx.gen.embedded Blog.Post title views:integer
+ ```console
+ $ mix phx.gen.embedded Blog.Post title views:integer
+ ```
The following types are supported:
diff --git a/lib/mix/tasks/phx.gen.html.ex b/lib/mix/tasks/phx.gen.html.ex
index 76fe2aa388..e3f75b2c6a 100644
--- a/lib/mix/tasks/phx.gen.html.ex
+++ b/lib/mix/tasks/phx.gen.html.ex
@@ -4,7 +4,9 @@ defmodule Mix.Tasks.Phx.Gen.Html do
@moduledoc """
Generates controller with view, templates, schema and context for an HTML resource.
- mix phx.gen.html Accounts User users name:string age:integer
+ ```console
+ $ mix phx.gen.html Accounts User users name:string age:integer
+ ```
The first argument, `Accounts`, is the resource's context.
A context is an Elixir module that serves as an API boundary for closely related resources.
@@ -51,7 +53,9 @@ defmodule Mix.Tasks.Phx.Gen.Html do
Alternatively, the `--context-app` option may be supplied to the generator:
- mix phx.gen.html Sales User users --context-app my_app
+ ```console
+ $ mix phx.gen.html Sales User users --context-app my_app
+ ```
If you delete the `:context_app` configuration option, Phoenix will automatically put generated web files in
`my_app_umbrella/apps/my_app_web_web`.
@@ -67,7 +71,9 @@ defmodule Mix.Tasks.Phx.Gen.Html do
You can customize the web module namespace by passing the `--web` flag with a
module name, for example:
- mix phx.gen.html Sales User users --web Sales
+ ```console
+ $ mix phx.gen.html Sales User users --web Sales
+ ```
Which would generate a `lib/app_web/controllers/sales/user_controller.ex` and
`lib/app_web/controllers/sales/user_html.ex`.
diff --git a/lib/mix/tasks/phx.gen.json.ex b/lib/mix/tasks/phx.gen.json.ex
index 08efb5f16c..97177b4935 100644
--- a/lib/mix/tasks/phx.gen.json.ex
+++ b/lib/mix/tasks/phx.gen.json.ex
@@ -4,7 +4,9 @@ defmodule Mix.Tasks.Phx.Gen.Json do
@moduledoc """
Generates controller, JSON view, and context for a JSON resource.
- mix phx.gen.json Accounts User users name:string age:integer
+ ```console
+ $ mix phx.gen.json Accounts User users name:string age:integer
+ ```
The first argument is the context module followed by the schema module
and its plural name (used as the schema table name).
@@ -56,7 +58,9 @@ defmodule Mix.Tasks.Phx.Gen.Json do
Alternatively, the `--context-app` option may be supplied to the generator:
- mix phx.gen.json Sales User users --context-app warehouse
+ ```console
+ $ mix phx.gen.json Sales User users --context-app warehouse
+ ```
## Web namespace
@@ -64,7 +68,9 @@ defmodule Mix.Tasks.Phx.Gen.Json do
You can customize the web module namespace by passing the `--web` flag with a
module name, for example:
- mix phx.gen.json Sales User users --web Sales
+ ```console
+ $ mix phx.gen.json Sales User users --web Sales
+ ```
Which would generate a `lib/app_web/controllers/sales/user_controller.ex` and
`lib/app_web/controller/sales/user_json.ex`.
diff --git a/lib/mix/tasks/phx.gen.live.ex b/lib/mix/tasks/phx.gen.live.ex
index f0b6aa28aa..e0d10ba91a 100644
--- a/lib/mix/tasks/phx.gen.live.ex
+++ b/lib/mix/tasks/phx.gen.live.ex
@@ -4,7 +4,9 @@ defmodule Mix.Tasks.Phx.Gen.Live do
@moduledoc """
Generates LiveView, templates, and context for a resource.
- mix phx.gen.live Accounts User users name:string age:integer
+ ```console
+ $ mix phx.gen.live Accounts User users name:string age:integer
+ ```
The first argument is the context module. The context is an Elixir module
that serves as an API boundary for the given resource. A context often holds
@@ -64,7 +66,9 @@ defmodule Mix.Tasks.Phx.Gen.Live do
Alternatively, the `--context-app` option may be supplied to the generator:
- mix phx.gen.live Accounts User users --context-app warehouse
+ ```console
+ $ mix phx.gen.live Accounts User users --context-app warehouse
+ ```
## Web namespace
@@ -72,7 +76,9 @@ defmodule Mix.Tasks.Phx.Gen.Live do
You can customize the web module namespace by passing the `--web` flag with a
module name, for example:
- mix phx.gen.live Accounts User users --web Sales
+ ```console
+ $ mix phx.gen.live Accounts User users --web Sales
+ ```
Which would generate the LiveViews in `lib/app_web/live/sales/user_live/`,
namespaced `AppWeb.Sales.UserLive` instead of `AppWeb.UserLive`.
@@ -84,7 +90,9 @@ defmodule Mix.Tasks.Phx.Gen.Live do
to yourself. You can use the `--no-context` and `--no-schema` flags
for file generation control.
- mix phx.gen.live Accounts User users --no-context --no-schema
+ ```console
+ $ mix phx.gen.live Accounts User users --no-context --no-schema
+ ```
In the cases above, tests are still generated, but they will all fail.
diff --git a/lib/phoenix/flash.ex b/lib/phoenix/flash.ex
index 794153fad7..591c9a5a11 100644
--- a/lib/phoenix/flash.ex
+++ b/lib/phoenix/flash.ex
@@ -8,8 +8,10 @@ defmodule Phoenix.Flash do
## Examples
-
<%= Phoenix.Flash.get(@flash, :info) %>
- <%= Phoenix.Flash.get(@flash, :error) %>
+ ```heex
+ <%= Phoenix.Flash.get(@flash, :info) %>
+ <%= Phoenix.Flash.get(@flash, :error) %>
+ ```
"""
def get(%mod{}, key) when is_atom(key) or is_binary(key) do
raise ArgumentError, """
diff --git a/lib/phoenix/router.ex b/lib/phoenix/router.ex
index ad4683ddf4..84b5afd793 100644
--- a/lib/phoenix/router.ex
+++ b/lib/phoenix/router.ex
@@ -1008,15 +1008,16 @@ defmodule Phoenix.Router do
will include the following routes:
- user_post_path GET /users/:user_id/posts PostController :index
- user_post_path GET /users/:user_id/posts/:id/edit PostController :edit
- user_post_path GET /users/:user_id/posts/new PostController :new
- user_post_path GET /users/:user_id/posts/:id PostController :show
- user_post_path POST /users/:user_id/posts PostController :create
- user_post_path PATCH /users/:user_id/posts/:id PostController :update
- PUT /users/:user_id/posts/:id PostController :update
- user_post_path DELETE /users/:user_id/posts/:id PostController :delete
-
+ ```console
+ user_post_path GET /users/:user_id/posts PostController :index
+ user_post_path GET /users/:user_id/posts/:id/edit PostController :edit
+ user_post_path GET /users/:user_id/posts/new PostController :new
+ user_post_path GET /users/:user_id/posts/:id PostController :show
+ user_post_path POST /users/:user_id/posts PostController :create
+ user_post_path PATCH /users/:user_id/posts/:id PostController :update
+ PUT /users/:user_id/posts/:id PostController :update
+ user_post_path DELETE /users/:user_id/posts/:id PostController :delete
+ ```
"""
defmacro resources(path, controller, opts, do: nested_context) do
add_resources(path, controller, opts, do: nested_context)
diff --git a/lib/phoenix/token.ex b/lib/phoenix/token.ex
index ba01eca287..8dd2548dec 100644
--- a/lib/phoenix/token.ex
+++ b/lib/phoenix/token.ex
@@ -59,8 +59,9 @@ defmodule Phoenix.Token do
One is via the meta tag:
- <%= tag :meta, name: "channel_token",
- content: Phoenix.Token.sign(@conn, "user auth", @current_user.id) %>
+ ```heex
+
+ ```
Or an endpoint that returns it:
diff --git a/lib/phoenix/verified_routes.ex b/lib/phoenix/verified_routes.ex
index a932743b84..222d52726e 100644
--- a/lib/phoenix/verified_routes.ex
+++ b/lib/phoenix/verified_routes.ex
@@ -1,12 +1,14 @@
defmodule Phoenix.VerifiedRoutes do
- @moduledoc ~S"""
+ @moduledoc ~S'''
Provides route generation with compile-time verification.
Use of the `sigil_p` macro allows paths and URLs throughout your
application to be compile-time verified against your Phoenix router(s).
For example, the following path and URL usages:
+ ~H"""
<.link href={~p"/sessions/new"} method="post">Log in
+ """
redirect(to: url(~p"/posts/#{post}"))
@@ -17,8 +19,10 @@ defmodule Phoenix.VerifiedRoutes do
Unmatched routes will issue compiler warnings:
- warning: no route path for AppWeb.Router matches "/postz/#{post}"
- lib/app_web/controllers/post_controller.ex:100: AppWeb.PostController.show/2
+ ```console
+ warning: no route path for AppWeb.Router matches "/postz/#{post}"
+ lib/app_web/controllers/post_controller.ex:100: AppWeb.PostController.show/2
+ ```
Additionally, interpolated ~p values are encoded via the `Phoenix.Param` protocol.
For example, a `%Post{}` struct in your application may derive the `Phoenix.Param`
@@ -101,7 +105,7 @@ defmodule Phoenix.VerifiedRoutes do
*Note: Elixir >= 1.14.0 is required for comprehensive warnings. Older versions
will compile properly, but no warnings will be issued.
- """
+ '''
@doc false
defstruct router: nil,
route: nil,