-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
View helper methods #5493
Open
gardnerapp
wants to merge
7
commits into
heartcombo:main
Choose a base branch
from
gardnerapp:view-helper-methods
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
View helper methods #5493
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5ba0475
Finish writing module & adding methods during generation
be0e75d
extend view_helpers to AV
66ec3e6
Rename methods and add comments explaining their usage
610bb3c
Finish Inclusion Test of Devise::Views::Helpers in ::ActionView
1784107
Finish testing include of Devise::Views::Helpers into ActionController
27ca9d6
Correct error in {mapping}_signed_out
a701476
fix spelling err
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
view-helpers-method-test branch, notes in views test files |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Devise | ||
module Views | ||
module Helpers | ||
|
||
# Generates helpers that do something based on mappings authentication status, | ||
# thereby avoiding the use of repetitive if/else blocks | ||
# | ||
# Generated Methods => signed_in_user & signed_out_user | ||
# | ||
# signed_in_user do | ||
# <h1>Hello <%= @user.name %> </h1> | ||
# end | ||
# | ||
# signed_out_user do | ||
# <%= link_to "Sign In", new_user_session_path %> | ||
# end | ||
# | ||
# These methods can also be used at the controller level: | ||
# | ||
# def some_action | ||
# signed_in_user {render @users} | ||
# signed_out_user {redirect_to root_path} | ||
# end | ||
|
||
def self.define_helpers(mapping) | ||
mapping = mapping.name | ||
class_eval <<-METHODS, __FILE__, __LINE__ + 1 | ||
def signed_in_#{mapping}(&block) | ||
block.call if #{mapping}_signed_in? | ||
end | ||
|
||
def signed_out_#{mapping}(&block) | ||
block.call unless #{mapping}_signed_in? | ||
end | ||
METHODS | ||
end | ||
end | ||
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
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,22 @@ | ||
# frozen_string_literal: true | ||
require 'test_helper' | ||
|
||
module ActionView | ||
include Devise::Views::Helpers | ||
end | ||
|
||
class ViewsHelperMethodsTest < Devise::IntegrationTest | ||
|
||
test 'Action View includes Devise::Views::Helpers' do | ||
assert_includes ActionView.ancestors, Devise::Views::Helpers | ||
end | ||
|
||
test 'ActionView defines signed_in_user' do | ||
assert ActionView.instance_methods.include?(:signed_in_user) | ||
end | ||
|
||
test 'ActionView defines signed_out_user' do | ||
assert ActionView.instance_methods.include?(:signed_out_user) | ||
end | ||
|
||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get this pulled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the review. Could we get this pull request submitted?