module Chance::Instance::JavaScript

Public Instance Methods

javascript(opts) click to toggle source
# File vendor/chance/lib/chance/instance/javascript.rb, line 4
def javascript(opts)
  # Currently, we only include the preload JavaScript
  preload_javascript(opts)
end
preload_javascript(opts) click to toggle source

Generates the preload JavaScript

# File vendor/chance/lib/chance/instance/javascript.rb, line 10
def preload_javascript(opts)
  output = "if (typeof CHANCE_SLICES === 'undefined') var CHANCE_SLICES = [];"
  output += "CHANCE_SLICES = CHANCE_SLICES.concat(["
  output += @slices.map {|name, slice| "'" + slice[:css_name] + "'" }.join(",\n")
  output += "]);"
end