Sha256: 95e4524c3f5f61f20ae0ac2f2546cb8fc6262e18b4aa0b92d9400ee10c4196b3
Contents?: true
Size: 1.24 KB
Versions: 1
Compression:
Stored size: 1.24 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 && Gon.all_variables.present? data = Gon.all_variables namespace = options[:namespace] || 'gon' script = '<script>window.' + namespace + ' = {};' if options[:camel_case] data.each do |key, val| script << namespace + '.' + key.to_s.camelize(:lower) + '=' + val.to_json + ';' end else data.each do |key, val| script << namespace + '.' + key.to_s + '=' + 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 != request.object_id Gon.request = request.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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gon-2.1.0 | lib/gon/helpers.rb |