-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add from to use_helpers to add macro like syntax (#2034)
* add: helpers macro * refactor helpers macro * refactor helpers macro * add: kwargs tests * add: documentation * add: changelog entry * add: block test and use_helper singular method * fix: ruby2_keywords warnings * add: singular documentation * fix: linting * fix: linting * fix: lint * refactor: code * fix rails main tests * fix: linting * fix linting * fix: linting * Apply suggestions from code review --------- Co-authored-by: Joel Hawksley <joel@hawksley.org> Co-authored-by: Joel Hawksley <joelhawksley@github.com>
- Loading branch information
1 parent
e0dba0b
commit 2c19936
Showing
12 changed files
with
172 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
test/sandbox/app/components/use_helper_macro_component.html copy.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class='helper__message'> | ||
<%= message %> | ||
</div> | ||
|
||
<div class='helper__args-message'> | ||
<%= message_with_args('macro helper method') %> | ||
</div> | ||
|
||
<div class='helper__kwargs-message'> | ||
<%= message_with_kwargs(name: 'macro kwargs helper method') %> | ||
</div> | ||
|
||
<div class='helper__block-message'> | ||
<%= block_content %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class UseHelperMacroComponent < ViewComponent::Base | ||
use_helper :message, from: MacroHelper | ||
use_helper :message_with_args, from: MacroHelper | ||
use_helper :message_with_kwargs, from: MacroHelper | ||
use_helper :message_with_block, from: MacroHelper | ||
|
||
def block_content | ||
message_with_block { "Hello block helper method" } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
class UseHelpersComponent < ViewComponent::Base | ||
use_helpers :message | ||
use_helper :message | ||
end |
15 changes: 15 additions & 0 deletions
15
test/sandbox/app/components/use_helpers_macro_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class='helper__message'> | ||
<%= message %> | ||
</div> | ||
|
||
<div class='helper__args-message'> | ||
<%= message_with_args('macro helper method') %> | ||
</div> | ||
|
||
<div class='helper__kwargs-message'> | ||
<%= message_with_kwargs(name: 'macro kwargs helper method') %> | ||
</div> | ||
|
||
<div class='helper__block-message'> | ||
<%= block_content %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class UseHelpersMacroComponent < ViewComponent::Base | ||
use_helpers :message, :message_with_args, :message_with_kwargs, :message_with_block, from: MacroHelper | ||
|
||
def block_content | ||
message_with_block { "Hello block helper method" } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module MacroHelper | ||
def message | ||
"Hello helper method" | ||
end | ||
|
||
def message_with_args(name) | ||
"Hello #{name}" | ||
end | ||
|
||
def message_with_kwargs(name:) | ||
"Hello #{name}" | ||
end | ||
|
||
def message_with_block | ||
yield | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters