rails/jbuilder — pull request #35 by mbrandonw (2012-04-17 13:36:03+00:00)
Title: Top level arrays and fragment caching

I've added a method to `Jbuilder` so that we can use the fragment caching pattern from ActionView, but along the way I also had to make a change to `array!`.

My change to `array!` allows one to simply set the array directly, similar to how `set!` allows one to set a key/value pair directly:

```ruby
json.array! [1,2,3] # => "[1,2,3]"
```

This change is pretty useful by itself. But, with this I created a method `cache!` that has the same signature as the helper `cache` in ActionView and allows the following pattern:

```ruby
json.cache! ['v1', @person], :expires_in => 10.minutes do |json|
json.extract! @person, :name, :age
end
```

There is still some work to be done (write tests, update readme, and right now I'm just using Rails.cache for the cache store so i guess that needs to be changed), but is this something people are interested in pulling?