Sha256: f6165d23c3a2cdc65c6c78b31ca068ad4a341da75cb8139e06ebde5b41278ce8
Contents?: true
Size: 815 Bytes
Versions: 1
Compression:
Stored size: 815 Bytes
Contents
require 'json' module Gon module Sinatra module Helpers def include_gon(options = {}) return '' if gon.all_variables.empty? data = gon.all_variables namespace = options[:namespace] || 'gon' script = "<script>window." + namespace + " = {};" unless options[:camel_case] data.each do |key, val| script += namespace + "." + key.to_s + '=' + val.to_json + ";" end else data.each do |key, val| script += namespace + "." + key.to_s.camelize(:lower) + '=' + val.to_json + ";" end end script += "</script>" script end end module GonHelpers def gon env["gon"] ||= Gon::Sinatra::Store.new({}) @gon = env["gon"] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gon-sinatra-0.1.1 | lib/gon/sinatra/helpers.rb |