Skip to content

Commit

Permalink
add: use_helper to base
Browse files Browse the repository at this point in the history
  • Loading branch information
reeganviljoen committed Jan 21, 2024
1 parent 84210ef commit adc1429
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 5 deletions.
4 changes: 1 addition & 3 deletions docs/guide/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 and is similar in use to using `delegate` on helpers.

```ruby
class UseHelpersComponent < ViewComponent::Base
include ViewComponent::UseHelpers
use_helpers :icon

erb_template <<-ERB
Expand Down
1 change: 1 addition & 0 deletions lib/view_component/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def config
end

include ViewComponent::InlineTemplate
include ViewComponent::UseHelpers
include ViewComponent::Slotable
include ViewComponent::Translatable
include ViewComponent::WithContentHelper
Expand Down
2 changes: 0 additions & 2 deletions test/sandbox/app/components/use_helpers_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

class UseHelpersComponent < ViewComponent::Base
include ViewComponent::UseHelpers

use_helpers :message
end

0 comments on commit adc1429

Please sign in to comment.