Closed pat closed 10 years ago
Figured out dynamic templates - instead of calling render within the endpoint, allowing the setting of a template within the env hash. Same approach for local variables too (thus, if wanted, instance variables can be avoided). These changes are in e8600b2efb144e86a9b613fd2e3811b5e1b5bcb1.
Thank you for this pull request, but because I'm busy now and maybe for a month, I have no time to check this commit. Would you mind waiting for a while?
That's fine, I understand how busy life can be :) We'll use my branch in the meantime.
I'm sorry for taking so long before responding your commits. I think they are great work, but I have a question about it.
Is your purpose of these commits that you want to change templates dynamically within the logic of a Grape endpoint?
Yes - here's an example, where I'm only setting the template if the save is successful (Profile is not an ActiveRecord class, hence the slightly different method calls):
put do
user = Profile.new(current_user, params[:user])
if user.update
env['api.tilt.template'] = 'profiles/show'
env['api.tilt.locals'] = {user: user}
else
status 406
{'status' => 'Not Acceptable', 'errors' => user.errors.to_hash}
end
end
Cool! I've merged.
I'll add a sample in README based on yours.
Thank you :)
Thanks for the merge :)
Any thoughts on when a new version release will happen?
I'll release it in a few hours.
Excellent, thanks!
I'm done! :)
Great - just updated the Gemfile in our project to use 0.2.0 :)
I realise this pull request is a significant change to the entire project. Happy to discuss things... perhaps it's worth reviewing on a per-commit basis, which should help explain what I've done a bit more clearly.
The reason for all of this is I'd like to be able to call rendering of templates within the logic of a Grape endpoint... I'm not yet sure how that'll be possible without the automatic translation of the render into a double-JSON'd string, but I figure these changes are worthwhile in and of themselves.