Sha256: dedefffee00fcc7ae6c037bc9b2d258310696cda7acd8ede308f55907fca833f
Contents?: true
Size: 1.19 KB
Versions: 2
Compression:
Stored size: 1.19 KB
Contents
module Gon module Helpers def self.included base base.send(:include, InstanceMethods) end module InstanceMethods def include_gon(options = {}) if Gon.request_env 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.html_safe else "" end end end end module GonHelpers def self.included base base.send(:include, InstanceMethods) end module InstanceMethods def gon if !Gon.request_env || Gon.request_env.object_id != request.env.object_id Gon.request_env = request.env end Gon end end end end ActionView::Base.send :include, Gon::Helpers ActionController::Base.send :include, Gon::GonHelpers
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gon-1.1.3 | lib/gon/helpers.rb |
gon-1.1.2 | lib/gon/helpers.rb |