Bldr is a minimalist templating library that provides a simple DSL for generating json documents from ruby objects. It currently supports Sinatra out of the box -- Rails 3 support is planned for the near future.
If you would like to contribute, pull requests with specs are warmly accepted :)
If you're building an API,
Model#to_json just doesn't cut it. Besides the JSON
representation of your models arguarbly being a presentation concern, trying
to cram all of this logic into an
#as_json method quickly turns into pure chaos.
There are a few other json templating libraries available, but I wasn't satisfied with any of the DSL's. So I created Bldr.
- Simple json templating DSL
- Uses Tilt's built-in rendering and template caching for better performance
There are two ways to use Bldr in your Sinatra app, depending on whether you are using Sinatra's classic or module application style:
# Method 1: Classic style require 'sinatra/bldr' get '/hello' do bldr :hello end # Method 2: Modular style require 'sinatra/bldr' class MyApp < Sinatra::Base register Sinatra::Bldr end
See the Documentation & Examples page on the wiki.
To get proper syntax highlighting in vim, add this line to your .vimrc:
au BufRead,BufNewFile *.bldr set filetype=ruby
- Rails 3 support
- Replace current_object with a block param for collection methods
- XML support
- Ian Hunter (@ihunter)
Copyright (c) 2011 Alex Sharp. See the MIT-LICENSE file for full copyright information.