Class Rabl::Engine
In: lib/rabl/engine.rb
Parent: Object

Methods

Included Modules

Helpers Partials Helpers::Escaper

Constants

FORMATS = [:json, :xml, :plist, :bson, :msgpack]   List of supported rendering formats

Public Class methods

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" })

Public Instance methods

Renders the representation based on source, object, context_scope and locals Rabl::Engine.new("…source…", { :format => "xml" }).apply(context_scope, { :foo => "bar", :object => @user })

Indicates an attribute or method should be included in the json output attribute :foo, :as => "bar" attribute :foo => :bar, :bar => :baz attribute :foo => :bar, :bar => :baz, :if => lambda { |r| r.foo }

attributes(*args)

Alias for attribute

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

Disables reading (but not writing) from the cache when rendering.

Creates a child node that is included in json output child(@user) { attribute :full_name }

code(name = nil, options = {}, &block)

Alias for node

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 }

Glues data from a child node to the json_output glue(@user) { attribute :full_name => :user_full_name }

Includes a helper module with a RABL template helper ExampleHelper

helpers(*klasses)

Alias for helper

Creates an arbitrary node that is included in the json output. node(:foo) { "bar" } node(:foo, :if => lambda { … }) { "bar" }

Sets the object to be used as the data source for this template object(@user) object @user => :person object @users

Returns a hash representing the partial partial("users/show", :object => @user) options must have :object options can have :view_path, :child_root, :root

Renders the representation based on a previous apply Rabl::Engine.new("…source…", { :format => "xml" }).apply(context_scope, { :foo => "bar", :object => @user }).render

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 bson representation of the data object to_bson(:root => true)

Returns a hash representation of the data object to_hash(:root => true, :child_root => true)

Returns a json representation of the data object to_json(:root => true)

to_mpac(options = {})

Alias for to_msgpack

Returns a msgpack representation of the data object to_msgpack(:root => true)

Returns a plist representation of the data object to_plist(:root => true)

Returns an xml representation of the data object to_xml(:root => true)

Protected Instance methods

Returns a guess at the default object for this template default_object => @user

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 context_scope using method_missing hook

Returns a guess at the format in this context_scope request_format => "xml"

Returns the request parameters if available in the context_scope request_params => { :foo => "bar" }

Resets the options parsed from a rabl template.

Augments respond to supporting context_scope methods

[Validate]