Module: Jquery::Rails::Cdn
- Defined in:
- lib/jquery-rails-cdn/version.rb,
lib/jquery-rails-cdn.rb
Constant Summary collapse
- VERSION =
'1.2.0'
- OFFLINE =
(Rails.env.development? or Rails.env.test?)
- URL =
{ :google => "//ajax.googleapis.com/ajax/libs/jquery/{JQUERY_VERSION}/jquery.min.js", :microsoft => "//ajax.aspnetcdn.com/ajax/jQuery/jquery-{JQUERY_VERSION}.min.js", :jquery => "//code.jquery.com/jquery-{JQUERY_VERSION}.min.js", :yandex => "//yandex.st/jquery/{JQUERY_VERSION}/jquery.min.js", :cloudflare => "//cdnjs.cloudflare.com/ajax/libs/jquery/{JQUERY_VERSION}/jquery.min.js" }
Instance Method Summary collapse
- #jquery_include_tag(name, options = {}) ⇒ Object
- #jquery_url(name) ⇒ Object
- #jquery_version_chooser(one, two, three) ⇒ Object
Instance Method Details
#jquery_include_tag(name, options = {}) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/jquery-rails-cdn.rb', line 43 def jquery_include_tag(name, = {}) return javascript_include_tag(jquery_url(:local), ) if OFFLINE && !.delete(:force) [ javascript_include_tag(jquery_url(name), ), javascript_tag("window.jQuery || document.write(unescape('#{javascript_include_tag(jquery_url(:local), ).gsub('<','%3C')}'))") ].join("\n").html_safe end |
#jquery_url(name) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jquery-rails-cdn.rb', line 17 def jquery_url(name) @@jquery_urls ||= begin constant = jquery_version_chooser('JQUERY_VERSION', 'JQUERY_2_VERSION', 'JQUERY_3_VERSION') version = "Jquery::Rails::#{constant}".constantize Hash[URL.map{|k,v| [k, v.sub(/\{JQUERY_VERSION\}/, version)] }] end if name == :local jquery_version_chooser(:jquery, :jquery2, :jquery3) else @@jquery_urls[name] end end |
#jquery_version_chooser(one, two, three) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jquery-rails-cdn.rb', line 30 def jquery_version_chooser(one, two, three) case Jquery::Rails::Cdn.major_version when 1, NilClass one when 2 two when 3 three else raise 'invalid :major_version option' end end |