Class | Rabl::Engine |
In: |
lib/rabl/engine.rb
|
Parent: | Object |
FORMATS | = | [:json, :xml, :plist, :bson, :msgpack] | List of supported rendering formats |
Constructs a new ejs engine based on given vars, handler and declarations Rabl::Engine.new("…source…", { :format => "xml", :root => true, :view_path => "/path/to/views" })
Sets the cache key to be used by ActiveSupport::Cache.expand_cache_key cache @user # calls @user.cache_key cache [‘rabl’, @user] # calls @user.cache_key and prefixes with rabl/ cache ‘user’ # explicit key of ‘user’ cache # uses the current item within a collection cache ‘user’, expires_in: 1.hour options is passed through to the cache store
Sets the object as a collection casted to a simple array collection @users collection @users => :people collection @users, :root => :person collection @users, :object_root => :person
Extends an existing rabl template with additional attributes in the block extends("users/show", :object => @user) { attribute :full_name }
Renders the representation based on source, object, scope and locals Rabl::Engine.new("…source…", { :format => "xml" }).render(scope, { :foo => "bar", :object => @user })
Returns the current object that is the topic of this template Can be the collection or the object depending on topic assigned root_object => @user
Returns a msgpack representation of the data object to_msgpack(:root => true)
Returns data as json embraced with callback when detected format_json({ :foo => "bar" }) => "test({ foo : ‘bar’ })" format_json("{ foo : "bar" }") => "test({ foo : ‘bar’ })"
Supports calling helpers defined for the template scope using method_missing hook
Returns the request parameters if available in the scope request_params => { :foo => "bar" }