Allow nesting of Jbuilder objects #23

Merged
merged 4 commits into from Aug 8, 2012

Conversation

Projects
None yet
7 participants
Contributor

bigjason commented Feb 15, 2012

Small change that detects when another jbuilder object is being added. This allows chaining objects together in a manner similar to partials. Very useful when using jbuilder outside of rails templates.

A contrived example:

class Person
  def to_builder
    person = Jbuilder.new
    person.(self, :name, :age)
  end
end

class Company
  def to_builder
    company = Jbuilder.new
    company.name name
    company.president president.to_builder
  end
end

puts company.to_builder.target!
Allow nesting of Jbuilder objects
Small change that detects when another jbuilder object is being added.
This allows a higher degree of code reuse.
Owner

dhh commented Mar 23, 2012

I like this. Please include README docs in your pull and we can merge.

Contributor

bigjason commented Mar 23, 2012

Will do. Thanks.

Contributor

bigjason commented Mar 23, 2012

@dhh I added the docs. Let me know if anything else is needed for this.

+1

Contributor

inossidabile commented Apr 9, 2012

+1

maletor commented Apr 20, 2012

+1

+1

cicloid commented Jul 31, 2012

👍

dhh added a commit that referenced this pull request Aug 8, 2012

Merge pull request #23 from bigjason/nestable-jbuilder
Allow nesting of Jbuilder objects

@dhh dhh merged commit fcebaad into rails:master Aug 8, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment