ccocchi / rabl-rails

Rails 4.2+ templating system with JSON, XML and Plist support.
MIT License
208 stars 51 forks source link

Allow conditionnal blocks within template #8

Closed ccocchi closed 12 years ago

ccocchi commented 12 years ago

To replace if and unless within template we introduce the condition keyword. It takes a proc (that take the current object rendered) as argument and a block. The block is parsed at compile time.

The source compiled from the block will be called if the proc is evaluated as true at rendering time. Here's a use example

object :@user

attributes :name
condition(->(u) { u == current_user }) do
 attributes :secret
end