diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index ac8b75ffb..09a91fff1 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,10 @@ nav_order: 5 ## main +* Include ViewComponent::UseHelpers by default. + + *Reegan Viljoen* + * Bump `puma` in Gemfile.lock. *Cameron Dutro* diff --git a/docs/guide/helpers.md b/docs/guide/helpers.md index 172c3aea0..495277f2b 100644 --- a/docs/guide/helpers.md +++ b/docs/guide/helpers.md @@ -55,12 +55,10 @@ end By default, ViewComponents don't have access to helper methods defined externally. The `use_helpers` method allows external helpers to be called from the component. -To use the `use_helpers` method, include `ViewComponent::UseHelpers`. -`UseHelpers` defines the helper on the component and is similar in use to using `delegate` on helpers. +`use_helpers` defines the helper on the component, similar to `delegate`: ```ruby class UseHelpersComponent < ViewComponent::Base - include ViewComponent::UseHelpers use_helpers :icon erb_template <<-ERB diff --git a/lib/view_component/base.rb b/lib/view_component/base.rb index 49e3ffd14..78bfe56d3 100644 --- a/lib/view_component/base.rb +++ b/lib/view_component/base.rb @@ -28,6 +28,7 @@ def config end include ViewComponent::InlineTemplate + include ViewComponent::UseHelpers include ViewComponent::Slotable include ViewComponent::Translatable include ViewComponent::WithContentHelper diff --git a/test/sandbox/app/components/use_helpers_component.rb b/test/sandbox/app/components/use_helpers_component.rb index 375c07db6..a83bd2e16 100644 --- a/test/sandbox/app/components/use_helpers_component.rb +++ b/test/sandbox/app/components/use_helpers_component.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true class UseHelpersComponent < ViewComponent::Base - include ViewComponent::UseHelpers - use_helpers :message end