rails/jbuilder — pull request #68 by rolftimmermans (2012-09-26 22:36:10+00:00)
Title: Changing the yielding API

This PR changes the API of `Jbuilder` to not require an argument for every block. It also fixes the implementation of `cache!` to be compatible with this API (see confusion in #63).

Old API:

```
Jbuilder.encode do |json|
json.author do |json|
json.name "Rolf"
end
json.attachments @message.attachments do |json, attachment|
json.filename attachment.filename
end
end
```

New API:

```
Jbuilder.encode do |json|
json.author do
json.name "Rolf"
end
json.attachments @message.attachments do |attachment|
json.filename attachment.filename
end
end
```

Documentation has been updated, but the old API actually still works. Keeping backwards compatibility was only an issue for the few methods that take a block with 2 arguments. The first argument used to be an instance of a `Jbuilder` object, the second argument the element for the current iteration. With this change a block with arity 1 only receives the element. The code for that is ugly though. Therefore it would be great if the old API could be deprecated and removed sometime after a major version bump.