class Lucy::JavascriptGenerator
Attributes
global[W]
init_namespace[W]
namespace[W]
Public Class Methods
new() { |self| ... }
click to toggle source
# File lib/lucy.rb, line 31 def initialize @keyed = [] @raw = [] yield self if block_given? end
Public Instance Methods
global()
click to toggle source
# File lib/lucy.rb, line 61 def global @global || DEFAULT_GLOBAL end
init_namespace()
click to toggle source
# File lib/lucy.rb, line 65 def init_namespace "if (!#{global}.#{namespace}) { #{namespace} = {}; }" end
init_namespace?()
click to toggle source
# File lib/lucy.rb, line 69 def init_namespace? @init_namespace.nil? ? true : @init_namespace end
namespace()
click to toggle source
# File lib/lucy.rb, line 57 def namespace @namespace || DEFAULT_NAMESPACE end
to_a()
click to toggle source
# File lib/lucy.rb, line 47 def to_a (init_namespace? ? [init_namespace] : []) + @keyed.map do |key, value| "#{namespace}.#{[key].flatten.join('.')} = #{value};" end + @raw end
to_js()
click to toggle source
# File lib/lucy.rb, line 53 def to_js to_a.join("\n\n") end
write(key, obj)
click to toggle source
# File lib/lucy.rb, line 37 def write(key, obj) @keyed << [key, ActiveSupport::JSON.encode(obj)] end
Also aliased as: []=
write_raw(data)
click to toggle source
# File lib/lucy.rb, line 42 def write_raw(data) @raw << data end
Also aliased as: <<