rack-jquery 2.1.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +12 -2
- data/CHANGES.md +17 -0
- data/Gemfile +1 -1
- data/lib/rack/jquery.rb +41 -22
- data/lib/rack/jquery/version.rb +1 -1
- data/rack-jquery.gemspec +1 -1
- data/spec/rack_jquery_spec.rb +95 -38
- data/spec/spec_helper.rb +1 -0
- metadata +19 -29
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1f8217e954299f15d500ed1770ab57c6cbad54be
|
4
|
+
data.tar.gz: df41cb37dd2e07665172fe992c7cc46a24f9ba3d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6ac69ec9553d8e9338a42563b5938018fbec02ba1a89391a8c22f9a8967e37d47d88867f3b2fb9aafdc9bb6a54bdb4d43d8b9f8dde1749a4da885272931101f5
|
7
|
+
data.tar.gz: f43e2244312b1b1c68fd11a6de4aad6185d7ed0cdecee78af8f6881ab0ba259d49937e18bda93e00b554237671bc8669486e1ff1eab6ecb32c31afed211d6e6d
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,11 +1,21 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 1.9.2
|
4
|
-
- 1.9.3
|
5
3
|
- 2.0.0
|
4
|
+
- 2.1.0
|
5
|
+
- 2.2.2
|
6
|
+
- jruby-19mode # JRuby in 1.9 mode
|
7
|
+
- rbx
|
8
|
+
- ruby-head
|
9
|
+
- jruby-head
|
6
10
|
|
7
11
|
# whitelist
|
8
12
|
branches:
|
9
13
|
only:
|
10
14
|
- master
|
11
15
|
- develop
|
16
|
+
|
17
|
+
matrix:
|
18
|
+
allow_failures:
|
19
|
+
- rvm: jruby-head
|
20
|
+
- rvm: ruby-head
|
21
|
+
- rvm: rbx
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
# CH CH CH CHANGES #
|
2
2
|
|
3
|
+
## Wednesday the 2nd of September 2015, v2.2.1 ##
|
4
|
+
|
5
|
+
* Fixed typo that was leading to bug. Organisation set by `use` statement would be ignored in `cdn`. Introduced by commit 801a5a13a. Clarified spec for it.
|
6
|
+
* Fixed a different bug that also made setting organisation to `false` via the `use` statement to be ignored.
|
7
|
+
* Don't give coverage of the vendor.noindex directory.
|
8
|
+
|
9
|
+
----
|
10
|
+
|
11
|
+
|
12
|
+
## Tuesday the 1st of September 2015, v2.2.0 ##
|
13
|
+
|
14
|
+
* Google's CDN now serves v2.1.0 of JQuery, changes for that.
|
15
|
+
* Added debug and organisation :false options for `cdn`, I want to be able to use the fallback in development.
|
16
|
+
|
17
|
+
----
|
18
|
+
|
19
|
+
|
3
20
|
## Monday the 27th of January 2014, v2.1.0 ##
|
4
21
|
|
5
22
|
* Can pass `:raise` as an option to both `use` and `cdn` so that an exception is raised if the chosen organisation isn't running the current version of jQuery on its CDN. It will just warn otherwise.
|
data/Gemfile
CHANGED
data/lib/rack/jquery.rb
CHANGED
@@ -15,7 +15,7 @@ module Rack
|
|
15
15
|
module CDN
|
16
16
|
|
17
17
|
# Script tags for the Media Temple CDN
|
18
|
-
MEDIA_TEMPLE = "
|
18
|
+
MEDIA_TEMPLE = "//code.jquery.com/#{JQUERY_FILE_NAME}"
|
19
19
|
|
20
20
|
# Script tags for the Google CDN
|
21
21
|
GOOGLE = "//ajax.googleapis.com/ajax/libs/jquery/#{JQUERY_VERSION}/jquery.min.js"
|
@@ -28,11 +28,14 @@ module Rack
|
|
28
28
|
|
29
29
|
end
|
30
30
|
|
31
|
+
# path to the fallback script
|
32
|
+
FALLBACK_PATH = "/js/#{JQUERY_FILE_NAME}"
|
33
|
+
|
31
34
|
# This javascript checks if the jQuery object has loaded. If not, that most likely means the CDN is unreachable, so it uses the local minified jQuery.
|
32
35
|
FALLBACK = <<STR
|
33
36
|
<script type="text/javascript">
|
34
37
|
if (typeof jQuery == 'undefined') {
|
35
|
-
document.write(unescape("%3Cscript src='
|
38
|
+
document.write(unescape("%3Cscript src='#{FALLBACK_PATH}' type='text/javascript'%3E%3C/script%3E"))
|
36
39
|
};
|
37
40
|
</script>
|
38
41
|
STR
|
@@ -59,40 +62,56 @@ STR
|
|
59
62
|
# Rack::JQuery.cdn env
|
60
63
|
#
|
61
64
|
# # Choose the organisation
|
62
|
-
#
|
63
|
-
# # Choose the organisation
|
64
65
|
# Rack::JQuery.cdn env, :organisation => :cloudflare
|
65
66
|
#
|
67
|
+
# # Choose to use the fallback path instead
|
68
|
+
# Rack::JQuery.cdn env, :organisation => false
|
69
|
+
#
|
66
70
|
# # Raise an error if the organisation doesn't
|
67
71
|
# # support this version of jQuery
|
68
72
|
# Rack::JQuery.cdn env, :raise => true
|
69
73
|
#
|
74
|
+
# # Use the unminified version from the CDN
|
75
|
+
# Rack::JQuery.cdn env, :debug => true
|
70
76
|
def self.cdn( env, options={} )
|
71
77
|
if env.nil? || env.has_key?(:organisation)
|
72
78
|
fail ArgumentError, "The Rack::JQuery.cdn method needs the Rack environment passed to it, or at the very least, an empty hash."
|
73
79
|
end
|
74
80
|
|
75
|
-
|
76
|
-
|
77
|
-
|
81
|
+
|
82
|
+
organisation = options[:organisation]
|
83
|
+
if organisation.nil? # because false is valid
|
84
|
+
organisation = env["rack.jquery.organisation"].nil? ?
|
85
|
+
:media_temple :
|
86
|
+
env["rack.jquery.organisation"]
|
87
|
+
end
|
78
88
|
|
79
89
|
raise = raiser?( env, options )
|
80
90
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
91
|
+
unless organisation == false
|
92
|
+
script_src =
|
93
|
+
case organisation
|
94
|
+
when :media_temple
|
95
|
+
CDN::MEDIA_TEMPLE
|
96
|
+
when :microsoft
|
97
|
+
CDN::MICROSOFT
|
98
|
+
when :cloudflare
|
99
|
+
CDN::CLOUDFLARE
|
100
|
+
when :google
|
101
|
+
# meth = raise ? :fail : :warn
|
102
|
+
# send meth, "#{organisation.to_s.gsub('_', ' ').capitalize}'s #{WARNING}"
|
103
|
+
CDN::GOOGLE
|
104
|
+
else
|
105
|
+
CDN::MEDIA_TEMPLE
|
106
|
+
end
|
107
|
+
|
108
|
+
debug = options.fetch :debug, false
|
109
|
+
|
110
|
+
script_src = "#{script_src[0..-7]}js" if debug
|
111
|
+
"<script src='#{script_src}'></script>\n#{FALLBACK}"
|
112
|
+
else
|
113
|
+
"<script src='#{FALLBACK_PATH}'></script>"
|
94
114
|
end
|
95
|
-
"<script src='#{script}'></script>\n#{FALLBACK}"
|
96
115
|
end
|
97
116
|
|
98
117
|
|
@@ -119,7 +138,7 @@ STR
|
|
119
138
|
# use Rack::JQuery, :organisation => :cloudflare
|
120
139
|
#
|
121
140
|
# # Raise if CDN does not support this version of the jQuery library.
|
122
|
-
# use Rack::JQuery, :raise =>
|
141
|
+
# use Rack::JQuery, :raise => true
|
123
142
|
def initialize( app, options={} )
|
124
143
|
@app, @options = app, DEFAULT_OPTIONS.merge(options)
|
125
144
|
@http_path_to_jquery = ::File.join @options[:http_path], JQUERY_FILE_NAME
|
data/lib/rack/jquery/version.rb
CHANGED
data/rack-jquery.gemspec
CHANGED
data/spec/rack_jquery_spec.rb
CHANGED
@@ -65,27 +65,63 @@ describe "The class methods" do
|
|
65
65
|
context "#cdn" do
|
66
66
|
let(:env) { {} }
|
67
67
|
subject { Rack::JQuery.cdn env, :organisation => organisation }
|
68
|
-
|
68
|
+
let(:expected) { "<script src='#{src}'></script>\n#{Rack::JQuery::FALLBACK}" }
|
69
|
+
let(:unminified) { "#{src[0..-7]}js" }
|
69
70
|
context "Given the organisation option" do
|
70
71
|
context "of nil (the default)" do
|
71
72
|
let(:organisation) { nil }
|
72
|
-
|
73
|
+
let(:src){ Rack::JQuery::CDN::MEDIA_TEMPLE }
|
74
|
+
it { should == expected }
|
75
|
+
context "and debug" do
|
76
|
+
subject { Rack::JQuery.cdn env, :organisation => organisation, :debug => true }
|
77
|
+
it { should_not include expected }
|
78
|
+
it { should include unminified }
|
79
|
+
end
|
73
80
|
end
|
74
81
|
context "of :google" do
|
75
82
|
let(:organisation) { :google }
|
76
|
-
|
83
|
+
let(:src){ Rack::JQuery::CDN::GOOGLE }
|
84
|
+
it { should == expected }
|
85
|
+
context "and debug" do
|
86
|
+
subject { Rack::JQuery.cdn env, :organisation => organisation, :debug => true }
|
87
|
+
it { should_not include expected }
|
88
|
+
it { should include unminified }
|
89
|
+
end
|
77
90
|
end
|
78
91
|
context "of :microsoft" do
|
79
92
|
let(:organisation) { :microsoft }
|
80
|
-
|
93
|
+
let(:src){ Rack::JQuery::CDN::MICROSOFT }
|
94
|
+
it { should == expected }
|
95
|
+
context "and debug" do
|
96
|
+
subject { Rack::JQuery.cdn env, :organisation => organisation, :debug => true }
|
97
|
+
it { should_not include expected }
|
98
|
+
it { should include unminified }
|
99
|
+
end
|
81
100
|
end
|
82
101
|
context "of :media_temple" do
|
83
102
|
let(:organisation) { :media_temple }
|
84
|
-
|
103
|
+
let(:src){ Rack::JQuery::CDN::MEDIA_TEMPLE }
|
104
|
+
it { should == expected }
|
105
|
+
context "and debug" do
|
106
|
+
subject { Rack::JQuery.cdn env, :organisation => organisation, :debug => true }
|
107
|
+
it { should_not include expected }
|
108
|
+
it { should include unminified }
|
109
|
+
end
|
85
110
|
end
|
86
111
|
context "of :cloudflare" do
|
87
112
|
let(:organisation) { :cloudflare }
|
88
|
-
|
113
|
+
let(:src){ Rack::JQuery::CDN::CLOUDFLARE }
|
114
|
+
it { should == expected }
|
115
|
+
context "and debug" do
|
116
|
+
subject { Rack::JQuery.cdn env, :organisation => organisation, :debug => true }
|
117
|
+
it { should_not include expected }
|
118
|
+
it { should include unminified }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
context "of false" do
|
122
|
+
let(:organisation) { false }
|
123
|
+
let(:expected) { "<script src='/js/#{Rack::JQuery::JQUERY_FILE_NAME}'></script>"}
|
124
|
+
it { should == expected }
|
89
125
|
end
|
90
126
|
end
|
91
127
|
|
@@ -119,44 +155,55 @@ describe "Inserting the CDN" do
|
|
119
155
|
it_should_behave_like "Any route"
|
120
156
|
end
|
121
157
|
context "Google CDN" do
|
122
|
-
context "With :raise set
|
158
|
+
context "With :raise set" do
|
123
159
|
let(:expected) { Rack::JQuery::CDN::GOOGLE }
|
124
|
-
|
125
|
-
|
160
|
+
context "to false (the default)" do
|
161
|
+
before do
|
162
|
+
get "/google-cdn"
|
163
|
+
end
|
164
|
+
it_should_behave_like "Any route"
|
165
|
+
subject { last_response.body }
|
166
|
+
it { should include expected }
|
126
167
|
end
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
use Rack::JQuery, :raise => true
|
136
|
-
get "/google-cdn" do
|
137
|
-
Rack::JQuery.cdn( env, :organisation => :google )
|
168
|
+
context "to true" do
|
169
|
+
context "via `use`" do
|
170
|
+
let(:app) {
|
171
|
+
Sinatra.new do
|
172
|
+
use Rack::JQuery, :raise => true
|
173
|
+
get "/google-cdn" do
|
174
|
+
Rack::JQuery.cdn( env, :organisation => :google )
|
175
|
+
end
|
138
176
|
end
|
177
|
+
}
|
178
|
+
# it "should raise error as it's not supported for this version" do
|
179
|
+
# expect { get "/google-cdn" }.to raise_error
|
180
|
+
# end
|
181
|
+
before do
|
182
|
+
get "/google-cdn"
|
139
183
|
end
|
140
|
-
|
141
|
-
|
142
|
-
|
184
|
+
it_should_behave_like "Any route"
|
185
|
+
subject { last_response.body }
|
186
|
+
it { should include expected }
|
143
187
|
end
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
Rack::JQuery.cdn( env, :organisation => :google, :raise => true )
|
188
|
+
context "via the method options" do
|
189
|
+
let(:app) {
|
190
|
+
Sinatra.new do
|
191
|
+
use Rack::JQuery
|
192
|
+
get "/google-cdn" do
|
193
|
+
Rack::JQuery.cdn( env, :organisation => :google, :raise => true )
|
194
|
+
end
|
152
195
|
end
|
196
|
+
}
|
197
|
+
# it "should raise error as it's not supported for this version" do
|
198
|
+
# expect { subject }.to raise_error
|
199
|
+
# end
|
200
|
+
before do
|
201
|
+
get "/google-cdn"
|
153
202
|
end
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
expect { subject }.to raise_error
|
203
|
+
it_should_behave_like "Any route"
|
204
|
+
subject { last_response.body }
|
205
|
+
it { should include expected }
|
158
206
|
end
|
159
|
-
# it { should include expected }
|
160
207
|
end
|
161
208
|
end
|
162
209
|
end
|
@@ -184,6 +231,9 @@ describe "Inserting the CDN" do
|
|
184
231
|
end
|
185
232
|
it_should_behave_like "Any route"
|
186
233
|
subject { last_response.body }
|
234
|
+
# The cloudflare CDN is specified in the app
|
235
|
+
# via the `use` statement, so it will be the one
|
236
|
+
# picked when unspecified via `cdn`
|
187
237
|
let(:expected) { Rack::JQuery::CDN::CLOUDFLARE }
|
188
238
|
it { should include expected }
|
189
239
|
end
|
@@ -206,9 +256,16 @@ describe "Inserting the CDN" do
|
|
206
256
|
it_should_behave_like "Any route"
|
207
257
|
end
|
208
258
|
context "Google CDN" do
|
209
|
-
|
210
|
-
|
259
|
+
# it "Should fail" do
|
260
|
+
# expect { get "/google-cdn" }.to raise_error
|
261
|
+
# end
|
262
|
+
before do
|
263
|
+
get "/google-cdn"
|
211
264
|
end
|
265
|
+
it_should_behave_like "Any route"
|
266
|
+
subject { last_response.body }
|
267
|
+
let(:expected) { Rack::JQuery::CDN::GOOGLE }
|
268
|
+
it { should include expected }
|
212
269
|
end
|
213
270
|
context "Microsoft CDN" do
|
214
271
|
before do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,78 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-jquery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1
|
5
|
-
prerelease:
|
4
|
+
version: 2.2.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Iain Barnett
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-09-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.2'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.2'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rack
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
47
|
+
version: 1.5.0
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
54
|
+
version: 1.5.0
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rack-jquery-helpers
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
description: jQuery CDN script tags and fallback in one neat package. Current version
|
@@ -83,8 +74,8 @@ executables: []
|
|
83
74
|
extensions: []
|
84
75
|
extra_rdoc_files: []
|
85
76
|
files:
|
86
|
-
- .gitignore
|
87
|
-
- .travis.yml
|
77
|
+
- ".gitignore"
|
78
|
+
- ".travis.yml"
|
88
79
|
- CHANGES.md
|
89
80
|
- Gemfile
|
90
81
|
- JQUERY-LICENCE.txt
|
@@ -103,27 +94,26 @@ files:
|
|
103
94
|
homepage: https://github.com/yb66/rack-jquery
|
104
95
|
licenses:
|
105
96
|
- MIT
|
97
|
+
metadata: {}
|
106
98
|
post_install_message:
|
107
99
|
rdoc_options: []
|
108
100
|
require_paths:
|
109
101
|
- lib
|
110
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
-
none: false
|
112
103
|
requirements:
|
113
|
-
- -
|
104
|
+
- - ">="
|
114
105
|
- !ruby/object:Gem::Version
|
115
106
|
version: '0'
|
116
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
-
none: false
|
118
108
|
requirements:
|
119
|
-
- -
|
109
|
+
- - ">="
|
120
110
|
- !ruby/object:Gem::Version
|
121
111
|
version: '0'
|
122
112
|
requirements: []
|
123
113
|
rubyforge_project:
|
124
|
-
rubygems_version:
|
114
|
+
rubygems_version: 2.4.5
|
125
115
|
signing_key:
|
126
|
-
specification_version:
|
116
|
+
specification_version: 4
|
127
117
|
summary: The description says it all.
|
128
118
|
test_files:
|
129
119
|
- spec/rack_jquery_spec.rb
|