Skip to content

Using Bldr Programmatically

ajsharp edited this page May 2, 2012 · 1 revision

Most of the time, you'll use bldr in a sinatra endpoint by using the bldr helper method. However, there are some cases where you need to generate json outside of the request / response cycle, and it's often useful to be able to use bldr in those situations. Here's how it's done.

template = Bldr::Template.new('./path/to/template/file.bldr')
template.render(Bldr::Node.new, {:local_variable => "value"})

The first line initializes a Bldr::Template object, which is a subclass of Tilt::Template. We then call the render method, passing in the scope in which the template is to be eval-ed by tilt, and an optional hash of local variables. The signature here is relatively simple, you just need to know how to use it.

See https://github.com/rtomayko/tilt for more about Tilt.

Clone this wiki locally