rack-jquery_ui 2.2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # CH CH CHANGES #
2
2
 
3
+ ## Monday the 4th of November 2013, v3.0.0 ##
4
+
5
+ * The `cdn` method now takes the Rack env as its first argument, which it should have always done, but at least now it does, so the defaults actually get passed on if set.
6
+
7
+ ----
8
+
9
+
10
+ ## Tuesday the 30th of July 2013 ##
11
+
12
+ ### v2.3.1 ###
13
+
14
+ * Fixed some typos in the README.
15
+
16
+ ----
17
+
18
+
19
+ ### v2.3.0 ###
20
+
21
+ * Added option to pass `false` to the `cdn` method, which then ignores the CDN's and uses the local fallback scripts.
22
+ * Media Temple CDN wasn't using the minified version of the file by default, now it is.
23
+ * Added a :debug option to the `cdn` method so that the unminified version of the file can be called. Doesn't work with the fallback script as the unminified versions aren't bundled with this library.
24
+
25
+ ----
26
+
27
+
3
28
  ## Friday the 19th of July 2013, v2.2.0 ##
4
29
 
5
30
  * Made Media Temple the default CDN as Google (and Microsoft) have sided with the Elzebub, otherwise known as the NSA and GCHQ, and there's no need to make tracking people around the net easier for them.
data/README.md CHANGED
@@ -22,11 +22,13 @@ Have a look in the examples directory, but here's a snippet.
22
22
 
23
23
 
24
24
  %head
25
- = Rack::JQueryUI.cdn
25
+ = Rack::JQueryUI.cdn env
26
+
27
+ where `env` is the Rack env.
26
28
 
27
29
  Now you have the script tags to Media Temple's CDN in the head (you can also use Google or Microsoft, or Cloudflare, see the docs).
28
30
 
29
- It also adds in a bit of javascript that will load in a locally kept version of jQuery, just incase the CDN is unreachable. The script will use the "/js/jquery-ui/1.10.3/jquery-ui.min.js" path (or, instead of 1.10.3, whatever is in {Rack::JQuery::VERSION}). You can change the "/js" bit if you like (see the docs).
31
+ It also adds in a bit of javascript that will load in a locally kept version of jQuery UI, just in case the CDN is unreachable. The script will use the "/js/jquery-ui/1.10.3/jquery-ui.min.js" path (or, instead of 1.10.3, whatever is in {Rack::JQueryUI::VERSION}). You can change the "/js" bit if you like (see the docs).
30
32
 
31
33
  That was easy.
32
34
 
@@ -41,9 +43,9 @@ I made a mistake and pushed out a version of the library where not all the CDNs
41
43
  To stop this happening again I've added more checks, but there's also a choice for the library user. If you've picked a CDN to use, something like this:
42
44
 
43
45
  %head
44
- = Rack::JQueryUI.cdn :microsoft
46
+ = Rack::JQueryUI.cdn env, :organisation => :microsoft
45
47
 
46
- and it doesn't support the jQuery UI version, then it will silently use the default CDN (usually Google's, but it will change depending on who supports what).
48
+ and it doesn't support the jQuery UI version, then it will silently use the default CDN (usually Media Temple's, but it will change depending on who supports what).
47
49
 
48
50
  If you'd prefer an exception to be raised you can either do this:
49
51
 
@@ -52,7 +54,7 @@ If you'd prefer an exception to be raised you can either do this:
52
54
  or
53
55
 
54
56
  %head
55
- = Rack::JQueryUI.cdn :microsoft, :raise => true
57
+ = Rack::JQueryUI.cdn env, :organisation => :microsoft, :raise => true
56
58
 
57
59
  the second way will always override the first.
58
60
 
@@ -0,0 +1,26 @@
1
+ # require 'rack'
2
+
3
+ require 'sinatra'
4
+
5
+ class MyMiddleware
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ warn env.inspect
12
+ @app.call(env)
13
+ end
14
+ end
15
+
16
+
17
+ use Rack::Session::Cookie, key: '_dummy_session', secret: '...'
18
+ use MyMiddleware
19
+ app = Sinatra.new do
20
+ get("/") {
21
+ session["blah"] = "more blah"
22
+ "HEllo"
23
+ }
24
+ end
25
+
26
+ run app
@@ -9,33 +9,51 @@ class App < Sinatra::Base
9
9
  use Rack::JQuery
10
10
  use Rack::JQueryUI
11
11
 
12
+ %w{google media_temple microsoft cloudflare unspecified}.each do |name|
13
+
14
+ get "/#{name}-cdn" do
15
+ haml :accordion, :layout => name.to_sym
16
+ end
17
+ end
18
+
12
19
  get "/" do
13
20
  haml :index, :layout => :unspecified
14
21
  end
15
22
 
16
- get "/google-cdn" do
17
- haml :accordion, :layout => :google
23
+ get "/fallback-only" do
24
+ haml :accordion, :layout => :fallback
18
25
  end
19
26
 
20
- get "/media-temple-cdn" do
21
- haml :accordion, :layout => :mediatemple
27
+ get "/ui/:plugin" do |plugin|
28
+ haml plugin.to_sym, :layout => :ui
22
29
  end
30
+ end
23
31
 
24
- get "/microsoft-cdn" do
25
- haml :accordion, :layout => :microsoft
32
+ class AppWithDefaults < Sinatra::Base
33
+
34
+ enable :inline_templates
35
+ use Rack::JQuery
36
+ use Rack::JQueryUI, :organisation => :cloudflare
37
+
38
+ %w{google media_temple microsoft cloudflare unspecified}.each do |name|
39
+
40
+ get "/#{name}-cdn" do
41
+ haml :accordion, :layout => name.to_sym
42
+ end
26
43
  end
27
44
 
28
- get "/cloudflare-cdn" do
29
- haml :accordion, :layout => :cloudflare
45
+ get "/" do
46
+ haml :index, :layout => :unspecified
30
47
  end
31
48
 
32
- get "/unspecified-cdn" do
33
- haml :accordion, :layout => :unspecified
49
+ get "/fallback-only" do
50
+ haml :accordion, :layout => :fallback
34
51
  end
35
52
 
36
53
  get "/ui/:plugin" do |plugin|
37
54
  haml plugin.to_sym, :layout => :ui
38
55
  end
56
+
39
57
  end
40
58
 
41
59
  __END__
@@ -43,9 +61,9 @@ __END__
43
61
  @@google
44
62
  %html
45
63
  %head
46
- = Rack::JQuery.cdn( :google )
47
- = Rack::JQueryUI.cdn( :google )
48
- %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/base/jquery-ui.css", rel: "stylesheet"}
64
+ = Rack::JQuery.cdn( env, :organisation => :google )
65
+ = Rack::JQueryUI.cdn( env, :organisation => :google )
66
+ %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/smoothness/jquery-ui.css", rel: "stylesheet"}
49
67
  :css
50
68
  body {
51
69
  font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
@@ -56,9 +74,9 @@ __END__
56
74
  @@microsoft
57
75
  %html
58
76
  %head
59
- = Rack::JQuery.cdn( :microsoft )
60
- = Rack::JQueryUI.cdn( :microsoft )
61
- %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/base/jquery-ui.css", rel: "stylesheet"}
77
+ = Rack::JQuery.cdn( env, :organisation => :microsoft )
78
+ = Rack::JQueryUI.cdn( env, :organisation => :microsoft )
79
+ %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/smoothness/jquery-ui.css", rel: "stylesheet"}
62
80
  :css
63
81
  body {
64
82
  font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
@@ -69,9 +87,9 @@ __END__
69
87
  @@cloudflare
70
88
  %html
71
89
  %head
72
- = Rack::JQuery.cdn( :cloudflare )
73
- = Rack::JQueryUI.cdn( :cloudflare )
74
- %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/base/jquery-ui.css", rel: "stylesheet"}
90
+ = Rack::JQuery.cdn( env, :organisation => :cloudflare )
91
+ = Rack::JQueryUI.cdn( env, :organisation => :cloudflare )
92
+ %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/smoothness/jquery-ui.css", rel: "stylesheet"}
75
93
  :css
76
94
  body {
77
95
  font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
@@ -79,12 +97,12 @@ __END__
79
97
  }
80
98
  = yield
81
99
 
82
- @@mediatemple
100
+ @@media_temple
83
101
  %html
84
102
  %head
85
- = Rack::JQuery.cdn( :media_temple )
86
- = Rack::JQueryUI.cdn( :media_temple )
87
- %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/base/jquery-ui.css", rel: "stylesheet"}
103
+ = Rack::JQuery.cdn( env, :organisation => :media_temple )
104
+ = Rack::JQueryUI.cdn( env, :organisation => :media_temple )
105
+ %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/smoothness/jquery-ui.css", rel: "stylesheet"}
88
106
  :css
89
107
  body {
90
108
  font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
@@ -95,9 +113,9 @@ __END__
95
113
  @@unspecified
96
114
  %html
97
115
  %head
98
- = Rack::JQuery.cdn()
99
- = Rack::JQueryUI.cdn()
100
- %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/base/jquery-ui.css", rel: "stylesheet"}
116
+ = Rack::JQuery.cdn(env)
117
+ = Rack::JQueryUI.cdn(env)
118
+ %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/smoothness/jquery-ui.css", rel: "stylesheet"}
101
119
  :css
102
120
  body {
103
121
  font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
@@ -106,12 +124,25 @@ __END__
106
124
  %body
107
125
  = yield
108
126
 
127
+ @@fallback
128
+ %html
129
+ %head
130
+ = Rack::JQuery.cdn env
131
+ = Rack::JQueryUI.cdn( env, :organisation => false )
132
+ %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/smoothness/jquery-ui.css", rel: "stylesheet"}
133
+ :css
134
+ body {
135
+ font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
136
+ font-size: 62.5%;
137
+ }
138
+ = yield
139
+
109
140
  @@ui
110
141
  %html
111
142
  %head
112
- = Rack::JQuery.cdn()
113
- = Rack::JQueryUI.cdn()
114
- %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/base/jquery-ui.css", rel: "stylesheet"}
143
+ = Rack::JQuery.cdn(env)
144
+ = Rack::JQueryUI.cdn(env)
145
+ %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/smoothness/jquery-ui.css", rel: "stylesheet"}
115
146
  :css
116
147
  body {
117
148
  font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
@@ -136,6 +167,9 @@ __END__
136
167
  %p
137
168
  %a{ href: "/unspecified-cdn" }
138
169
  unspecified-cdn
170
+ %p
171
+ %a{ href: "/fallback-only" }
172
+ forced fallback
139
173
  %p
140
174
  %a{ href: "/ui/accordion" }
141
175
  accordion
@@ -3,4 +3,9 @@ require "bundler"
3
3
  Bundler.setup(:examples)
4
4
  require File.expand_path( '../config.rb', __FILE__)
5
5
 
6
+
7
+ map "/defaults" do
8
+ run AppWithDefaults
9
+ end
10
+
6
11
  run App
@@ -17,7 +17,7 @@ module Rack
17
17
  module CDNs
18
18
 
19
19
  # Script tags for the Media Temple CDN
20
- MEDIA_TEMPLE = "http://code.jquery.com/ui/#{JQUERY_UI_VERSION}/jquery-ui.js"
20
+ MEDIA_TEMPLE = "http://code.jquery.com/ui/#{JQUERY_UI_VERSION}/jquery-ui.min.js"
21
21
 
22
22
  # Script tags for the Google CDN
23
23
  GOOGLE = "//ajax.googleapis.com/ajax/libs/jqueryui/#{JQUERY_UI_VERSION}/jquery-ui.min.js"
@@ -30,32 +30,72 @@ module Rack
30
30
  CLOUDFLARE = "//cdnjs.cloudflare.com/ajax/libs/jqueryui/#{JQUERY_UI_VERSION}/jquery-ui.min.js"
31
31
  end
32
32
 
33
+
34
+ # path to the fallback script
35
+ FALLBACK_PATH = "/js/jquery-ui/#{JQUERY_UI_VERSION}/#{JQUERY_UI_FILE_NAME}"
36
+
33
37
  # This javascript checks if the jQuery-UI object has loaded. If not, that most likely means the CDN is unreachable, so it uses the local minified jQuery.
34
38
  FALLBACK = <<STR
35
39
  <script type="text/javascript">
36
- !window.jQuery.ui && document.write(unescape("%3Cscript src='/js/jquery-ui/#{JQUERY_UI_VERSION}/#{JQUERY_UI_FILE_NAME}' type='text/javascript'%3E%3C/script%3E"))
40
+ !window.jQuery.ui && document.write(unescape("%3Cscript src='#{FALLBACK_PATH}' type='text/javascript'%3E%3C/script%3E"))
37
41
  </script>
38
42
  STR
39
43
 
40
44
 
41
- # @param [Symbol] organisation Choose which CDN to use, either :google, :microsoft or :media_temple, or :cloudflare
45
+ # @param [Hash] env The rack env hash.
46
+ # @param [Hash] options
47
+ # @option options [Symbol,false,nil] :organisation Choose which CDN to use, either :google, :microsoft or :media_temple, or :cloudflare. Pass in `false` to force use of the local jQuery script. `nil` will force choosing the default CDN.
48
+ # @option options [true, false] :debug If you need the unminified version from the CDN for debugging then pass this in. The unminified scripts aren't included via the fallback to keep the library light, so this won't change anything if fallback is used.
42
49
  # @return [String] The HTML script tags to get the CDN.
43
- def self.cdn( organisation=:media_temple, options={} )
50
+ # @example
51
+ # # in a Haml file… (but could be any type of template)
52
+ # # For the default
53
+ # Rack::JQueryUI.cdn env
54
+ #
55
+ # # Choose the organisation
56
+ # Rack::JQueryUI.cdn env, :organisation => :cloudflare
57
+ #
58
+ # # Raise an error if the organisation doesn't
59
+ # # support this version of jQuery UI
60
+ # Rack::JQueryUI.cdn env, :raise => true
61
+ #
62
+ # # Use the unminified version from the CDN
63
+ # Rack::JQueryUI.cdn env, :debug => true
64
+ #
65
+ def self.cdn( env, options={} )
66
+ if env.nil? || env.has_key?(:organisation)
67
+ fail ArgumentError, "The Rack::JQueryUI.cdn method needs the Rack environment passed to it, or at the very least, an empty hash."
68
+ end
44
69
  raise = (opt = options[:raise]).nil? ?
45
- raise? :
46
- opt
47
- script = if organisation === :media_temple
48
- CDNs::MEDIA_TEMPLE
49
- elsif organisation === :microsoft
50
- CDNs::MICROSOFT
51
- elsif organisation === :cloudflare
52
- CDNs::CLOUDFLARE
53
- elsif organisation === :google
54
- CDNs::GOOGLE
55
- else
56
- CDNs::MEDIA_TEMPLE
70
+ opt :
71
+ (env["rack.jquery_ui.raise"] || false)
72
+
73
+ organisation = options[:organisation]
74
+ if organisation.nil? # because false is valid
75
+ organisation = env["rack.jquery_ui.organisation"] ||
76
+ :media_temple
77
+ end
78
+
79
+ unless organisation == false
80
+ script_src = if organisation === :media_temple
81
+ CDNs::MEDIA_TEMPLE
82
+ elsif organisation === :microsoft
83
+ CDNs::MICROSOFT
84
+ elsif organisation === :cloudflare
85
+ CDNs::CLOUDFLARE
86
+ elsif organisation === :google
87
+ CDNs::GOOGLE
88
+ else
89
+ CDNs::MEDIA_TEMPLE
90
+ end
91
+
92
+ debug = options.fetch :debug, false
93
+
94
+ script_src = "#{script_src[0..-7]}js" if debug
95
+ "<script src='#{script_src}'></script>\n#{FALLBACK}"
96
+ else
97
+ "<script src='#{FALLBACK_PATH}'></script>"
57
98
  end
58
- "<script src='#{script}'></script>\n#{FALLBACK}"
59
99
  end
60
100
 
61
101
 
@@ -66,22 +106,6 @@ STR
66
106
  }
67
107
 
68
108
 
69
- # Whether to raise an exception if the chosen CDN
70
- # does not support the jQuery UI version this library is using
71
- # @param [TrueClass] bool
72
- def self.raise=( bool )
73
- @raise = bool
74
- end
75
-
76
-
77
- # @see raise=
78
- # @return [TrueClass]
79
- def self.raise?
80
- @raise = false if @raise.nil?
81
- @raise
82
- end
83
-
84
-
85
109
  # @param [#call] app
86
110
  # @param [Hash] options
87
111
  # @option options [String] :http_path If you wish the jQuery fallback route to be "/js/jquery-ui/1.10.1/jquery-ui.min.js" (or whichever version this is at) then do nothing, that's the default. If you want the path to be "/assets/javascripts/jquery-ui/1.10.1/jquery-ui.min.js" then pass in `:http_path => "/assets/javascripts/#{Rack::JQueryUI::JQUERY_UI_VERSION}".
@@ -95,7 +119,8 @@ STR
95
119
  def initialize( app, options={} )
96
120
  @app, @options = app, DEFAULT_OPTIONS.merge(options)
97
121
  @http_path_to_jquery = ::File.join @options[:http_path], JQUERY_UI_FILE_NAME
98
- self.class.raise = @options[:raise]
122
+ @raise = @options.fetch :raise, false
123
+ @organisation = options.fetch :organisation, :media_temple
99
124
  end
100
125
 
101
126
 
@@ -109,6 +134,8 @@ STR
109
134
  # @param (see #call)
110
135
  def _call( env )
111
136
  request = Rack::Request.new(env.dup)
137
+ env.merge! "rack.jquery_ui.organisation" => @organisation
138
+ env.merge! "rack.jquery_ui.raise" => @raise
112
139
  if request.path_info == @http_path_to_jquery
113
140
  response = Rack::Response.new
114
141
  # for caching
@@ -1,7 +1,7 @@
1
1
  module Rack
2
2
  class JQueryUI
3
3
  # library version
4
- VERSION = "2.2.0"
4
+ VERSION = "3.0.0"
5
5
 
6
6
  # This is here in case another rack-jquery_ui library has already been loaded.
7
7
  jquery_ui_version = "1.10.3"
@@ -4,115 +4,271 @@ require 'spec_helper'
4
4
  require_relative "../lib/rack/jquery_ui.rb"
5
5
 
6
6
  describe "The class methods" do
7
- subject { Rack::JQueryUI.cdn organisation }
8
- context "Given an argument" do
7
+ let(:env) { {} }
8
+ subject { Rack::JQueryUI.cdn env, :organisation => organisation }
9
+
10
+ context "Given the organisation option" do
11
+ subject { Rack::JQueryUI.cdn env, :organisation => organisation }
12
+ let(:expected) { "<script src='#{src}'></script>\n#{Rack::JQueryUI::FALLBACK}" }
9
13
  context "of nil (the default)" do
10
14
  let(:organisation) { nil }
11
- it { should == "<script src='#{Rack::JQueryUI::CDNs::MEDIA_TEMPLE}'></script>\n#{Rack::JQueryUI::FALLBACK}" }
15
+ let(:src) { Rack::JQueryUI::CDNs::MEDIA_TEMPLE }
16
+ it { should == expected }
17
+ context "and debug" do
18
+ let(:unminified) { "#{src[0..-7]}js" }
19
+ subject { Rack::JQueryUI.cdn env, :organisation => organisation, :debug => true }
20
+ it { should_not include expected }
21
+ it { should include unminified }
22
+ end
12
23
  end
13
24
  context "of :google" do
14
25
  let(:organisation) { :google }
15
- it { should == "<script src='#{Rack::JQueryUI::CDNs::GOOGLE}'></script>\n#{Rack::JQueryUI::FALLBACK}" }
26
+ let(:src) { Rack::JQueryUI::CDNs::GOOGLE }
27
+ it { should == expected }
28
+ context "and debug" do
29
+ let(:unminified) { "#{src[0..-7]}js" }
30
+ subject { Rack::JQueryUI.cdn env, :organisation => organisation, :debug => true }
31
+ it { should_not include expected }
32
+ it { should include unminified }
33
+ end
16
34
  end
17
35
  context "of :microsoft" do
18
36
  let(:organisation) { :microsoft }
19
- it { should == "<script src='#{Rack::JQueryUI::CDNs::MICROSOFT}'></script>\n#{Rack::JQueryUI::FALLBACK}" }
37
+ let(:src) { Rack::JQueryUI::CDNs::MICROSOFT }
38
+ it { should == expected }
39
+ context "and debug" do
40
+ let(:unminified) { "#{src[0..-7]}js" }
41
+ subject { Rack::JQueryUI.cdn env, :organisation => organisation, :debug => true }
42
+ it { should_not include expected }
43
+ it { should include unminified }
44
+ end
20
45
  end
21
46
  context "of :media_temple" do
22
47
  let(:organisation) { :media_temple }
23
- it { should == "<script src='#{Rack::JQueryUI::CDNs::MEDIA_TEMPLE}'></script>\n#{Rack::JQueryUI::FALLBACK}" }
48
+ let(:src) { Rack::JQueryUI::CDNs::MEDIA_TEMPLE }
49
+ it { should == expected }
50
+ context "and debug" do
51
+ let(:unminified) { "#{src[0..-7]}js" }
52
+ subject { Rack::JQueryUI.cdn env, :organisation => organisation, :debug => true }
53
+ it { should_not include expected }
54
+ it { should include unminified }
55
+ end
24
56
  end
25
57
  context "of :cloudflare" do
26
58
  let(:organisation) { :cloudflare }
27
- # context "When raise is true" do
28
- # subject { Rack::JQueryUI.cdn organisation, {raise: true} }
29
- # it "should raise error as it's not supported for this version" do
30
- # expect { subject }.to raise_error
31
- # end
32
- # end
33
- it { should == "<script src='#{Rack::JQueryUI::CDNs::CLOUDFLARE}'></script>\n#{Rack::JQueryUI::FALLBACK}" }
59
+ let(:src) { Rack::JQueryUI::CDNs::CLOUDFLARE }
60
+ it { should == expected }
61
+ context "and debug" do
62
+ let(:unminified) { "#{src[0..-7]}js" }
63
+ subject { Rack::JQueryUI.cdn env, :organisation => organisation, :debug => true }
64
+ it { should_not include expected }
65
+ it { should include unminified }
66
+ end
67
+ end
68
+ context "of false" do
69
+ let(:organisation) { false }
70
+ let(:expected) { "<script src='/js/jquery-ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/#{Rack::JQueryUI::JQUERY_UI_FILE_NAME}'></script>"}
71
+ it { should == expected }
72
+ end
73
+ end
74
+
75
+ context "Given no Rack env argument" do
76
+ it "should fail and give a message" do
77
+ expect{ Rack::JQueryUI.cdn nil }.to raise_error(ArgumentError)
78
+ end
79
+
80
+ context "and an organisation option" do
81
+ it "should fail and give a message" do
82
+ expect{ Rack::JQueryUI.cdn nil, {:organisation => :microsoft} }.to raise_error(ArgumentError)
83
+ end
34
84
  end
35
85
  end
36
86
  end
37
87
 
38
88
  describe "Inserting the CDN" do
39
- include_context "All routes"
40
- context "Check the examples run at all" do
41
- before do
42
- get "/"
89
+ context "When not given a default" do
90
+ include_context "All routes"
91
+ context "Check the examples run at all" do
92
+ before do
93
+ get "/"
94
+ end
95
+ it_should_behave_like "Any route"
43
96
  end
44
- it_should_behave_like "Any route"
45
- end
46
- context "Google CDN" do
47
- before do
48
- get "/google-cdn"
97
+ context "Google CDN" do
98
+ before do
99
+ get "/google-cdn"
100
+ end
101
+ it_should_behave_like "Any route"
102
+ subject { last_response.body }
103
+ let(:expected) { Rack::JQueryUI::CDNs::GOOGLE }
104
+ it { should include expected }
105
+ end
106
+ context "Cloudflare CDN" do
107
+ before do
108
+ get "/cloudflare-cdn"
109
+ end
110
+ it_should_behave_like "Any route"
111
+ subject { last_response.body }
112
+ context "With :raise set to false" do
113
+ let(:expected) { Rack::JQueryUI::CDNs::CLOUDFLARE }
114
+ it { should include expected }
115
+ end
116
+ context "With :raise set to true" do
117
+ context "via `use`" do
118
+ let(:app) {
119
+ Sinatra.new do
120
+ use Rack::JQuery
121
+ use Rack::JQueryUI, :raise => true
122
+ get "/cloudflare-cdn" do
123
+ Rack::JQueryUI.cdn( env, :organisation => :cloudflare )
124
+ end
125
+ end
126
+ }
127
+ # it "should raise error as it's not supported for this version" do
128
+ # expect { subject }.to raise_error
129
+ # end
130
+ it { should include "//cdnjs.cloudflare.com/ajax/libs/jqueryui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/jquery-ui.min.js" }
131
+ end
132
+ context "via the method options" do
133
+ let(:app) {
134
+ Sinatra.new do
135
+ use Rack::JQuery
136
+ use Rack::JQueryUI, :raise => false
137
+ get "/cloudflare-cdn" do
138
+ Rack::JQueryUI.cdn( env, :organisation => :cloudflare, :raise => true )
139
+ end
140
+ end
141
+ }
142
+ # subject { get "/cloudflare-cdn" }
143
+ # it "should raise error as it's not supported for this version" do
144
+ # expect { subject }.to raise_error
145
+ # end
146
+ it { should include "//cdnjs.cloudflare.com/ajax/libs/jqueryui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/jquery-ui.min.js" }
147
+ end
148
+ end
149
+ end
150
+ context "Media_temple CDN" do
151
+ before do
152
+ get "/media_temple-cdn"
153
+ end
154
+ it_should_behave_like "Any route"
155
+ subject { last_response.body }
156
+ let(:expected) { Rack::JQueryUI::CDNs::MEDIA_TEMPLE }
157
+ it { should include expected }
158
+ end
159
+ context "Unspecified CDN" do
160
+ before do
161
+ get "/unspecified-cdn"
162
+ end
163
+ it_should_behave_like "Any route"
164
+ subject { last_response.body }
165
+ let(:expected) { Rack::JQueryUI::CDNs::MEDIA_TEMPLE }
166
+ it { should include expected }
167
+ end
168
+ context "No CDN, force the fallback" do
169
+ before do
170
+ get "/fallback-only"
171
+ end
172
+ it_should_behave_like "Any route"
173
+ subject { last_response.body }
174
+ let(:expected) { "<script src='/js/jquery-ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/#{Rack::JQueryUI::JQUERY_UI_FILE_NAME}'></script>" }
175
+ it { should include expected }
49
176
  end
50
- it_should_behave_like "Any route"
51
- subject { last_response.body }
52
- let(:expected) { Rack::JQueryUI::CDNs::GOOGLE }
53
- it { should include expected }
54
177
  end
55
- context "Cloudflare CDN" do
56
- before do
57
- get "/cloudflare-cdn"
178
+
179
+ # These check the default is overriden
180
+ # when `cdn` is given a value
181
+ # but when not, the default is used.
182
+ context "When given a default" do
183
+ include_context "All routes" do
184
+ let(:app){ AppWithDefaults }
58
185
  end
59
- it_should_behave_like "Any route"
60
- subject { last_response.body }
61
- context "With :raise set to false" do
62
- let(:expected) { Rack::JQueryUI::CDNs::CLOUDFLARE }
186
+ context "Check the examples run at all" do
187
+ before do
188
+ get "/"
189
+ end
190
+ it_should_behave_like "Any route"
191
+ end
192
+ context "Google CDN" do
193
+ before do
194
+ get "/google-cdn"
195
+ end
196
+ it_should_behave_like "Any route"
197
+ subject { last_response.body }
198
+ let(:expected) { Rack::JQueryUI::CDNs::GOOGLE }
63
199
  it { should include expected }
64
200
  end
65
- context "With :raise set to true" do
66
- context "via `use`" do
67
- let(:app) {
68
- Sinatra.new do
69
- use Rack::JQuery
70
- use Rack::JQueryUI, :raise => true
71
- get "/cloudflare-cdn" do
72
- Rack::JQueryUI.cdn( :cloudflare )
201
+ context "Cloudflare CDN" do
202
+ before do
203
+ get "/cloudflare-cdn"
204
+ end
205
+ it_should_behave_like "Any route"
206
+ subject { last_response.body }
207
+ context "With :raise set to false" do
208
+ let(:expected) { Rack::JQueryUI::CDNs::CLOUDFLARE }
209
+ it { should include expected }
210
+ end
211
+ context "With :raise set to true" do
212
+ context "via `use`" do
213
+ let(:app) {
214
+ Sinatra.new do
215
+ use Rack::JQuery
216
+ use Rack::JQueryUI, :raise => true
217
+ get "/cloudflare-cdn" do
218
+ Rack::JQueryUI.cdn( env, :organisation => :cloudflare )
219
+ end
73
220
  end
74
- end
75
- }
76
- # it "should raise error as it's not supported for this version" do
77
- # expect { subject }.to raise_error
78
- # end
79
- it { should include "//cdnjs.cloudflare.com/ajax/libs/jqueryui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/jquery-ui.min.js" }
80
- end
81
- context "via the method options" do
82
- let(:app) {
83
- Sinatra.new do
84
- use Rack::JQuery
85
- use Rack::JQueryUI, :raise => false
86
- get "/cloudflare-cdn" do
87
- Rack::JQueryUI.cdn( :cloudflare, :raise => true )
221
+ }
222
+ # it "should raise error as it's not supported for this version" do
223
+ # expect { subject }.to raise_error
224
+ # end
225
+ it { should include "//cdnjs.cloudflare.com/ajax/libs/jqueryui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/jquery-ui.min.js" }
226
+ end
227
+ context "via the method options" do
228
+ let(:app) {
229
+ Sinatra.new do
230
+ use Rack::JQuery
231
+ use Rack::JQueryUI, :raise => false
232
+ get "/cloudflare-cdn" do
233
+ Rack::JQueryUI.cdn( env, :organisation => :cloudflare, :raise => true )
234
+ end
88
235
  end
89
- end
90
- }
91
- # subject { get "/cloudflare-cdn" }
92
- # it "should raise error as it's not supported for this version" do
93
- # expect { subject }.to raise_error
94
- # end
95
- it { should include "//cdnjs.cloudflare.com/ajax/libs/jqueryui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/jquery-ui.min.js" }
236
+ }
237
+ # subject { get "/cloudflare-cdn" }
238
+ # it "should raise error as it's not supported for this version" do
239
+ # expect { subject }.to raise_error
240
+ # end
241
+ it { should include "//cdnjs.cloudflare.com/ajax/libs/jqueryui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/jquery-ui.min.js" }
242
+ end
96
243
  end
97
244
  end
98
- end
99
- context "Media_temple CDN" do
100
- before do
101
- get "/media-temple-cdn"
245
+ context "Media_temple CDN" do
246
+ before do
247
+ get "/media_temple-cdn"
248
+ end
249
+ it_should_behave_like "Any route"
250
+ subject { last_response.body }
251
+ let(:expected) { Rack::JQueryUI::CDNs::MEDIA_TEMPLE }
252
+ it { should include expected }
102
253
  end
103
- it_should_behave_like "Any route"
104
- subject { last_response.body }
105
- let(:expected) { Rack::JQueryUI::CDNs::MEDIA_TEMPLE }
106
- it { should include expected }
107
- end
108
- context "Unspecified CDN" do
109
- before do
110
- get "/unspecified-cdn"
254
+ context "Unspecified CDN" do
255
+ before do
256
+ get "/unspecified-cdn"
257
+ end
258
+ it_should_behave_like "Any route"
259
+ subject { last_response.body }
260
+ let(:expected) { Rack::JQueryUI::CDNs::CLOUDFLARE }
261
+ it { should include expected }
262
+ end
263
+ context "No CDN, force the fallback" do
264
+ before do
265
+ get "/fallback-only"
266
+ end
267
+ it_should_behave_like "Any route"
268
+ subject { last_response.body }
269
+ let(:expected) { "<script src='/js/jquery-ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/#{Rack::JQueryUI::JQUERY_UI_FILE_NAME}'></script>" }
270
+ it { should include expected }
111
271
  end
112
- it_should_behave_like "Any route"
113
- subject { last_response.body }
114
- let(:expected) { Rack::JQueryUI::CDNs::MEDIA_TEMPLE }
115
- it { should include expected }
116
272
  end
117
273
  end
118
274
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-jquery_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 3.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-19 00:00:00.000000000 Z
12
+ date: 2013-11-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -91,6 +91,7 @@ files:
91
91
  - LICENCE.txt
92
92
  - README.md
93
93
  - Rakefile
94
+ - config.ru
94
95
  - examples/config.rb
95
96
  - examples/config.ru
96
97
  - lib/rack/jquery_ui.rb