-
Notifications
You must be signed in to change notification settings - Fork 22.1k
Variants in ActionView::Digestor #14243
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
Conversation
|
Implementation & test look good to me. It breaks |
|
That was my concern too, but Digestor this kinda is a breaking change anyway. If someone is using variants, the digestor is broken if not configured to deal with it. So this seems like a better way to fail early. On Mar 1, 2014, at 20:25, Jeremy Kemper [email protected] wrote:
|
|
Good point, haven't thought about it to be honest. What about changing format argument into format_or_options, having What do you think? On Saturday, March 1, 2014, David Heinemeier Hansson <
|
|
IMO it sucks to have a breaking change, but IMO this isn’t something most people extended in their own app, and even if they did, the variant feature will simply be silently broken unless this is changed. I don’t like breaking shit more than anyone, but imo it’s preferable to break stuff loud and clear, than to have silently corrupt digests that’ll be a bitch to debug (took me a while to find the problem on Basecamp!). On Mar 1, 2014, at 21:04, Łukasz Strzałkowski [email protected] wrote:
|
|
Completely agree. What I was thinking about was not to break things here I'm away from computer at the moment. I'll work on this tomorrow and show On Saturday, March 1, 2014, David Heinemeier Hansson <
|
|
We could also put |
|
Def agree that it should be fixed. However, can it be fixed in a way that won't require a breaking change next time the method signature the needs to change? Good sign we should be passing an a template "descriptor" instead, like a hash of Also, adding variant will blow all fragment caches in apps that don't use variants yet. Can we preserve the same cache key when variant is nil? |
|
Alternative implementation using a 'descriptor' array instead of wdyt? Nil variants are ignored, so existing fragment caches should be preserved. |
|
What I don’t like is if whatever we do doesn’t fail fast when variants are used. Changing the API signature is obviously fail fast, but that also hits people who aren’t using variants. Preferably we’d only fail fast when variants are used. But if the choice is between silent failure and fail fast even when variants are not used, I’d pick the latter. On Mar 2, 2014, at 0:36, Piotr Chmolowski [email protected] wrote:
|
|
We can also do something like this: def digest(*args)
options = {}
unless args.first.is_a?(Hash)
ActiveSupport::Deprecation.warn("...")
options = {
name: args.first,
format: args.second,
finder: args.third,
}.merge(args.fourth || {})
else
options = args.first
end
# ...
endEverybody will be happy. Old API will still work, we'll transition to more flexible, hash based one, for the future and kill deprecated one in 5.x release or 4.2. |
|
Yeah, it would be nice if people who aren’t using variants can just keep on trucking. Just want to make sure that we are loud about it in the logs that whatever they’re doing will fail with variants if they don’t change. So let’s try this! On Mar 3, 2014, at 2:45 PM, Łukasz Strzałkowski [email protected] wrote:
|
|
I've updated the code, implementing your suggestions. Please let me know what you think. |
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.
We should add a documentation section describing the options here.
|
Code looking good to me. Any comments, @jeremy? Just need a little documentation. |
|
When do we plan to remove support for old API? 4.2 or 5.0? I think it would be worth to put this information in both changelog notes and deprecation warning message. |
|
I'd say 5.0. |
|
Travis says the build failed. Have you run all the tests with this in place? Eager to merge. |
|
Fleaky memcached test - connection failure. Let's wait for rebuild which I've just triggered, should be green. |
|
Sorry, didn't notice. Everything seemed fine locally - will look into it. |
|
Ah, cools. I’ll merge, then. Thanks again for working on this! On Mar 4, 2014, at 2:44 PM, Piotr Chmolowski [email protected] wrote:
|
|
Good to go, it's green again, @pch could you please rebase your branch? |
Take variants into account when calculating template digests in ActionView::Digest. Digestor#digest now takes a hash as an argument to support variants and allow more flexibility in the future. Old-style arguments have been deprecated. Fixes #14242
|
Done. |
|
Hmm, looks like something is still busted.
doesn't actually seem to return the right template. It ignores the variants. Did you guys look at LookupContext to ensure that this would work? |
|
Problem is that when I ask for a variant of a template that also has a non-variant form, I get the non-variant form back. |
|
ActionView::ViewPaths doesn't seem to know anything about variants. And we're also not recording a #rendered_variant in the LookupContext. The PartialRenderer also doesn't seem to be aware of variants. |
|
Thanks for heads up. I'll work on this today. On Wednesday, March 5, 2014, David Heinemeier Hansson <
|
Even though I have |
|
@dhh could you paste you view paths here? So far, I've only managed to figure out that the following order seems to pick both desktop & phone versions: but when you prepend |
|
More examples: The Dir["/Users/piotrek/test-app/app/views/desktop/messages/show{.en,}{.html,}{+phone,}{.erb,.builder,.raw,.ruby,.jbuilder,.coffee,}"]
#=> ["/Users/piotrek/test-app/app/views/desktop/messages/show.html.erb"]Variant is optional here, so the next directory in line ( (If I understand correctly) |
|
Hmm. Preferably order shouldn’t matter. They should search all of these view paths before selecting. Not just the first good enough match. On Mar 8, 2014, at 5:59 PM, Piotr Chmolowski [email protected] wrote:
|
|
It seems to be the case for language versions as well: prepend_view_path Rails.root.join("app/views/phone")
prepend_view_path Rails.root.join("app/views/desktop")In this case |
|
Yeah, that’s no bueno. But first things first. Let’s make sure the current path, as it exists for the renderer, is right for digester too. Then let’s fix the ordering problem. On Mar 8, 2014, at 9:46 PM, Piotr Chmolowski [email protected] wrote:
|
Take variants into account when calculating template digests in ActionView::Digestor
Fixes #14242