rack-jquery_ui 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -3,7 +3,6 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  - 2.0.0
6
- - ruby-head
7
6
 
8
7
  # whitelist
9
8
  branches:
data/CHANGES.md CHANGED
@@ -1,8 +1,17 @@
1
1
  # CH CH CHANGES #
2
2
 
3
- ## v1.1.0 ##
3
+ ## Thursday the 4th of July 2013, v2.0.0 ##
4
4
 
5
- Thursday the 23rd of May 2013
5
+ OK, I made a bit of mistake with the last release. Not all the CDN's support 1.10.3, but I didn't check that properly. I've rolled this release back to 1.10.1 and I'll push out a release for 1.10.3, but going forward this has prompted some changes:
6
+
7
+ * There is now a :raise option (that can be used in several places, see the API docs). If a CDN isn't supported and :raise is set to false then the default will be used. If :raise is set to true then an exception is raised.
8
+ * There is a command in the Rakefile that can be run to check each CDN to see if it responds ok.
9
+ * Updated docs.
10
+
11
+ ----
12
+
13
+
14
+ ## Thursday the 23rd of May 2013, v1.1.0 ##
6
15
 
7
16
  * Updated to jQuery-UI version 1.10.3.
8
17
  * Added note about version numbers.
@@ -13,18 +22,14 @@ Thursday the 23rd of May 2013
13
22
  ----
14
23
 
15
24
 
16
- ## v1.0.2 ##
17
-
18
- Thursday the 23rd of May 2013
25
+ ## Thursday the 23rd of May 2013, v1.0.2 ##
19
26
 
20
27
  * Was missing a little bit of instruction.
21
28
 
22
29
  ----
23
30
 
24
31
 
25
- ## v1.0.1 ##
26
-
27
- Wednesday the 24th of April 2013
32
+ ## Wednesday the 24th of April 2013, v1.0.1 ##
28
33
 
29
34
  * Fixed clobbering of `call` method.
30
35
 
@@ -40,32 +45,30 @@ Friday the 22nd of March 2013
40
45
 
41
46
  ____
42
47
 
43
- ## v0.0.5 ##
44
48
 
45
- Friday the 7th of March 2013
49
+ ## Friday the 7th of March 2013, v0.0.5 ##
46
50
 
47
51
  * Added some code that checks whether the constants holding the version numbers have already been defined, and warns. It give a stronger warning if the version numbers differ. It won't _always_ cause a problem that they differ, but if I CDN goes down it's likely, so caveat emptor is the phrase of the day.
48
52
 
49
53
  ----
50
54
 
51
- ## v0.0.4 ##
52
55
 
53
- Thursday the 6th of March 2013
56
+ ## Thursday the 6th of March 2013, v0.0.4 ##
54
57
 
55
58
  * Using the rack-jquery-helpers library now, to help cut down on duplicated code.
56
59
  * Cleaned up the examples a bit.
57
60
 
58
- ## v0.0.3 ##
61
+ ----
62
+
59
63
 
60
- Wednesday the 5th of March 2013
64
+ ## Wednesday the 5th of March 2013, v0.0.3 ##
61
65
 
62
66
  * Updated gemspec so it automatically shows the current version of jQuery-UI that it supports.
63
67
 
64
68
  ____
65
69
 
66
- ## v0.0.2 ##
67
70
 
68
- Wednesday the 5th of March 2013
71
+ ## Wednesday the 5th of March 2013, v0.0.2 ##
69
72
 
70
73
  * Simplified, as moving themes to a separate library.
71
74
 
data/README.md CHANGED
@@ -20,10 +20,9 @@ Have a look in the examples directory, but here's a snippet.
20
20
  * Add `use Rack::JQueryUI` to your middleware stack.
21
21
  * Put this in the head of your layout (the example is Haml but you can use whatever you like)
22
22
 
23
- <pre><code>
24
- %head
25
- = Rack::JQueryUI.cdn
26
- </code></pre>
23
+
24
+ %head
25
+ = Rack::JQueryUI.cdn
27
26
 
28
27
  Now you have the script tags to Google's CDN in the head (you can also use Media Temple or Microsoft, or Cloudflare, see the docs).
29
28
 
@@ -35,6 +34,29 @@ That was easy.
35
34
 
36
35
  You have to have loaded jQuery _before_ using the CDN helper, as jQuery-UI relies on it. I've already mentioned [Rack::JQuery](https://github.com/yb66/rack-jquery) which you can use to do this, or load the script however you like. Just remember that it needs to be there.
37
36
 
37
+ ### When the CDN doesn't support the jQuery UI version of the library ###
38
+
39
+ I made a mistake and pushed out a version of the library where not all the CDNs supported the version of jQuery UI it was using. Embarrassing.
40
+
41
+ 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
+
43
+ %head
44
+ = Rack::JQueryUI.cdn :microsoft
45
+
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).
47
+
48
+ If you'd prefer an exception to be raised you can either do this:
49
+
50
+ use Rack::JQueryUI, :raise => true
51
+
52
+ or
53
+
54
+ %head
55
+ = Rack::JQueryUI.cdn :microsoft, :raise => true
56
+
57
+ the second way will always override the first.
58
+
59
+
38
60
  ### Version numbers ###
39
61
 
40
62
  This library uses [semver](http://semver.org/) to version the **library**. That means the library version is ***not*** an indicator of quality but a way to manage changes. The version of jQuery UI can be found in the lib/rack/jquery_ui/version.rb file, or via the {Rack::JQueryUI::JQUERY_UI_VERSION} constant.
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ namespace :docs do
12
12
  require 'yard'
13
13
 
14
14
  YARD::Rake::YardocTask.new :yard do |t|
15
- t.files = ['lib/**/*.rb', 'app/*.rb', 'spec/**/*.rb']
15
+ t.files = ['lib/**/*.rb', 'app/*.rb']
16
16
  t.options = ['-odocs/'] # optional
17
17
  end
18
18
 
@@ -46,3 +46,27 @@ namespace :examples do
46
46
  end
47
47
 
48
48
  end
49
+
50
+ namespace :cdn do
51
+ require 'open3'
52
+ desc "An availability check, for sanity"
53
+ task :check do
54
+ require_relative './lib/rack/jquery_ui.rb'
55
+ Rack::JQueryUI::CDNs.constants.each do |const|
56
+ url = "#{Rack::JQueryUI::CDNs.const_get(const)}"
57
+ url = "http:#{url}" unless url.start_with? "http"
58
+ cmd = "curl -I #{url}"
59
+ puts cmd
60
+ puts catch(:status) {
61
+ Open3.popen3(cmd) do |_,stdout,_|
62
+ line = stdout.gets
63
+ throw :status, "Nothing for #{const}" if line.nil?
64
+ puts line.match("HTTP/1.1 404 Not Found") ?
65
+ "FAILED: #{const}" :
66
+ "PASSED: #{const}"
67
+ end
68
+ }
69
+ end
70
+ end
71
+
72
+ end
data/examples/config.rb CHANGED
@@ -45,7 +45,7 @@ __END__
45
45
  %head
46
46
  = Rack::JQuery.cdn( :google )
47
47
  = Rack::JQueryUI.cdn( :google )
48
- %link{ href: "http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css", rel: "stylesheet"}
48
+ %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/base/jquery-ui.css", rel: "stylesheet"}
49
49
  :css
50
50
  body {
51
51
  font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
@@ -58,7 +58,7 @@ __END__
58
58
  %head
59
59
  = Rack::JQuery.cdn( :microsoft )
60
60
  = Rack::JQueryUI.cdn( :microsoft )
61
- %link{ href: "http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css", rel: "stylesheet"}
61
+ %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/base/jquery-ui.css", rel: "stylesheet"}
62
62
  :css
63
63
  body {
64
64
  font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
@@ -71,7 +71,7 @@ __END__
71
71
  %head
72
72
  = Rack::JQuery.cdn( :cloudflare )
73
73
  = Rack::JQueryUI.cdn( :cloudflare )
74
- %link{ href: "http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css", rel: "stylesheet"}
74
+ %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/base/jquery-ui.css", rel: "stylesheet"}
75
75
  :css
76
76
  body {
77
77
  font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
@@ -84,7 +84,7 @@ __END__
84
84
  %head
85
85
  = Rack::JQuery.cdn( :media_temple )
86
86
  = Rack::JQueryUI.cdn( :media_temple )
87
- %link{ href: "http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css", rel: "stylesheet"}
87
+ %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/base/jquery-ui.css", rel: "stylesheet"}
88
88
  :css
89
89
  body {
90
90
  font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
@@ -97,7 +97,7 @@ __END__
97
97
  %head
98
98
  = Rack::JQuery.cdn()
99
99
  = Rack::JQueryUI.cdn()
100
- %link{ href: "http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css", rel: "stylesheet"}
100
+ %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/base/jquery-ui.css", rel: "stylesheet"}
101
101
  :css
102
102
  body {
103
103
  font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
@@ -111,7 +111,7 @@ __END__
111
111
  %head
112
112
  = Rack::JQuery.cdn()
113
113
  = Rack::JQueryUI.cdn()
114
- %link{ href: "http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css", rel: "stylesheet"}
114
+ %link{ href: "http://code.jquery.com/ui/#{Rack::JQueryUI::JQUERY_UI_VERSION}/themes/base/jquery-ui.css", rel: "stylesheet"}
115
115
  :css
116
116
  body {
117
117
  font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
@@ -11,19 +11,24 @@ module Rack
11
11
  # The usual file name.
12
12
  JQUERY_UI_FILE_NAME = "jquery-ui.min.js"
13
13
 
14
- # Script tags for the Media Temple CDN
15
- MEDIA_TEMPLE = "<script src='http://code.jquery.com/ui/#{JQUERY_UI_VERSION}/jquery-ui.js'></script>"
16
-
17
- # Script tags for the Google CDN
18
- GOOGLE = "<script src='//ajax.googleapis.com/ajax/libs/jqueryui/#{JQUERY_UI_VERSION}/jquery-ui.min.js'></script>"
19
-
20
- # Script tags for the Microsoft CDN
21
- MICROSOFT = "<script src='//ajax.aspnetcdn.com/ajax/jquery.ui/#{JQUERY_UI_VERSION}/jquery-ui.min.js'></script>"
22
-
23
-
24
- # Script tags for the Cloudflare CDN
25
- CLOUDFLARE = "<script src='//cdnjs.cloudflare.com/ajax/libs/jqueryui/#{JQUERY_UI_VERSION}/jquery-ui.min.js'></script>"
26
14
 
15
+ # Namespaced for convenience, to help with checking
16
+ # which CDN supports what.
17
+ module CDNs
18
+
19
+ # Script tags for the Media Temple CDN
20
+ MEDIA_TEMPLE = "http://code.jquery.com/ui/#{JQUERY_UI_VERSION}/jquery-ui.js"
21
+
22
+ # Script tags for the Google CDN
23
+ GOOGLE = "//ajax.googleapis.com/ajax/libs/jqueryui/#{JQUERY_UI_VERSION}/jquery-ui.min.js"
24
+
25
+ # Script tags for the Microsoft CDN
26
+ MICROSOFT = "//ajax.aspnetcdn.com/ajax/jquery.ui/#{JQUERY_UI_VERSION}/jquery-ui.min.js"
27
+
28
+
29
+ # Script tags for the Cloudflare CDN
30
+ CLOUDFLARE = "//cdnjs.cloudflare.com/ajax/libs/jqueryui/#{JQUERY_UI_VERSION}/jquery-ui.min.js"
31
+ end
27
32
 
28
33
  # 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.
29
34
  FALLBACK = <<STR
@@ -35,27 +40,51 @@ STR
35
40
 
36
41
  # @param [Symbol] organisation Choose which CDN to use, either :google, :microsoft or :media_temple
37
42
  # @return [String] The HTML script tags to get the CDN.
38
- def self.cdn( organisation=:google )
39
- script = case organisation
40
- when :media_temple then MEDIA_TEMPLE
41
- when :microsoft then MICROSOFT
42
- when :cloudflare then CLOUDFLARE
43
- else GOOGLE
43
+ def self.cdn( organisation=:google, options={} )
44
+ 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) && raise
52
+ fail "The Cloudflare CDN does not support version jQuery UI version #{JQUERY_UI_VERSION}."
53
+ else
54
+ CDNs::GOOGLE
44
55
  end
45
- "#{script}\n#{FALLBACK}"
56
+ "<script src='#{script}'></script>\n#{FALLBACK}"
46
57
  end
47
58
 
48
59
 
49
60
  # Default options hash for the middleware.
50
61
  DEFAULT_OPTIONS = {
51
- :http_path => "/js/jquery-ui/#{JQUERY_UI_VERSION}"
62
+ :http_path => "/js/jquery-ui/#{JQUERY_UI_VERSION}",
63
+ :raise => false
52
64
  }
53
65
 
54
66
 
67
+ # Whether to raise an exception if the chosen CDN
68
+ # does not support the jQuery UI version this library is using
69
+ # @param [TrueClass] bool
70
+ def self.raise=( bool )
71
+ @raise = bool
72
+ end
73
+
74
+
75
+ # @see raise=
76
+ # @return [TrueClass]
77
+ def self.raise?
78
+ @raise = false if @raise.nil?
79
+ @raise
80
+ end
81
+
82
+
55
83
  # @param [#call] app
56
84
  # @param [Hash] options
57
85
  # @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}".
58
86
  # @note ***Don't leave out the version number!***. The scripts provided by jQuery don't contain the version in the filename like the jQuery scripts do, which means that organising them and sending the right headers back is bound to go wrong unless you put the version number somewhere in the route. You have been warned!
87
+ # @option options [TrueClass] :raise If one of the CDNs does not support then raise an error if it is chosen. Defaults to false.
59
88
  # @example
60
89
  # # The default:
61
90
  # use Rack::JQueryUI
@@ -64,6 +93,7 @@ STR
64
93
  def initialize( app, options={} )
65
94
  @app, @options = app, DEFAULT_OPTIONS.merge(options)
66
95
  @http_path_to_jquery = ::File.join @options[:http_path], JQUERY_UI_FILE_NAME
96
+ self.class.raise = @options[:raise]
67
97
  end
68
98
 
69
99
 
@@ -1,10 +1,10 @@
1
1
  module Rack
2
2
  class JQueryUI
3
3
  # library version
4
- VERSION = "1.1.0"
4
+ VERSION = "2.0.0"
5
5
 
6
6
  # This is here in case another rack-jquery_ui library has already been loaded.
7
- jquery_ui_version = "1.10.3"
7
+ jquery_ui_version = "1.10.1"
8
8
  if defined? JQUERY_UI_VERSION
9
9
  warn "JQUERY_UI_VERSION was already defined."
10
10
  unless JQUERY_UI_VERSION == jquery_ui_version
@@ -15,8 +15,8 @@ module Rack
15
15
  JQUERY_UI_VERSION = jquery_ui_version
16
16
 
17
17
  # This is the release date of the jQuery file, it makes an easy "Last-Modified" date for setting the headers around caching.
18
- # @todo remember to change Last-Modified with each release!
19
- JQUERY_UI_VERSION_DATE = "Fri, 03 May 2013 00:00:00 GMT"
18
+ # TODO remember to change Last-Modified with each release!
19
+ JQUERY_UI_VERSION_DATE = "Fri, 15 Feb 2013 00:00:00 GMT"
20
20
  end
21
21
  end
22
22
  end
@@ -8,23 +8,28 @@ describe "The class methods" do
8
8
  context "Given an argument" do
9
9
  context "of nil (the default)" do
10
10
  let(:organisation) { nil }
11
- it { should == "#{Rack::JQueryUI::GOOGLE}\n#{Rack::JQueryUI::FALLBACK}" }
11
+ it { should == "<script src='#{Rack::JQueryUI::CDNs::GOOGLE}'></script>\n#{Rack::JQueryUI::FALLBACK}" }
12
12
  end
13
13
  context "of :google" do
14
14
  let(:organisation) { :google }
15
- it { should == "#{Rack::JQueryUI::GOOGLE}\n#{Rack::JQueryUI::FALLBACK}" }
15
+ it { should == "<script src='#{Rack::JQueryUI::CDNs::GOOGLE}'></script>\n#{Rack::JQueryUI::FALLBACK}" }
16
16
  end
17
17
  context "of :microsoft" do
18
18
  let(:organisation) { :microsoft }
19
- it { should == "#{Rack::JQueryUI::MICROSOFT}\n#{Rack::JQueryUI::FALLBACK}" }
19
+ it { should == "<script src='#{Rack::JQueryUI::CDNs::MICROSOFT}'></script>\n#{Rack::JQueryUI::FALLBACK}" }
20
20
  end
21
21
  context "of :media_temple" do
22
22
  let(:organisation) { :media_temple }
23
- it { should == "#{Rack::JQueryUI::MEDIA_TEMPLE}\n#{Rack::JQueryUI::FALLBACK}" }
23
+ it { should == "<script src='#{Rack::JQueryUI::CDNs::MEDIA_TEMPLE}'></script>\n#{Rack::JQueryUI::FALLBACK}" }
24
24
  end
25
25
  context "of :cloudflare" do
26
26
  let(:organisation) { :cloudflare }
27
- it { should == "#{Rack::JQueryUI::CLOUDFLARE}\n#{Rack::JQueryUI::FALLBACK}" }
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
28
33
  end
29
34
  end
30
35
  end
@@ -43,17 +48,51 @@ describe "Inserting the CDN" do
43
48
  end
44
49
  it_should_behave_like "Any route"
45
50
  subject { last_response.body }
46
- let(:expected) { Rack::JQueryUI::GOOGLE }
51
+ let(:expected) { Rack::JQueryUI::CDNs::GOOGLE }
47
52
  it { should include expected }
48
53
  end
49
54
  context "Cloudflare CDN" do
50
- before do
51
- get "/cloudflare-cdn"
55
+ context "With :raise set to false" do
56
+ before do
57
+ get "/cloudflare-cdn"
58
+ end
59
+ it_should_behave_like "Any route"
60
+ subject { last_response.body }
61
+ let(:expected) { Rack::JQueryUI::CDNs::GOOGLE }
62
+ it { should include expected }
63
+ end
64
+ context "With :raise set to true" do
65
+ context "via `use`" do
66
+ let(:app) {
67
+ Sinatra.new do
68
+ use Rack::JQuery
69
+ use Rack::JQueryUI, :raise => true
70
+ get "/cloudflare-cdn" do
71
+ Rack::JQueryUI.cdn( :cloudflare )
72
+ end
73
+ end
74
+ }
75
+ subject { get "/cloudflare-cdn" }
76
+ it "should raise error as it's not supported for this version" do
77
+ expect { subject }.to raise_error
78
+ end
79
+ end
80
+ context "via the method options" do
81
+ let(:app) {
82
+ Sinatra.new do
83
+ use Rack::JQuery
84
+ use Rack::JQueryUI, :raise => false
85
+ get "/cloudflare-cdn" do
86
+ Rack::JQueryUI.cdn( :cloudflare, :raise => true )
87
+ end
88
+ end
89
+ }
90
+ subject { get "/cloudflare-cdn" }
91
+ it "should raise error as it's not supported for this version" do
92
+ expect { subject }.to raise_error
93
+ end
94
+ end
52
95
  end
53
- it_should_behave_like "Any route"
54
- subject { last_response.body }
55
- let(:expected) { Rack::JQueryUI::CLOUDFLARE }
56
- it { should include expected }
57
96
  end
58
97
  context "Media_temple CDN" do
59
98
  before do
@@ -61,7 +100,7 @@ describe "Inserting the CDN" do
61
100
  end
62
101
  it_should_behave_like "Any route"
63
102
  subject { last_response.body }
64
- let(:expected) { Rack::JQueryUI::MEDIA_TEMPLE }
103
+ let(:expected) { Rack::JQueryUI::CDNs::MEDIA_TEMPLE }
65
104
  it { should include expected }
66
105
  end
67
106
  context "Unspecified CDN" do
@@ -70,7 +109,7 @@ describe "Inserting the CDN" do
70
109
  end
71
110
  it_should_behave_like "Any route"
72
111
  subject { last_response.body }
73
- let(:expected) { Rack::JQueryUI::GOOGLE }
112
+ let(:expected) { Rack::JQueryUI::CDNs::GOOGLE }
74
113
  it { should include expected }
75
114
  end
76
115
  end