-
Notifications
You must be signed in to change notification settings - Fork 206
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
Avoid Helpers::Render in mandatory includes #610
Conversation
This patch moves "include Helpers::Render" from Amber::Controller::Base into ApplicationController. ApplicationController is part of user code and now it is possible to avoid including Helpers::Render (and kilt dependencies) in case that user application does not want to use the default render system.
(Just to be clear, neither @robacarp nor I know how the "in-progress" tag got attached. The PR is in any case finished and ready for review.) |
@@ -1,13 +1,15 @@ | |||
require "http" | |||
|
|||
require "./filters" | |||
require "./helpers/*" | |||
require "./helpers/csrf" |
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 like this. ❤️
@@ -83,6 +83,7 @@ class HelloController < Amber::Controller::Base | |||
end | |||
|
|||
class RenderController < Amber::Controller::Base | |||
include Amber::Controller::Helpers::Render |
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.
Should we add an ApplicationController
fixture in between?
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.
Good one, will do, thanks!
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.
Actually @drujensen looking into spec/support/fixtures/controller_fixtures.cr I suggest things to remain as they are.
Because if we add ApplicationController fixture then other fixture classes in that file should inherit from it, which would make them have more functionality than the spec specifically wanted to test.
So I would for keeping specs as granular and specific as they are now.
The failures in Travis are real. I think the error controller may not inherit from Perhaps the best fix is to have the |
@marksiemers uh yes, but if ErrorController needs it, then that means Amber's render helper will always be "required" somewhere and it will bring in kilt dependencies with it. (In other words, if we can't remove use of render() from there, then it's not truly possible to completely avoid Amber's built-in rendering (which as a consequence requires kilt).) Even though, by removing the include from AppController the user can essentially free his part of code the built-in "render" macro and all other things that get initialized, which was the most important to do anyway, so it still looks useful. |
@docelic - Let me clarify, it isn't Amber's If you run class ErrorController < Amber::Controller::Error
LAYOUT = "application.slang"
def forbidden
render("forbidden.slang")
end
def not_found
render("not_found.slang")
end
def internal_server_error
render("internal_server_error.slang")
end
end For a little background, what the build tests do is build an actual amber app using the cli, then it generates one of everything (model, controller, scaffold, auth, etc.). Then it runs the test suite of that generated app. You can recreate locally with |
So, just the generator will need to be updated for |
Good catch @marksiemers 👍 @docelic Yeah just add |
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.
ErrorController
needs include Amber::Controller::Helpers::Render
as well
@docelic Thank you for fixing
Spec location: |
I seem to be able to run tests correctly now. Will fix failing specs in other PRs now too. |
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 would very much prefer to keep render in Controller::Base for now. It's not in the way of Kilt as you can still call Kilt.render or overload your own render macro if necessary.
If we start removing something as default as render, why not redirect, params, before_filters, csrf, responders, the router or anything else that makes amber what it is?
As @docelic said:
Perhaps some render systems can conflict with |
@faustinoaq I haven't seen any render systems that do conflict with kilt, since it's namespaced under |
I think I side with @elorest here. If the default render macro doesn’t do what you want, why not just override it in your application controller? |
Well you get render() macro from default method and possibly some other stuff that it initializes in the controller. |
@docelic Thanks for your work on this. Personally I didn't really want this to happen, but I hate it when someone puts a lot of time into code and doesn't get to use it. I just want you to know that I really do appreciate it. This may be something we'll want to address in the future. My biggest issues were with it right now is that there are multiple things on the same level and usefulness in the base controller and just moving one of them out seemed a little premature. Thanks. |
Sure, no worries. I instead sent additional patches to Liquid.cr and Kilt to make them work as one would expect (including ability to pass custom context), so there's no need yet to replace/leave out kilt in any scenario. |
This patch moves "include Helpers::Render" from Amber::Controller::Base
into ApplicationController.
ApplicationController is part of user code and now it is possible to
avoid including Helpers::Render (and kilt dependencies) in case that
user application does not want to use the default render system.