Sha256: e81fa7d7bb26c2c1bfe1f744e55aa0f22599a049e08e31f75d344b5ac06a8309
Contents?: true
Size: 787 Bytes
Versions: 1
Compression:
Stored size: 787 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}=#{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.2 | lib/gon/sinatra/helpers.rb |