-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor compiler and template to use requested details
- Loading branch information
Showing
11 changed files
with
188 additions
and
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module ViewComponent | ||
# LookupContext computes and encapsulates @details for each request | ||
# so that it doesn't need to be recomputed on each partial render. | ||
# This data is wrapped in ActionView::TemplateDetails::Requested and | ||
# used by instances of ActionView::Resolver to choose which template | ||
# best matches the request. | ||
# | ||
# ActionView considers this logic internal to template/partial resolution. | ||
# We're exposing it to the compiler via `refine` so that ViewComponent | ||
# can match Rails' template picking logic. | ||
module RequestDetails | ||
refine ActionView::LookupContext do | ||
# Return an abstraction for matching and sorting available templates | ||
# based on the current lookup context details. | ||
# | ||
# @return ActionView::TemplateDetails::Requested | ||
# @see ActionView::LookupContext#detail_args_for | ||
# @see ActionView::FileSystemResolver#_find_all | ||
def vc_requested_details(user_details = {}) | ||
# The hash `user_details` would normally be the standard arguments that | ||
# `render` accepts, but there's currently no mechanism for users to | ||
# provide these when calling render on a ViewComponent. | ||
details, cached = detail_args_for(user_details) | ||
cached || ActionView::TemplateDetails::Requested.new(**details) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.