Skip to content

Commit

Permalink
Update Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
pulkitkkr committed Jun 29, 2022
1 parent 32e4d3f commit 4e6a46b
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ While this also generally applies to `stylesheet_pack_tag`, you may use multiple
<%= stylesheet_pack_tag 'print', media: 'print' %>
```

#### View Helper `append_javascript_pack_tag`
#### View Helper `append_javascript_pack_tag` and `append_stylesheet_pack_tag`

If you need configure your script pack names from the view for a route or partials, then you will need some logic to ensure you call the helpers only once with multiple arguments. The new view helper `append_javascript_pack_tag` can solve this problem. This helper will queue up script packs when the `javascript_pack_tag` is finally used.
If you need configure your script pack names or stylesheet pack names from the view for a route or partials, then you will need some logic to ensure you call the helpers only once with multiple arguments. The new view helpers, `append_javascript_pack_tag` and `append_stylesheet_pack_tag` can solve this problem. The helper `append_javascript_pack_tag` will queue up script packs when the `javascript_pack_tag` is finally used. Similarly `append_stylesheet_pack_tag` will queue up Style packs when the `stylesheet_pack_tag` is finally used.

Main view:
```erb
Expand All @@ -274,28 +274,7 @@ is the same as using this in the main layout:
<%= javascript_pack_tag 'calendar', 'map', application' %>
```

However, you typically can't do that in the main layout, as the view and partial codes will depend on the route.

Thus, you can distribute the logic of what packs are needed for any route. All the magic of splitting up the code was automatic!

**Important:** `append_javascript_pack_tag` can be used anywhere in your application as long as it is executed BEFORE the `javascript_pack_tag`. If you attempt to call `append_javascript_pack_tag` helper after `javascript_pack_tag`, an error will be raised. You should have only a single `javascript_pack_tag` invocation in your page load.

The typical issue is that your layout might reference some partials that need to configure packs. A good way to solve this problem is to use `content_for` to ensure that the code to render your partial comes before the call to `javascript_pack_tag`.

```erb
<% content_for :footer do
render 'shared/footer' %>
<%= javascript_pack_tag %>
<%= content_for :footer %>
```

For alternative options of setting the additional packs, [see this discussion](https://github.com/shakacode/shakapacker/issues/39).

#### View Helper append_stylesheet_pack_tag
If you need configure your stylesheet pack names from the view for a route or partials, then you will need some logic to ensure you call the helpers only once with multiple arguments. The new view helper append_stylesheet_pack_tag can solve this problem. This helper will queue up packs when the stylesheet_pack_tag is finally used.

Similarly for the stylsheet packs
Main view:
```erb
<% append_stylesheet_pack_tag 'calendar' %>
Expand All @@ -321,6 +300,23 @@ However, you typically can't do that in the main layout, as the view and partial

Thus, you can distribute the logic of what packs are needed for any route. All the magic of splitting up the code was automatic!

**Important:** `append_javascript_pack_tag` can be used anywhere in your application as long as it is executed BEFORE the `javascript_pack_tag`. If you attempt to call `append_javascript_pack_tag` helper after `javascript_pack_tag`, an error will be raised. You should have only a single `javascript_pack_tag` invocation in your page load.

**Important** Similar to `append_javascript_pack_tag`, the `append_stylesheet_pack_tag` should be used anywhere in your application as long as it is executed BEFORE the `stylesheet_pack_tag`. However, for now if you attempt to call `append_stylesheet_pack_tag` helper after `stylesheet_pack_tag`, an error will be *not* be raised.

The typical issue is that your layout might reference some partials that need to configure packs. A good way to solve this problem is to use `content_for` to ensure that the code to render your partial comes before the call to `javascript_pack_tag`.

```erb
<% content_for :footer do
render 'shared/footer' %>
<%= javascript_pack_tag %>
<%= content_for :footer %>
```

For alternative options of setting the additional packs, [see this discussion](https://github.com/shakacode/shakapacker/issues/39).

#### View Helper: `asset_pack_path`

If you want to link a static asset for `<img />` tag, you can use the `asset_pack_path` helper:
Expand Down

0 comments on commit 4e6a46b

Please sign in to comment.