Skip to content

Commit

Permalink
Guides hyperlinks fixes (phoenixframework#3170)
Browse files Browse the repository at this point in the history
* Add missing hyperlink to socket/3 in the routing guide

* Mix Tasks guides hyperlinks changes

Fix links to mix tasks in the Mix Tasks guide;
Add precise links to Mix Tasks guide in the Up and Running guide;

* Leverage ex_doc's new mix task docs auto-linking in Up and Running and Mix Tasks guides

* Revert unnecessary change in the Up and Running guide
  • Loading branch information
michallepicki authored and chrismccord committed Nov 21, 2018
1 parent e4936bf commit 39068a5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
64 changes: 32 additions & 32 deletions guides/phoenix_mix_tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ mix phx.server # Starts applications and their servers

We have seen all of these at one point or another in the guides, but having all the information about them in one place seems like a good idea. And here we are.

#### `mix phx.new`
### `mix phx.new`

This is how we tell Phoenix the framework to generate a new Phoenix application for us. We saw it early on in the [Up and Running Guide](up_and_running.html).

Before we begin, we should note that Phoenix uses [Ecto](https://github.com/elixir-lang/ecto) for database access and [webpack](https://webpack.js.org/) for asset management by default. We can pass `--no-ecto` to opt out of Ecto and `--no-webpack` to opt out of webpack.

> Note: If we do use webpack, we need to install its dependencies before we start our application. `phx.new` will ask to do this for us. Otherwise, we can install them with `npm install`. If we don't install them, the app will throw errors and may not serve our assets properly.
> Note: If we do use webpack, we need to install its dependencies before we start our application. `mix phx.new` will ask to do this for us. Otherwise, we can install them with `npm install`. If we don't install them, the app will throw errors and may not serve our assets properly.
We need to pass `phx.new` a name for our application. Conventionally, we use all lower-case letters with underscores.
We need to pass a name for our application to `mix phx.new`. Conventionally, we use all lower-case letters with underscores.

```console
$ mix phx.new task_tester
Expand All @@ -64,15 +64,15 @@ $ mix phx.new /Users/me/work/task_tester
. . .
```

The `phx.new` task will also ask us if we want to install our dependencies. (Please see the note above about webpack dependencies.)
The `mix phx.new` task will also ask us if we want to install our dependencies. (Please see the note above about webpack dependencies.)

```console
Fetch and install dependencies? [Yn] y
* cd assets && npm install && node node_modules/webpack/bin/webpack.js --mode development
* running mix deps.get
```

Once all of our dependencies are installed, `phx.new` will tell us what our next steps are.
Once all of our dependencies are installed, `mix phx.new` will tell us what our next steps are.

```console
We are all set! Run your Phoenix application:
Expand All @@ -85,7 +85,7 @@ You can also run it inside IEx (Interactive Elixir) as:
$ iex -S mix phx.server
```

By default `phx.new` will assume we want to use ecto for our contexts. If we don't want to use ecto in our application, we can use the `--no-ecto` flag.
By default `mix phx.new` will assume we want to use ecto for our contexts. If we don't want to use ecto in our application, we can use the `--no-ecto` flag.

```console
$ mix phx.new task_tester --no-ecto
Expand All @@ -95,7 +95,7 @@ $ mix phx.new task_tester --no-ecto

With the `--no-ecto` flag, Phoenix will not make either ecto or postgrex a dependency of our application, and it will not create a `repo.ex` file.

By default, Phoenix will name our OTP application after the name we pass into `phx.new`. If we want, we can specify a different OTP application name with the `--app` flag.
By default, Phoenix will name our OTP application after the name we pass into `mix phx.new`. If we want, we can specify a different OTP application name with the `--app` flag.

```console
$ mix phx.new task_tester --app hello
Expand Down Expand Up @@ -187,11 +187,11 @@ defmodule Hello.MixProject do
. . .
```

#### [mix phx.gen.html](`Mix.Tasks.Phx.Gen.Html.run/1`)
### `mix phx.gen.html`

Phoenix now offers the ability to generate all the code to stand up a complete HTML resource - ecto migration, ecto context, controller with all the necessary actions, view, and templates. This can be a tremendous timesaver. Let's take a look at how to make this happen.

The `phx.gen.html` task takes a number of arguments, the module name of the context, the module name of the schema, the resource name, and a list of column_name:type attributes. The module name we pass in must conform to the Elixir rules of module naming, following proper capitalization.
The `mix phx.gen.html` task takes a number of arguments, the module name of the context, the module name of the schema, the resource name, and a list of column_name:type attributes. The module name we pass in must conform to the Elixir rules of module naming, following proper capitalization.

```console
$ mix phx.gen.html Blog Post posts body:string word_count:integer
Expand All @@ -211,7 +211,7 @@ $ mix phx.gen.html Blog Post posts body:string word_count:integer
* injecting test/hello/blog/blog_test.exs
```

When `phx.gen.html` is done creating files, it helpfully tells us that we need to add a line to our router file as well as run our ecto migrations.
When `mix phx.gen.html` is done creating files, it helpfully tells us that we need to add a line to our router file as well as run our ecto migrations.

```console
Add the resource to your browser scope in lib/hello_web/router.ex:
Expand Down Expand Up @@ -301,11 +301,11 @@ warning: function HelloWeb.Router.Helpers.post_path/3 is undefined or private
lib/hello_web/templates/post/edit.html.eex:3
```

#### [mix phx.gen.json](`Mix.Tasks.Phx.Gen.Json.run/1`)
### `mix phx.gen.json`

Phoenix also offers the ability to generate all the code to stand up a complete JSON resource - ecto migration, ecto schema, controller with all the necessary actions and view. This command will not create any template for the app.

The `phx.gen.json` task takes a number of arguments, the module name of the context, the module name of the schema, the resource name, and a list of column_name:type attributes. The module name we pass in must conform to the Elixir rules of module naming, following proper capitalization.
The `mix phx.gen.json` task takes a number of arguments, the module name of the context, the module name of the schema, the resource name, and a list of column_name:type attributes. The module name we pass in must conform to the Elixir rules of module naming, following proper capitalization.

```console
$ mix phx.gen.json Blog Post posts title:string content:string
Expand All @@ -322,7 +322,7 @@ $ mix phx.gen.json Blog Post posts title:string content:string
* injecting test/hello/blog/blog_test.exs
```

When `phx.gen.json` is done creating files, it helpfully tells us that we need to add a line to our router file as well as run our ecto migrations.
When `mix phx.gen.json` is done creating files, it helpfully tells us that we need to add a line to our router file as well as run our ecto migrations.

```console
Add the resource to your :api scope in lib/hello_web/router.ex:
Expand Down Expand Up @@ -415,11 +415,11 @@ Compiling 18 files (.ex)
(elixir) lib/kernel/parallel_compiler.ex:121: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1
```

#### [mix phx.gen.context](`Mix.Tasks.Phx.Gen.Context.run/1`)
### `mix phx.gen.context`

If we don't need a complete HTML/JSON resource and instead are only interested in a context, we can use the `phx.gen.context` task. It will generate a context, a schema, a migration and a test case.
If we don't need a complete HTML/JSON resource and instead are only interested in a context, we can use the `mix phx.gen.context` task. It will generate a context, a schema, a migration and a test case.

The `phx.gen.context` task takes a number of arguments, the module name of the context, the module name of the schema, the resource name, and a list of column_name:type attributes.
The `mix phx.gen.context` task takes a number of arguments, the module name of the context, the module name of the schema, the resource name, and a list of column_name:type attributes.

```console
$ mix phx.gen.context Accounts User users name:string age:integer
Expand All @@ -442,19 +442,19 @@ $ mix phx.gen.context Accounts User users name:string age:integer
* injecting test/hello/admin/accounts/accounts_test.exs
```

#### [mix phx.gen.schema](`Mix.Tasks.Phx.Gen.Schema.run/1`)
### `mix phx.gen.schema`

If we don't need a complete HTML/JSON resource and are not interested in generating or altering a context we can use the `phx.gen.schema` task. It will generate a schema, and a migration.
If we don't need a complete HTML/JSON resource and are not interested in generating or altering a context we can use the `mix phx.gen.schema` task. It will generate a schema, and a migration.

The `phx.gen.schema` task takes a number of arguments, the module name of the schema (which may be namespaced), the resource name, and a list of column_name:type attributes.
The `mix phx.gen.schema` task takes a number of arguments, the module name of the schema (which may be namespaced), the resource name, and a list of column_name:type attributes.

```console
$ mix phx.gen.schema Accounts.Credential credentials email:string:unique user_id:references:users
* creating lib/hello/accounts/credential.ex
* creating priv/repo/migrations/20170906162013_create_credentials.exs
```

#### [mix phx.gen.channel](`Mix.Tasks.Phx.Gen.Channel.run/1`)
### `mix phx.gen.channel`

This task will generate a basic Phoenix channel as well a test case for it. It takes the module name for the channel as argument:

Expand All @@ -464,15 +464,15 @@ $ mix phx.gen.channel Room
* creating test/hello_web/channels/room_channel_test.exs
```

When `phx.gen.channel` is done, it helpfully tells us that we need to add a channel route to our router file.
When `mix phx.gen.channel` is done, it helpfully tells us that we need to add a channel route to our router file.

```console
Add the channel to your `lib/hello_web/channels/user_socket.ex` handler, for example:

channel "rooms:lobby", HelloWeb.RoomChannel
```

#### [mix phx.gen.presence](`Mix.Tasks.Phx.Gen.Presence.run/1`)
### `mix phx.gen.presence`

This task will generate a Presence tracker. The module name can be passed as an argument,
`Presence` is used if no module name is passed.
Expand All @@ -482,7 +482,7 @@ $ mix phx.gen.presence Presence
$ lib/hello_web/channels/presence.ex
```

#### `mix [mix phx.routes](`Mix.Tasks.Phx.Routes.run/1`)
### `mix phx.routes`

This task has a single purpose, to show us all the routes defined for a given router. We saw it used extensively in the [Routing Guide](routing.html).

Expand All @@ -499,7 +499,7 @@ $ mix phx.routes TaskTesterWeb.Router
page_path GET / TaskTesterWeb.PageController.index/2
```

#### [mix phx.server](`Mix.Tasks.Phx.Server.run/1`)
### `mix phx.server`

This is the task we use to get our application running. It takes no arguments at all. If we pass any in, they will be silently ignored.

Expand All @@ -524,7 +524,7 @@ Interactive Elixir (1.0.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>
```

#### [mix phx.digest](`Mix.Tasks.Phx.Digest.run/1`)
### `mix phx.digest`

This task does two things, it creates a digest for our static assets and then compresses them.

Expand Down Expand Up @@ -571,15 +571,15 @@ We can optionally determine which files should be gzipped by using the `:gzippab
config :phoenix, :gzippable_exts, ~w(.js .css)
```

> Note: We can specify a different output folder where `phx.digest` will put processed files. The first argument is the path where the static files are located.
> Note: We can specify a different output folder where `mix phx.digest` will put processed files. The first argument is the path where the static files are located.
```console
$ mix phx.digest priv/static -o www/public
Check your digested files at 'www/public'.
```

## Ecto Specific Mix Tasks

Newly generated Phoenix applications now include ecto and postgrex as dependencies by default (which is to say, unless we use the `--no-ecto` flag with `phx.new`). With those dependencies come mix tasks to take care of common ecto operations. Let's see which tasks we get out of the box.
Newly generated Phoenix applications now include ecto and postgrex as dependencies by default (which is to say, unless we use `mix phx.new` with the `--no-ecto` flag). With those dependencies come mix tasks to take care of common ecto operations. Let's see which tasks we get out of the box.

```console
$ mix help | grep -i ecto
Expand All @@ -593,7 +593,7 @@ mix ecto.rollback # Reverts migrations down on a repo

Note: We can run any of the tasks above with the `--no-start` flag to execute the task without starting the application.

#### `ecto.create`
### `mix ecto.create`
This task will create the database specified in our repo. By default it will look for the repo named after our application (the one generated with our app unless we opted out of ecto), but we can pass in another repo if we want.

Here's what it looks like in action.
Expand Down Expand Up @@ -677,7 +677,7 @@ $ mix ecto.drop -r OurCustom.Repo
The database for OurCustom.Repo has been dropped.
```

#### `ecto.gen.repo`
### `mix ecto.gen.repo`

Many applications require more than one data store. For each data store, we'll need a new repo, and we can generate them automatically with `ecto.gen.repo`.

Expand Down Expand Up @@ -724,7 +724,7 @@ children = [
. . .
```

#### `ecto.gen.migration`
### `mix ecto.gen.migration`

Migrations are a programmatic, repeatable way to affect changes to a database schema. Migrations are also just modules, and we can create them with the `ecto.gen.migration` task. Let's walk through the steps to create a migration for a new comments table.

Expand Down Expand Up @@ -779,7 +779,7 @@ For example, to alter an existing schema see the documentation on ecto’s

That's it! We're ready to run our migration.

#### `ecto.migrate`
### `mix ecto.migrate`

Once we have our migration module ready, we can simply run `mix ecto.migrate` to have our changes applied to the database.

Expand Down Expand Up @@ -837,7 +837,7 @@ The `--to` option will behave the same way.
mix ecto.migrate --to 20150317170448
```

#### `ecto.rollback`
### `mix ecto.rollback`

The `ecto.rollback` task will reverse the last migration we have run, undoing the schema changes. `ecto.migrate` and `ecto.rollback` are mirror images of each other.

Expand Down
2 changes: 1 addition & 1 deletion guides/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ defmodule HelloWeb.Endpoint do
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.
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.

Expand Down
8 changes: 4 additions & 4 deletions guides/up_and_running.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ $ mix phx.new hello

> A note about [webpack](https://webpack.js.org/) before we begin: Phoenix will use webpack for asset management by default. Webpacks' dependencies are installed via the node package manager, not mix. Phoenix will prompt us to install them at the end of the `mix phx.new` task. If we say "no" at that point, and if we don't install those dependencies later with `npm install`, our application will raise errors when we try to start it, and our assets may not load properly. If we don't want to use webpack at all, we can simply pass `--no-webpack` to `mix phx.new`.
> A note about [Ecto](https://hexdocs.pm/phoenix/ecto.html): Ecto allows our Phoenix application to communicate with a data store, such as PostgreSQL or MongoDB. If our application will not require this component we can skip this dependency by passing the `--no-ecto` flag to the `mix phx.new`. This flag may also be combined with `--no-webpack` to create a skeleton application.
> A note about [Ecto](https://hexdocs.pm/phoenix/ecto.html): Ecto allows our Phoenix application to communicate with a data store, such as PostgreSQL or MongoDB. If our application will not require this component we can skip this dependency by passing the `--no-ecto` flag to `mix phx.new`. This flag may also be combined with `--no-webpack` to create a skeleton application.
> Note to learn more about `mix phx.new` read [Phoenix Mix Tasks](phoenix_mix_tasks.html).
> To learn more about `mix phx.new` you can read the [Mix Tasks Guide](phoenix_mix_tasks.html#phoenix-specific-mix-tasks).
```console
mix phx.new hello
Expand Down Expand Up @@ -59,7 +59,7 @@ You can also run your app inside IEx (Interactive Elixir) as:

Once our dependencies are installed, the task will prompt us to change into our project directory and start our application.

Phoenix assumes that our PostgreSQL database will have a `postgres` user account with the correct permissions and a password of "postgres". If that isn't the case, please see the instructions for the [ecto.create](phoenix_mix_tasks.html#ecto-specific-mix-tasks) mix task.
Phoenix assumes that our PostgreSQL database will have a `postgres` user account with the correct permissions and a password of "postgres". If that isn't the case, please see the [`Mix Tasks Guide`](phoenix_mix_tasks.html#ecto-specific-mix-tasks) to learn more about the `mix ecto.create` task.

Ok, let's give it a try. First, we'll `cd` into the `hello/` directory we've just created:

Expand All @@ -86,7 +86,7 @@ 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.
If we choose not to have Phoenix install our dependencies when we generate a new application, the `mix phx.new` task will prompt us to take the necessary steps when we do want to install them.

```console
Fetch and install dependencies? [Yn] n
Expand Down

0 comments on commit 39068a5

Please sign in to comment.