README.md in jsonify-0.1.2 vs README.md in jsonify-0.1.3
- old
+ new
@@ -1,10 +1,10 @@
-# Jsonify — a builder for JSON [![Build Status](http://travis-ci.org/bsiggelkow/jsonify.png)](http://travis-ci.org/bsiggelkow/jsonify)
+# Jsonify — a builder for JSON [![Build Status](https://secure.travis-ci.org/bsiggelkow/jsonify.png)](http://travis-ci.org/bsiggelkow/jsonify)
[Jsonify](https://github.com/bsiggelkow/jsonify) is to JSON as [Builder](https://github.com/jimweirich/builder) is to XML.
-If you want to use Jsonify for Rails templates, install [Jsonify-Rails](https://github.com/bsiggelkow/jsonify-rails).
+To use Jsonify for Rails templates, install [Jsonify-Rails](https://github.com/bsiggelkow/jsonify-rails).
## Goal
Jsonify provides a ___builder___ style engine for creating correct JSON representations of Ruby objects.
@@ -80,22 +80,40 @@
"href": "http://gatech.edu"
}
]
}
-### View Templates
+#### Convenience methods
+Jsonify provides class-level convenience methods that
+save you the trouble of instantiating the `Jsonify::Builder`. Each of these methods accepts a block, yields a new `Builder` object to the block, and then compiles the result.
-Jsonify includes a Rails 3 template handler. Any template with a `.jsonify` will be handled by Rails.
+- `compile`
+ - Compiles the given block; any options are passed the instantiated `Builder`
+- `pretty`
+ - Compiles the given block; results are output in `pretty` format.
+- `plain`
+ - Compiles the given block; results are output in `plain` (default) format.
+For example ...
+
+ Jsonify::Builder.plain do |j|
+ j.song 'Fearless'
+ j.album 'Meddle'
+ end
+
+### Rails View Templates
+
+Jsonify can be used for Rails 3 view templates via the [jsonify-rails](https://github.com/bsiggelkow/jsonify-rails) which includes a Rails 3 template handler. Any template with a `.jsonify` extension will be handled by Rails.
+
The Jsonify template handler exposes the `Jsonify::Builder` instance to your template with the `json` variable as in the following example:
json.hello do
json.world "Jsonify is Working!"
end
Just like with any other template, your Jsonify template will have access to
-any instance variables that are exposed through the controller.
+any instance variables that are exposed through the controller. See [Jsonify-Rails](https://github.com/bsiggelkow/jsonify-rails) for additional details.
#### Partials
You can use partials from Jsonify views, and you can create Jsonify partials. How your Jsonify template uses a partial depends on how the information the partial returns is structured. Keep in mind that any paritial, be it a Jsonify template, erb, or anything else, always a returns its result as a string.
@@ -149,10 +167,32 @@
renders ...
[1,{"date":"2011-07-30"}]
+### Tilt Integration
+
+Jsonify includes support for [Tilt](http://github.com/rtomayko/tilt). This allow you to create views that use Jsonify with any framework that supports Tilt. Here's an example of a simple [Sinatra](http://sinatrarb.com) application that leverages Jsonify's Tilt integration.
+
+ require 'bundler/setup'
+ require 'sinatra'
+
+ require 'jsonify'
+ require 'jsonify/tilt'
+
+ helpers do
+ def jsonify(*args) render(:jsonify, *args) end
+ end
+
+ get '/' do
+ jsonify :index
+ end
+
+And the corresponding template in `views\index.jsonify`
+
+ json.hello :frank
+
### Usage Patterns
Jsonify is designed to support construction of an valid JSON representation and
is entirely based on the [JSON specification](http://json.org).
@@ -360,13 +400,9 @@
- [Argonaut](https://github.com/jbr/argonaut)
- [JSON Builder](https://github.com/dewski/json_builder)
- [RABL](https://github.com/nesquena/rabl)
- [Representative](https://github.com/mdub/representative)
- [Tokamak](https://github.com/abril/tokamak)
-
-## TODOs
-1. Benchmark performance
-1. Tilt Integration (jsonify-tilt)
## License
This project is released under the MIT license.