# Generators

## Generators

### mix petal.gen.live

This produces the same files as Phoenix's `mix phx.gen.live` ([docs](https://hexdocs.pm/phoenix/Mix.Tasks.Phx.Gen.Live.html)). The only difference is that the templates use Tailwind and Petal Components. You can try it out with:&#x20;

```
mix petal.gen.live Todos Todo todos label:string is_done:boolean
```

Add the routes from the output.&#x20;

{% hint style="info" %}
If you're wondering where to put the routes, you can search in the router file for the text "page\_builder:live:protected", and add them straight after that line.
{% endhint %}

```elixir
def PetalProWeb.Router do
  ...

  scope "/", PetalProWeb do
    pipe_through [
      :browser,
      :require_authenticated_user,
      :kick_user_if_suspended_or_deleted,
      :onboard_new_users
    ]
    
    live_session :require_authenticated_user,
      on_mount: {PetalProWeb.UserOnMountHooks, :require_authenticated_user} do
      ...
      
      # page_builder:live:protected
      live "/todos", TodoLive.Index, :index
      live "/todos/new", TodoLive.Index, :new
      live "/todos/:id/edit", TodoLive.Index, :edit
    
      live "/todos/:id", TodoLive.Show, :show
      live "/todos/:id/show/edit", TodoLive.Show, :edit
    end
  end
  ...
end
```

![After running the generator: the "index" screen](https://content.gitbook.com/content/HHjyspJsNlFy25BeBYYU/blobs/sSGt6CcEytsBfF61VWWj/image.png)

![The "new todo" screen](https://content.gitbook.com/content/HHjyspJsNlFy25BeBYYU/blobs/X6zP9AmUfA7Vtd0oNtep/image.png)

![After creating a new todo](https://content.gitbook.com/content/HHjyspJsNlFy25BeBYYU/blobs/Y6B9td8W1XZyiZI6e6FF/image.png)

![The "show" page](https://content.gitbook.com/content/HHjyspJsNlFy25BeBYYU/blobs/hoD9fMxOhFi43TFPQhWE/image.png)

### mix petal.gen.html

Same file output as `phx.gen.html` ([docs](https://hexdocs.pm/phoenix/Mix.Tasks.Phx.Gen.Html.html)), but uses Petal Components and a layout from Pro.

Example:

```
mix petal.gen.html Todos Todo todos label:string is_done:boolean
```
