jquery-rails-cdn-yjchen 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Kenn Ejima
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # jquery-rails-cdn
2
+
3
+ Add CDN support to
4
+
5
+ * [jquery-rails](https://github.com/rails/jquery-rails).
6
+
7
+ Serving javascripts and stylesheets from a publicly available [CDN](http://en.wikipedia.org/wiki/Content_Delivery_Network) has clear benefits:
8
+
9
+ * **Speed**: Users will be able to download jQuery and others from the closest physical location.
10
+ * **Caching**: CDN is used so widely that potentially your users may not need to download jQuery and others at all.
11
+ * **Parallelism**: Browsers have a limitation on how many connections can be made to a single host. Using CDN for jQuery offloads a big one.
12
+
13
+ ## Features
14
+
15
+ This gem offers the following features:
16
+
17
+ * Supports multiple CDN. (Google, Microsoft and jquery.com)
18
+ * jQuery and jQuery-UI version is automatically detected via jquery-rails.
19
+ * Automatically fallback to jquery-rails' bundled jQuery when:
20
+ * You're on a development environment so that you can work offline.
21
+ * The CDN is down or unavailable.
22
+
23
+ On top of that, if you're using asset pipeline, you may have noticed that the major chunks of the code in `application.js` is jQuery. Implications of externalizing jQuery from `application.js` are:
24
+
25
+ * Updating your js code won't evict the entire cache in browsers - your code changes more often than jQuery upgrades, right?
26
+ * `rake assets:precompile` takes less peak memory usage.
27
+
28
+ Changelog:
29
+
30
+ * v0.3.0: Microsoft and Yandex are now always scheme-less. (Thanks to @atipugin)
31
+ * v0.2.2: Remove Bootstrap and Angular.js to their own rails engine.
32
+ * v0.2.1: Add Angular.js
33
+ * v0.2.0: Update to match original codes and update bootstrap to 2.1.0
34
+ * v0.1.2: Added bootstrap.
35
+ * v0.1.1: Added jQuery-UI
36
+ * v0.1.0: Added `:google_schemeless` for sites that support both ssl / non-ssl
37
+ * v0.0.1: Initial release
38
+
39
+ ## Installation
40
+
41
+ Add this line to your application's Gemfile:
42
+
43
+ ```ruby
44
+ gem 'jquery-rails-cdn'
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ This gem adds these methods to generate a script tag to the jQuery on a CDN of your preference:
50
+ `jquery_include_tag` and `jquery_url`
51
+ `jQuery_ui_include_tag` and `jquery_ui_url`
52
+
53
+ If you're using asset pipeline with Rails 3.1+, first remove `//= require jquery` and `//= require jquery-ui` from `application.js`.
54
+
55
+ Then in layout:
56
+
57
+ ```ruby
58
+ = jquery_include_tag :google
59
+ = jquery_ui_include_tag :google
60
+ = javascript_include_tag 'application'
61
+ ```
62
+
63
+ Note that valid CDN symbols for jQuery and jQuery-UI are:
64
+
65
+ ```ruby
66
+ :google
67
+ :microsoft
68
+ :jquery
69
+ :yandex
70
+ ```
71
+
72
+ Note that valid CDN symbols for bootstrap are:
73
+
74
+ ```ruby
75
+ :default
76
+ ```
77
+
78
+ It will generate the following for jQuery and similarly for jQuery-UI on production:
79
+
80
+ ```html
81
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
82
+ <script type="text/javascript">
83
+ //<![CDATA[
84
+ window.jQuery || document.write(unescape('%3Cscript src="/assets/jquery-86b29a215ef746103e2469f095a4df9e.js" type="text/javascript">%3C/script>'))
85
+ //]]>
86
+ </script>
87
+ ```
88
+
89
+ on development:
90
+
91
+ ```html
92
+ <script src="/assets/jquery.js?body=1" type="text/javascript"></script>
93
+ ```
94
+
95
+ If you want to check the production URL, you can pass `:force => true` as an option.
96
+
97
+ ```ruby
98
+ jquery_include_tag :google, :force => true
99
+ ```
100
+
101
+ To fallback to rails assets when CDN is not available, add `jquery.js` and `jquery-ui.js` in `config/environments/production.rb`
102
+
103
+ ```ruby
104
+ config.assets.precompile += %w( jquery.js jquery-ui.js )
105
+ ```
106
+
107
+ ## Clarification
108
+ [jquery-rails-cdn](https://github.com/kenn/jquery-rails-cdn) supports jQuery from jquery-rails gem, but [not jQuery UI](https://github.com/kenn/jquery-rails-cdn/issues/11) in the same gem. [jquery-ui-rails-cdn](https://github.com/styx/jquery-ui-rails-cdn) supports jQuery UI from jquery-ui-rails gem. This one supports both jQuery and jQuery UI from jquery-rails gem.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/jquery-rails-cdn/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Kenn Ejima", "Yen-Ju Chen"]
6
+ gem.email = ["kenn.ejima@gmail.com", "yjchenx@gmail.com"]
7
+ gem.description = %q{Add CDN support to jquery-rails}
8
+ gem.summary = %q{Add CDN support to jquery-rails}
9
+ gem.homepage = "https://github.com/yjchen/jquery-rails-cdn"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "jquery-rails-cdn-yjchen"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Jquery::Rails::Cdn::VERSION
17
+
18
+ gem.add_runtime_dependency "jquery-rails"
19
+ end
@@ -0,0 +1,7 @@
1
+ module Jquery
2
+ module Rails
3
+ module Cdn
4
+ VERSION = "0.3.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,61 @@
1
+ require 'jquery-rails'
2
+ require 'jquery-rails-cdn/version'
3
+
4
+ module Jquery::Rails::Cdn
5
+ module ActionViewExtensions
6
+ JQUERY_VERSION = Jquery::Rails::JQUERY_VERSION
7
+ JQUERY_UI_VERSION = Jquery::Rails::JQUERY_UI_VERSION
8
+ OFFLINE = (Rails.env.development? or Rails.env.test?)
9
+
10
+ CDNS = {
11
+ :jquery => {
12
+ :google => "//ajax.googleapis.com/ajax/libs/jquery/#{JQUERY_VERSION}/jquery.min.js",
13
+ :microsoft => "//ajax.aspnetcdn.com/ajax/jQuery/jquery-#{JQUERY_VERSION}.min.js",
14
+ :jquery => "//code.jquery.com/jquery-#{JQUERY_VERSION}.min.js",
15
+ :yandex => "//yandex.st/jquery/#{JQUERY_VERSION}/jquery.min.js"
16
+ },
17
+ :jquery_ui => {
18
+ :google => "//ajax.googleapis.com/ajax/libs/jqueryui/#{JQUERY_UI_VERSION}/jquery-ui.min.js",
19
+ :microsoft => "//ajax.aspnetcdn.com/ajax/jquery.ui/#{JQUERY_UI_VERSION}/jquery-ui.min.js",
20
+ :jquery => "//code.jquery.com/ui/#{JQUERY_UI_VERSION}/jquery-ui.min.js",
21
+ :yandex => "//yandex.st/jquery-ui/#{JQUERY_UI_VERSION}/jquery-ui.min.js"
22
+ },
23
+ }
24
+
25
+ def jquery_url(name, options = {})
26
+ return CDNS[:jquery][name]
27
+ end
28
+
29
+ def jquery_ui_url(name, options = {})
30
+ return CDNS[:jquery_ui][name]
31
+ end
32
+
33
+ def jquery_include_tag(name, options = {})
34
+ if OFFLINE and !options[:force]
35
+ return javascript_include_tag(:jquery)
36
+ else
37
+ [ javascript_include_tag(jquery_url(name, options)),
38
+ javascript_tag("window.jQuery || document.write(unescape('#{javascript_include_tag(:jquery).gsub('<','%3C')}'))")
39
+ ].join("\n").html_safe
40
+ end
41
+ end
42
+
43
+ def jquery_ui_include_tag(name, options = {})
44
+ if OFFLINE and !options[:force]
45
+ return javascript_include_tag(:'jquery-ui')
46
+ else
47
+ [ javascript_include_tag(jquery_ui_url(name, options)),
48
+ javascript_tag("window.jQuery.ui || document.write(unescape('#{javascript_include_tag(:'jquery-ui').gsub('<','%3C')}'))")
49
+ ].join("\n").html_safe
50
+ end
51
+ end
52
+ end
53
+
54
+ class Railtie < Rails::Railtie
55
+ initializer 'jquery_rails_cdn.action_view' do |app|
56
+ ActiveSupport.on_load(:action_view) do
57
+ include Jquery::Rails::Cdn::ActionViewExtensions
58
+ end
59
+ end
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery-rails-cdn-yjchen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kenn Ejima
9
+ - Yen-Ju Chen
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-11-13 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: jquery-rails
17
+ requirement: &70271415758660 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70271415758660
26
+ description: Add CDN support to jquery-rails
27
+ email:
28
+ - kenn.ejima@gmail.com
29
+ - yjchenx@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - jquery-rails-cdn.gemspec
40
+ - lib/jquery-rails-cdn.rb
41
+ - lib/jquery-rails-cdn/version.rb
42
+ homepage: https://github.com/yjchen/jquery-rails-cdn
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.15
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Add CDN support to jquery-rails
66
+ test_files: []