-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Introduce a file type template #35119
Conversation
0869f7d
to
64bb1f2
Compare
64bb1f2
to
8401df7
Compare
@compiled = true | ||
end | ||
end | ||
|
||
class LegacyTemplate < DelegateClass(Template) # :nodoc: |
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.
What is the plan to this class? We will always have a LegacyTemplate or we plan to remove it some day?
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.
I think we can remove it eventually. I want to change this call to pass in the view and the source. But for backwards compatibility we need to pass an object that has a reference to the mutated source.
I'll follow up with another commit that deprecates arity one blocks
Every template that specifies a "virtual path" loses the template source when the template gets compiled: https://github.com/rails/rails/blob/eda0f574f129fcd5ad1fc58b55cb6d1db71ea95c/actionview/lib/action_view/template.rb#L275 The "refresh" method seems to think that the source code for a template can be recovered if there is a virtual path: https://github.com/rails/rails/blob/eda0f574f129fcd5ad1fc58b55cb6d1db71ea95c/actionview/lib/action_view/template.rb#L171-L188 Every call site that allocates a template object *and* provides a "virtual path" reads the template contents from the filesystem: https://github.com/rails/rails/blob/eda0f574f129fcd5ad1fc58b55cb6d1db71ea95c/actionview/lib/action_view/template/resolver.rb#L229-L231 Templates that are inline or literals don't provide a "virtual path": https://github.com/rails/rails/blob/eda0f574f129fcd5ad1fc58b55cb6d1db71ea95c/actionview/lib/action_view/renderer/template_renderer.rb#L34 This commit introduces a `FileTemplate` type that subclasses `Template`. The `FileTemplate` keeps a reference to the filename, and reads the source from the filesystem. This effectively makes the template source immutable. Other classes depended on the source to be mutated while being compiled, so this commit also introduces a temporary way to pass the mutated source to the ERB (or whatever) compiler. See `LegacyTemplate`. I think we should consider it an error to provide a virtual path on a non file type template an non-file templates can't recover their source. Here is an example: https://github.com/rails/rails/blob/eda0f574f129fcd5ad1fc58b55cb6d1db71ea95c/actionview/lib/action_view/testing/resolvers.rb#L53 This provides a "virtual path" so the source code (a string literal) is thrown away after compilation. Clearly we can't recover that string, so I think this should be an error.
8401df7
to
2169bd3
Compare
Template#refresh
I changed this to not deprecate rails/actionview/lib/action_view/testing/resolvers.rb Lines 26 to 47 in 2169bd3
After this PR, the common case will be to instantiate |
Ah right. This is something we support and José's book talk about it in the "Retrieving View Templates from Custom Stores" chapter https://pragprog.com/book/jvrails2/crafting-rails-4-applications |
This commit passes the mutated source to the template handler as a parameter and deprecates the old handlers. Old handlers required that templates contain a reference to mutated source code, but we would like to make template objects "read only". This change lets the template remain "read only" while still giving template handlers access to the source code after mutations.
fb811c6
to
28f88e0
Compare
- `ActionView::Handlers#call` now needs to accept the `template` and `source` as arguments. Change in this patch is backward compatible - Change upstream rails/rails#35119
While upgrading to Rails 6.0 I'm getting warning:
which is not really clear where to find it. I suspect some gem, as I don't mess with templates in the app. |
Single-arity template handlers are deprecated as of Rails 6. rails/rails#35119
Single-arity template handlers are deprecated as of Rails 6. rails/rails#35119
I have the same question. I am now updating our rails app and getting the same message but cannot find anywhere this might affect our app. (We also do not use templates outside of the devise gem.) |
Setting I think the code that tries to extract the culprit from the backtrace could be doing a better job here. |
This fixes compatibility with ActionView 6.0.0+, whic deprecated old style template handlers [[1]]. Fixes alexrothenberg#61. [1]: rails/rails#35119
See rails/rails#35119 for details about the change to `Curlybars::TemplateHandler.call`.
See rails/rails#35119 for details about the change to `Curlybars::TemplateHandler.call`.
See rails/rails#35119 for details about the change to `Curlybars::TemplateHandler.call`.
See rails/rails#35119 for details about the change to `Curlybars::TemplateHandler.call`.
Every template that specifies a "virtual path" loses the template source
when the template gets compiled:
rails/actionview/lib/action_view/template.rb
Line 275 in eda0f57
The "refresh" method seems to think that the source code for a template
can be recovered if there is a virtual path:
rails/actionview/lib/action_view/template.rb
Lines 171 to 188 in eda0f57
Every call site that allocates a template object and provides a
"virtual path" reads the template contents from the filesystem:
rails/actionview/lib/action_view/template/resolver.rb
Lines 229 to 231 in eda0f57
Templates that are inline or literals don't provide a "virtual path":
rails/actionview/lib/action_view/renderer/template_renderer.rb
Line 34 in eda0f57
This commit introduces a
FileTemplate
type that subclassesTemplate
.The
FileTemplate
keeps a reference to the filename, and reads thesource from the filesystem. This effectively makes the template source
immutable.
Other classes depended on the source to be mutated while being compiled,
so this commit also introduces a temporary way to pass the mutated
source to the ERB (or whatever) compiler. See
LegacyTemplate
.I think we should consider it an error to provide a virtual path on a
non file type template an non-file templates can't recover their source.
Here is an example:
rails/actionview/lib/action_view/testing/resolvers.rb
Line 53 in eda0f57
This provides a "virtual path" so the source code (a string literal) is
thrown away after compilation. Clearly we can't recover that string, so
I think this should be an error.