milkcocoa / grape-jbuilder

Use Jbuilder with Grape
MIT License
49 stars 18 forks source link

Class for rendering, plus unit specs and some cleaning up. #4

Closed pat closed 10 years ago

pat commented 10 years ago

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.

pat commented 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.

milkcocoa commented 10 years ago

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?

pat commented 10 years ago

That's fine, I understand how busy life can be :) We'll use my branch in the meantime.

milkcocoa commented 10 years ago

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?

pat commented 10 years ago

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
milkcocoa commented 10 years ago

Cool! I've merged.

I'll add a sample in README based on yours.

Thank you :)

pat commented 10 years ago

Thanks for the merge :)

Any thoughts on when a new version release will happen?

milkcocoa commented 10 years ago

I'll release it in a few hours.

pat commented 10 years ago

Excellent, thanks!

milkcocoa commented 10 years ago

I'm done! :)

pat commented 10 years ago

Great - just updated the Gemfile in our project to use 0.2.0 :)