Skip to content

Commit

Permalink
Update Changelog, Docs and Error Message (shakacode#153)
Browse files Browse the repository at this point in the history
* Update documentation for `append_(javascript/stylesheet)_pack_tag`
* Update Warning Texts to have Links
  • Loading branch information
pulkitkkr authored Jul 1, 2022
1 parent 184ab84 commit 3473ce1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
## [Unreleased]
Changes since last non-beta release.

- Added `append_stylesheet_pack_tag` helper, which is required for filesystem-based automated Component Registry API on React-on-Rails.
### Added
- `append_stylesheet_pack_tag` helper. It helps in configuring stylesheet pack names from the view for a route or partials. It is also required for filesystem-based automated Component Registry API on React on Rails gem. [PR 144](https://github.com/shakacode/shakapacker/pull/144) by [pulkitkkr](https://github.com/pulkitkkr).

_Please add entries here for your pull requests that are not yet released._

Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,8 @@ 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 and CSS 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:** Both `append_(javascript/stylesheet)_pack_tag` helpers can be used anywhere in your application as long as they are executed BEFORE `(javascript/stylesheet)_pack_tag` respectively. If you attempt to call one of the `append_(javascript/stylesheet)_pack_tag` helpers after the respective `(javascript/stylesheet)_pack_tag`, an error will be raised.

**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, 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
Expand Down
6 changes: 3 additions & 3 deletions lib/webpacker/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def favicon_pack_tag(name, **options)
def javascript_pack_tag(*names, defer: true, **options)
if @javascript_pack_tag_loaded
raise "To prevent duplicated chunks on the page, you should call javascript_pack_tag only once on the page. " \
"Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#usage for the usage guide"
"Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helpers-javascript_pack_tag-and-stylesheet_pack_tag for the usage guide"
end

append_javascript_pack_tag(*names, defer: defer)
Expand Down Expand Up @@ -169,7 +169,7 @@ def stylesheet_pack_tag(*names, **options)
def append_stylesheet_pack_tag(*names)
if @stylesheet_pack_tag_loaded
raise "You can only call append_stylesheet_pack_tag before stylesheet_pack_tag helper. " \
"Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#usage for the usage guide"
"Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
end

@stylesheet_pack_tag_queue ||= []
Expand All @@ -179,7 +179,7 @@ def append_stylesheet_pack_tag(*names)
def append_javascript_pack_tag(*names, defer: true)
if @javascript_pack_tag_loaded
raise "You can only call append_javascript_pack_tag before javascript_pack_tag helper. " \
"Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#usage for the usage guide"
"Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide"
end

hash_key = defer ? :deferred : :non_deferred
Expand Down
4 changes: 2 additions & 2 deletions test/helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_append_javascript_pack_tag_raises

assert_equal \
"You can only call append_javascript_pack_tag before javascript_pack_tag helper. " +
"Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#usage for the usage guide",
"Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helper-append_javascript_pack_tag-and-append_stylesheet_pack_tag for the usage guide",
error.message
end

Expand Down Expand Up @@ -161,7 +161,7 @@ def test_javascript_pack_tag_multiple_invocations

assert_equal \
"To prevent duplicated chunks on the page, you should call javascript_pack_tag only once on the page. " +
"Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#usage for the usage guide",
"Please refer to https://github.com/shakacode/shakapacker/blob/master/README.md#view-helpers-javascript_pack_tag-and-stylesheet_pack_tag for the usage guide",
error.message
end

Expand Down

0 comments on commit 3473ce1

Please sign in to comment.