Method: Merb::AssetsMixin#js

Defined in:
lib/merb-assets/assets_mixin.rb

#js(data) ⇒ Object

Parameters

data<Object>

Object to translate into JSON. If the object does not respond to :to_json, then data.inspect.to_json is returned instead.

Examples

js({'user' => 'Lewis', 'page' => 'home'})
 # => "{\"user\":\"Lewis\",\"page\":\"home\"}"

js([ 1, 2, {"a"=>3.141}, false, true, nil, 4..10 ])
  # => "[1,2,{\"a\":3.141},false,true,null,\"4..10\"]"


226
227
228
229
230
231
232
# File 'lib/merb-assets/assets_mixin.rb', line 226

def js(data)
  if data.respond_to? :to_json
    data.to_json
  else
    data.inspect.to_json
  end
end