Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add from to use_helpers to add macro like syntax #2034

Merged
merged 23 commits into from
Jun 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add: documentation
  • Loading branch information
reeganviljoen committed May 27, 2024
commit d63f5b4dc3ac735ae7026c06e2e1555271a8547d
12 changes: 12 additions & 0 deletions docs/guide/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@
end
```

Methods defined in helper modules that are not available in the component can be included individually using the `from:` keyword:

Check failure on line 72 in docs/guide/helpers.md

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Microsoft.Contractions] Use 'aren't' instead of 'are not'. Raw Output: {"message": "[Microsoft.Contractions] Use 'aren't' instead of 'are not'.", "location": {"path": "docs/guide/helpers.md", "range": {"start": {"line": 72, "column": 40}}}, "severity": "ERROR"}

```ruby
class UserComponent < ViewComponent::Base
use_helpers :icon, from: IconHelper
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it would make sense to support the singular form use_helper as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Spone I have added this recommendation, as it seems like a great fit


def profile_icon
icon :user
end
end
```

## Nested URL helpers

Rails nested URL helpers implicitly depend on the current `request` in certain cases. Since ViewComponent is built to enable reusing components in different contexts, nested URL helpers should be passed their options explicitly:
Expand Down
Loading