WIP: Use ActionView::TemplateDetails for template priority ordering #2145
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.
What are you trying to accomplish?
Uses ActionView::TemplateDetails to generate ordering for prioritising templates based on the request/response configuration. See #2128 for details.
What approach did you choose and why?
Using the ActionView::TemplateDetails sort ordering when there are multiple formats. This approach generates a per-request priority array for each template, then sorts the template by the priority order. For example:
In this situation, the format parameter is restricted to turbo_stream, html, or unset (nil), so the jbuilder templates are excluded. The locales are the same (unspecified) so the second term is not relevant. Finally, the phone variant is chosen because the phone variant parameter (0) is lower than the admin variant (1) or the unspecified variant (2). In this situation the handler priority doesn't matter.
Anything you want to highlight for special attention from reviewers?
Two failing tests:
TODO:
__vc_variant
– this approach is limited as it only supports one variant instead of the intended cascade__vc_request
which bakes the request format in to the response, instead of using the allow header