javascript - Configuration inside a gem's asset not working -
i created gem called supportator puts warning modal when browser version not supported. accepting configuration hash can pass last version not supported of each browser.
the code
this initializer inside application config/initializers/supportator.rb
supportator.configure({:chrome => 30, :ie => 11})
this configuration file of gem lib/supportator.rb
:
require "supportator/version" require "engine" module supportator @config = { :chrome => 14, :safari => 5, :firefox => 3, :ie => 9, :opera => 12 } @valid_config_keys = @config.keys def self.configure(opts = {}) opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym} end def self.config @config end end
this part of js.erb file triggers modal of gem lib/assets/javascripts/supportator.js.erb
:
... if (browsername == "chrome" && majorversion >= <%= supportator.config[:chrome] %>) supported = true; else if (browsername == "safari" && majorversion >= <%= supportator.config[:safari] %>) supported = true; else if (browsername == "firefox" && majorversion >= <%= supportator.config[:firefox] %>) supported = true; else if (browsername == "microsoft internet explorer" && majorversion >= <%= supportator.config[:ie] %>) supported = true; else if (browsername == "opera" && majorversion >= <%= supportator.config[:opera] %>) supported = true; else supported = false; ....
the problem
when see code after pre-compilation result is:
... if (browsername == "chrome" && majorversion >= 14) supported = true; else if (browsername == "safari" && majorversion >= 5) supported = true; else if (browsername == "firefox" && majorversion >= 3) supported = true; else if (browsername == "microsoft internet explorer" && majorversion >= 9) supported = true; else if (browsername == "opera" && majorversion >= 12) supported = true; else supported = false; ....
but when put in console supportator.config[:ie]
result 12.
clearly in pre-compilation of js.erb configuration being ignored. has ideas of why happening?
i know might not helpful i'm not able reproduce bug. gem acting expected when rails_env=development bundle exec rake assets:precompile
, rails s
Comments
Post a Comment