Class: String

Inherits:
Object show all
Defined in:
lib/to-javascript/encoders/string.rb

Direct Known Subclasses

ActiveSupport::JS::Code

Instance Method Summary collapse

Instance Method Details

#as_jsObject

Synonymous with Javascript(‘string’) Returns an unquoted Javascript object that will not be quoted when renderded as javasctipy

datecode = 'new Date()'.to_javascript
{ :now => datecode }.to_js
# => { "now": new Date() }

{ :location => 'window.location'.as_js }.to_js
# => {"location": window.location}


16
17
18
# File 'lib/to-javascript/encoders/string.rb', line 16

def as_js
  ActiveSupport::JS::Code.new self
end

#to_js(options = nil) ⇒ Object

:nodoc:



2
3
4
# File 'lib/to-javascript/encoders/string.rb', line 2

def to_js(options = nil) #:nodoc:
  ActiveSupport::JS::Code.new to_json(options)
end