Skip to content

Commit

Permalink
Merge pull request #76 from avo-hq/feature/eject_components
Browse files Browse the repository at this point in the history
feature: eject components & eject partial new syntax
  • Loading branch information
Paul-Bob authored Aug 8, 2023
2 parents 98f1a26 + 025eb4b commit 4be8827
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
6 changes: 3 additions & 3 deletions docs/3.0/custom-asset-pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Avo supports the other bundlers too but we just don't have a generator command t

## Manually add your CSS and JS assets

In order to manually add your assets you have to eject the `_pre_head.html.erb` partial (`bin/rails generate avo:eject :pre_head`), create the asset files (examples below), and add the asset files from your pipeline to the `_pre_head` partial. Then, your asset pipeline will pick up those assets and use add them to your app.
In order to manually add your assets you have to eject the `_pre_head.html.erb` partial (`bin/rails generate avo:eject --partial :pre_head`), create the asset files (examples below), and add the asset files from your pipeline to the `_pre_head` partial. Then, your asset pipeline will pick up those assets and use add them to your app.

:::warning
You should add your custom styles to `_pre_head.html.erb`, versus `_head.html.erb` to avoid overriding Avo's default styles. This
Expand All @@ -124,7 +124,7 @@ The order in which Avo loads the partials and asset files is this one:
### Sprockets and Propshaft

Create `avo.custom.js` and `avo.custom.css` inside `app/assets/javascripts` and `app/assets/stylesheets` with the desired scripts and styles.
Then add them to Avo using the `_pre_head.html.erb` partial (`rails generate avo:eject :pre_head`).
Then add them to Avo using the `_pre_head.html.erb` partial (`rails generate avo:eject --partial :pre_head`).

```erb
# app/views/avo/partials/_pre_head.html.erb
Expand All @@ -148,7 +148,7 @@ Instructions below are for Webpacker version 6. Version 5 has different paths (`
:::

Create `avo.custom.js` and `avo.custom.css` inside `app/packs/entrypoints` with the desired scripts and styles.
Then add them to Avo using the `_pre_head.html.erb` partial (`rails generate avo:eject :pre_head`).
Then add them to Avo using the `_pre_head.html.erb` partial (`rails generate avo:eject --partial :pre_head`).

```erb
# app/views/avo/partials/_pre_head.html.erb
Expand Down
59 changes: 51 additions & 8 deletions docs/3.0/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,25 @@ The `_current_user` variable holds what gets resolved from the [`current_user_me

You can access the context data with `::Avo::App.context` object.

## Eject views
## Eject

If you want to change one of Avo's built-in views, you can eject it, update it and use it in your admin.
If you want to change one of Avo's built-in views, you can eject it, update it and use it in your admin panel.

:::warning
Once ejected, the views will not receive updates on new Avo releases. You must maintain them yourself.
:::

:::option `--partial`
Utilize the `--partial` option when you intend to extract certain partial

### Prepared templates

We prepared a few templates to make it.
We prepared a few templates to make it easier for you.

`bin/rails generate avo:eject :logo` will eject the `_logo.html.erb` partial.
`bin/rails generate avo:eject --partial :logo` will eject the `_logo.html.erb` partial.

```
▶ bin/rails generate avo:eject :logo
▶ bin/rails generate avo:eject --partial :logo
Running via Spring preloader in process 20947
create app/views/avo/logo/_logo.html.erb
```
Expand Down Expand Up @@ -200,12 +207,48 @@ The `_scripts.html.erb` partial enables you to insert scripts in the footer of y
You can eject any partial from Avo using the partial path.

```
▶ bin/rails generate avo:eject app/views/layouts/avo/application.html.erb
▶ bin/rails generate avo:eject --partial app/views/layouts/avo/application.html.erb
create app/views/layouts/avo/application.html.erb
```
:::

:::option `--component`
You can eject any view component from Avo using the `--component` option.

```bash
$ bin/rails generate avo:eject --component Avo::Index::TableRowComponent
```
or

```bash
$ bin/rails generate avo:eject --component avo/index/table_row_component
```

Have the same output:
```bash
create app/components/avo/index/table_row_component.rb
create app/components/avo/index/table_row_component.html.erb
```

:::option `--scope`
When you opt to eject a view component that exists under `Avo::Views` namespace, for example the `Avo::Views::ResourceIndexComponent` you can employ the `--scope` option to specify the namespace that should be adopted by the ejected component, extending from `Avo::Views`.

```bash
$ rails g avo:eject --component Avo::Views::ResourceIndexComponent --scope admins
create app/components/avo/views/admins/resource_index_component.rb
create app/components/avo/views/admins/resource_index_component.html.erb
```

The ejected file have the same code that original `Avo::Views::ResourceIndexComponent` but you can notice that the class name has changed

```ruby
class Avo::Views::Admins::ResourceIndexComponent < Avo::ResourceComponent
```

:::info Scopes transformation
`--scope users_admins` -> `Avo::Views::UsersAdmins::ResourceIndexComponent`<br>
`--scope users/admins` -> `Avo::Views::Users::Admins::ResourceIndexComponent`

:::warning
Once ejected, the views will not receive updates on new Avo releases. You must maintain them yourself.
:::

## Breadcrumbs
Expand Down
4 changes: 2 additions & 2 deletions docs/3.0/menu-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ end

## Custom content in the profile menu

You might, however, wnat to add a very custom form or more items to the profile menu. For that we prepared the `_profile_menu_extra.html.erb` partial for you.
You might, however, want to add a very custom form or more items to the profile menu. For that we prepared the `_profile_menu_extra.html.erb` partial for you.

```bash
bin/rails generate avo:eject :profile_menu_extra
bin/rails generate avo:eject --partial :profile_menu_extra
```

This will eject the partial and you can add whatever custom content you might need.
Expand Down

0 comments on commit 4be8827

Please sign in to comment.