Skip to content

Instantly share code, notes, and snippets.

@alto
Created October 28, 2011 16:18
Show Gist options
  • Save alto/1322663 to your computer and use it in GitHub Desktop.
Save alto/1322663 to your computer and use it in GitHub Desktop.
API DSL
# places/index.api
@places.each do |place|
template('places/show', :place => place) # user shall be available as @user in the template
end
# places/show.api
object(@place) do
:name, # plain attribute
:address => address_for(@user), # helper used
:location => { # hash
:lat => 52.0,
:lng => 10.0
},
:category => :place_type, # renaming/mapping (@place.place_type exists)
:links => [
{rel => 'self', :href => 'http://...'},
{rel => 'full', :href => 'http://...'}
],
:host => template('users/show', :user => @place.host) # child_object
end
# users/show.api
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment