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
Created a Raw handler for templates. #6309
Conversation
|
Thanks @steveklabnik ! This looks great except the template is never being registered. So nobody can render it with a |
|
I will do that later today. |
|
Turns out I have a spare ten minutes here... I've amended the commit to include the registration, but since there aren't any tests about the registration so far, I'm not sure how to write it. Any hints? |
|
Well, I would just create a template with raw extension in the fixtures directory and render it by path. |
|
Maybe something like this: https://github.com/rails/rails/blob/master/actionpack/test/template/render_test.rb#L78 |
|
Awesome, give me a few hours. Thanks for the help. |
|
Okay, so I've added that test. But there are... 505 tests that throw this deprecation notice now. Ouch. I'm guessing it probably shouldn't output that, huh? |
|
Yes, we should probably fix the majority of these before merging. On the good side, they will probably be fixed by simply renaming the files to have .erb extension. |
|
I made a silly mistake: threw the warning no matter what! That's been fixed, and now we only get one warning, in the NullResolverTest. I'm not 100% sure how to fix it yet... gonna dig in at lunch, I think. |
|
The tests now have zero deprecation warnings. We should be good to go! |
| module Template::Handlers | ||
| class Raw | ||
| def call(template) | ||
| "'#{template.source}';" |
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.
One last thing: wouldn't template.source.inspect be a better alternative here since it would automatically escape quotes?
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.
Quite possibly. I was copying what was done in the Builder handler. I can absolutely change that if you'd like, I have no idea what's the best.
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'm not sure using inspect is good:
1) Failure:
test_render_raw_template_with_handlers(CachedViewRenderTest) [/Users/steve/src/rails/actionpack/test/template/render_test.rb:83]:
--- expected
+++ actual
@@ -1,2 +1,2 @@
-"<%= hello_world %>
-"
+"\"<%= hello_world %>\
+\""
2) Failure:
test_render_raw_template_with_handlers(LazyViewRenderTest) [/Users/steve/src/rails/actionpack/test/template/render_test.rb:83]:
--- expected
+++ actual
@@ -1,2 +1,2 @@
-"<%= hello_world %>
-"
+"\"<%= hello_world %>\
+\""
3) Failure:
test_raw_template(TestERBTemplate) [/Users/steve/src/rails/actionpack/test/template/template_test.rb:69]:
Expected: "<%= hello %>"
Actual: "\"<%= hello %>\""
Or is that what we'd want?
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.
Hrm, so let's change the question. Using the current solution (without
inspect), does it work if I have single- or double-quotes in the template?
José Valim
www.plataformatec.com.br
Founder and Lead Developer
*
|
Updated to explicitly test quoting. |
|
Jut playing devil's advocate, but now it can fail if it has a } inside the José Valim |
|
Hahahaha. Lemme check that... |
|
Apparently it does work. I updated the test to test a bunch of characters, regardless. |
|
Actually, @evanphx says: It detects matching {}'s yes, but if there just a } it will blow up |
|
So, this commit is now just a WIP, as it fails the test, but @rkh pointed out to me what tilt does: https://github.com/rtomayko/tilt/blob/master/lib/tilt/string.rb Trying to port that here. Tests are failing, but I have a few hours where I can't work on this, so I figured i'd push my wip up |
|
Okay! This now works. Some discussion here: https://gist.github.com/2720171 |
|
Merged, thanks a lot! |
Created a Raw handler for templates.
|
Yay! :D |
|
Added a changelog entry here: https://github.com/rails/rails/blob/master/actionpack/CHANGELOG.md |
This addresses the issue brought up in #2394.
I built this based on @josevalim's suggestion, which involves creating a raw template and adding a deprecation message for default template handlers.
One issue with this as it stands is that the tests now throw some warnings; I should probably fix those up, but I wanted to get feedback on my test and this code first. I'm 99% sure that it's all good, but I've never dived into this part of Rails before.