README.md in jbuilder-1.5.0 vs README.md in jbuilder-1.5.1

- old
+ new

@@ -84,11 +84,10 @@ json.array! @people, :id, :name # => [ { "id": 1, "name": "David" }, { "id": 2, "name": "Jamie" } ] ``` - Jbuilder objects can be directly nested inside each other. Useful for composing objects. ``` ruby class Person # ... Class Definition ... # @@ -153,10 +152,14 @@ json.partial! 'posts/post', collection: @posts, as: :post # or json.partial! partial: 'posts/post', collection: @posts, as: :post + +# or + +json.comments @post.comments, partial: 'comment/comment', as: :comment ``` You can explicitly make Jbuilder object return null if you want: ``` ruby @@ -169,26 +172,35 @@ json.last_name @post.author_last_name end end ``` +Fragment caching is supported, it uses `Rails.cache` and works like caching in HTML templates: + +```ruby +json.cache! ['v1', @person], expires_in: 10.minutes do + json.extract! @person, :name, :age +end +``` + Keys can be auto formatted using `key_format!`, this can be used to convert keynames from the standard ruby_format to CamelCase: ``` ruby -json.key_format! :camelize => :lower +json.key_format! camelize: :lower json.first_name 'David' # => { "firstName": "David" } ``` You can set this globally with the class method `key_format` (from inside your environment.rb for example): ``` ruby -Jbuilder.key_format :camelize => :lower +Jbuilder.key_format camelize: :lower ``` Libraries similar to this in some form or another include: +* Active Model Serializers: https://github.com/rails-api/active_model_serializers * RABL: https://github.com/nesquena/rabl * JsonBuilder: https://github.com/nov/jsonbuilder * JSON Builder: https://github.com/dewski/json_builder * Jsonify: https://github.com/bsiggelkow/jsonify * RepresentationView: https://github.com/mdub/representative_view