# `Igniter.Libs.Phoenix`
[🔗](https://github.com/ash-project/igniter/blob/v0.8.3/lib/igniter/libs/phoenix.ex#L5)

Codemods & utilities for working with Phoenix

# `add_pipeline`

```elixir
@spec add_pipeline(Igniter.t(), atom(), String.t(), Keyword.t()) :: Igniter.t()
```

Adds a pipeline to a Phoenix router.

## Options

* `:router` - The router module to append to. Will be looked up if not provided.
* `:arg2` - The second argument to the scope macro. Must be a value (typically a module).

# `add_scope`

```elixir
@spec add_scope(Igniter.t(), String.t(), String.t(), Keyword.t()) :: Igniter.t()
```

Adds a scope to a Phoenix router.

## Options

- `:router` - The router module to append to. Will be looked up if not provided.
- `:arg2` - The second argument to the scope macro. Must be a value (typically a module).
- `:placement` - `:before` | `:after`. Determines where the `contents` will be placed:
  - `:before` - place before the first scope in the module if one is found, otherwise tries to place
     after the last pipeline or after the `use MyAppWeb, :router` call.
  - `:after` - place at the end (bottom) of the module, after all scopes and pipelines.

# `append_to_pipeline`

```elixir
@spec append_to_pipeline(Igniter.t(), atom(), String.t(), Keyword.t()) :: Igniter.t()
```

Appends code to a Phoenix router pipeline.

## Options

* `:router` - The router module to append to. Will be looked up if not provided.

# `append_to_scope`

```elixir
@spec append_to_scope(Igniter.t(), String.t(), String.t(), Keyword.t()) :: Igniter.t()
```

Appends to a phoenix router scope.

Relatively limited currently only exact matches of a top level route, second argument, and pipelines.

## Options

* `:router` - The router module to append to. Will be looked up if not provided.
* `:arg2` - The second argument to the scope macro. Must be a value (typically a module).
* `:with_pipelines` - A list of pipelines that the pipeline must be using to be considered a match.
- `:placement` - `:before` | `:after`. Determines where the `contents` will be placed. Note that it first tries
  to find a matching scope and place the contents into that scope, otherwise `:placement` is used to determine
  where to place the contents:
  * `:before` - place before the first scope in the module if one is found, otherwise tries to place
     after the last pipeline or after the `use MyAppWeb, :router` call.
  * `:after` - place at the end (bottom) of the module, after all scopes and pipelines.

# `controller?`

```elixir
@spec controller?(Igniter.t(), module()) :: boolean()
```

Returns `true` if the module is a Phoenix controller

# `endpoints_for_router`

```elixir
@spec endpoints_for_router(igniter :: Igniter.t(), router :: module()) ::
  {Igniter.t(), [module()]}
```

Gets the list of endpoints that use a given router

# `has_pipeline`

```elixir
@spec has_pipeline(Igniter.t(), router :: module(), name :: atom()) ::
  {Igniter.t(), boolean()}
```

Returns `{igniter, true}` if a pipeline exists in a Phoenix router, and `{igniter, false}` otherwise.

## Options

* `:router` - The router module to append to. Will be looked up if not provided.
* `:arg2` - The second argument to the scope macro. Must be a value (typically a module).

# `html?`

```elixir
@spec html?(Igniter.t(), module()) :: boolean()
```

Returns `true` if the module is a Phoenix HTML module

# `list_routers`

```elixir
@spec list_routers(Igniter.t()) :: {Igniter.t(), [module()]}
```

Lists all routers found in the project.

# `list_web_modules`

```elixir
@spec list_web_modules(Igniter.t()) :: {Igniter.t(), [module()]}
```

Lists all web modules found in the project.

A web module is defined as:
- Only one level of namespace deep (e.g., `FooWeb` not `Foo.BarWeb`)
- Ends with `Web`

# `move_to_router_use`

```elixir
@spec move_to_router_use(Igniter.t(), Sourceror.Zipper.t()) ::
  :error | {:ok, Sourceror.Zipper.t()}
```

Moves to the use statement in a module that matches `use <WebModule>, :router`

# `prepend_to_pipeline`

```elixir
@spec prepend_to_pipeline(Igniter.t(), atom(), String.t(), Keyword.t()) :: Igniter.t()
```

Prepends code to a Phoenix router pipeline.

## Options

* `:router` - The router module to append to. Will be looked up if not provided.

# `select_endpoint`

```elixir
@spec select_endpoint(Igniter.t(), module() | nil, String.t()) ::
  {Igniter.t(), module() | nil}
```

Selects an endpoint to be used in a later step. If only one endpoint is found, it will be selected automatically.

If no endpoints exist, `{igniter, nil}` is returned.

If multiple endpoints are found, the user is prompted to select one of them.

# `select_router`

```elixir
@spec select_router(Igniter.t(), String.t()) :: {Igniter.t(), module() | nil}
```

Selects a router to be used in a later step. If only one router is found, it will be selected automatically.

If no routers exist, `{igniter, nil}` is returned.

If multiple routes are found, the user is prompted to select one of them.

# `web_module`

```elixir
@spec web_module(Igniter.t()) :: module()
```

Returns the web module name for the current app

# `web_module?`

```elixir
@spec web_module?(module() | String.t()) :: boolean()
```

Checks if a module is a valid web module.

A web module is defined as:
- Only one level of namespace deep (e.g., `FooWeb` not `Foo.BarWeb`)
- Ends with `Web`

Accepts both atoms and strings.

# `web_module_for_router`

```elixir
@spec web_module_for_router(Igniter.t(), module()) :: {Igniter.t(), module()}
```

Returns the web module that the given `router` belongs to.

Reads the router's `use <WebModule>, :router` declaration, which is the module
that generated modules (`use <WebModule>, :controller`, `:verified_routes`,
etc.) should reference. This lets installers place generated modules alongside
the selected router rather than assuming the application's default web module.

Falls back to `web_module/1` when the router uses `Phoenix.Router` directly or
cannot be found.

# `web_module_name`

> This function is deprecated. Use `web_module/0` instead..

```elixir
@spec web_module_name() :: module()
```

Returns the web module name for the current app

# `web_module_name`

> This function is deprecated. Use `web_module_name/2` instead..

```elixir
@spec web_module_name(String.t()) :: module()
```

Generates a module name that lives in the Web directory of the current app.

# `web_module_name`

```elixir
@spec web_module_name(Igniter.t(), String.t()) :: module()
```

Generates a module name that lives in the Web directory of the current app.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
