| Class | ServerSide::JS |
| In: |
lib/serverside/js.rb
|
| Parent: | Object |
Serializes data into a Javscript literal hash format. For example: ServerSide::JS.new {|j| j}
| NULL | = | 'null'.freeze |
# File lib/serverside/js.rb, line 46
46: def <<(value)
47: value = value.__content if value.respond_to?(:__content)
48: @stack.last.__add_array_value(value)
49: end
# File lib/serverside/js.rb, line 41
41: def __add_array_value(value)
42: @content ||= []
43: @content << value
44: end
# File lib/serverside/js.rb, line 36
36: def __add_hash_value(key, value)
37: @content ||= {}
38: @content[key] = value
39: end
Returns the current document content.
# File lib/serverside/js.rb, line 52
52: def __content
53: @content
54: end
Catches calls to define keys and creates methods on the fly.
# File lib/serverside/js.rb, line 22
22: def method_missing(key, *args, &block)
23: value = nil
24: if block
25: @stack.push JS.new
26: block.call(self)
27: value = @stack.pop.__content
28: else
29: value = args.first
30: value = value.__content if value.respond_to?(:__content)
31: end
32: @stack.last.__add_hash_value(key, value)
33: self
34: end