1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

6 commits

Author SHA1 Message Date
John Hawthorn
f8f9a085cc Encapsulate "details" into TemplateDetails
When dealing with the "details" for a template: locale, format,
variant, and handler, previously we would store these in an ad-hoc way
every place we did. Often as a hash or as separate instance variables on
a class.

This PR attempts to simplify this by encapsulating known details on a
template in a new ActionView::TemplateDetails class, and requested
details in ActionView::TemplateDetails::Requested.

This allowed extracting and simplifying filtering and sorting logic from
the Resolver class as well as extracting default format logic from
UnboundTemplate.

As well as reducing complexity, in the future this should make it
possible to provide suggestions on missing template errors due to
mismatched details, and might allow improved performance.

At least for now these new classes are private (:nodoc)

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2021-05-11 18:48:24 -07:00
John Hawthorn
2be8d3ebf8 Store details on unbound template
Previously we just stored handler, format, and variant and assigned a
default format if none existed.

Now we want to also store locale, and move the default format behaviour
into unbound template.
2021-04-20 13:48:12 -07:00
Akira Matsuda
7a563f749d Fix Class#new + keyword arguments warnings 2019-09-09 02:35:59 +09:00
Jean Boussier
bd78d3eecf Fix a minor typo in ActionView::UnboundTemplate 2019-07-19 15:18:57 +02:00
Ryuta Kamizono
c81af6ae72 Enable Layout/EmptyLinesAroundAccessModifier cop
We sometimes say "✂️ newline after `private`" in a code review (e.g.
https://github.com/rails/rails/pull/18546#discussion_r23188776,
https://github.com/rails/rails/pull/34832#discussion_r244847195).

Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style
`EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059).

That cop and enforced style will reduce the our code review cost.
2019-06-13 12:00:45 +09:00
John Hawthorn
1fc735e5f5 De-dup Templates, introduce UnboundTemplate
Previously it's possible to have multiple copies of the "same" Template.
For example, if index.html.erb is found both the :en and :fr locale, it
will return a different Template object for each. The same can happen
with formats, variants, and handlers.

This commit de-duplicates templates, there will now only be one template
per file/virtual_path/locals tuple.

We need to consider virtual_path because both `render "index"`, and
`render "index.html"` can both find the same file but will have
different virtual_paths. IMO this is rare and should be
deprecated/removed, but it exists now so we need to consider it in order
to cache correctly.

This commit introduces a new UnboundTemplate class, which represents a
template with unknown locals. Template objects can be built from it by
using `#with_locals`. Currently, this is just a convenience around
caching templates, but I hope it's a helpful concept that could have
more utility in the future.
2019-04-12 12:30:26 -07:00