rack-jquery_ui-themes 2.1.1 → 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,15 @@
1
1
  # CH CH CH CHANGES #
2
2
 
3
+ ## Tuesday the 6th of August 2013, v3.0.0 ##
4
+
5
+ * Removed class methods for theme and themes, they just don't work with the Rack architecture, at least not the way I'm using them.
6
+ * Found a way to check if the external CDN has loaded, by adding a meta tag and then one of the jQuery UI classes to it, and seeing if it changes.
7
+ * Added some extra keys the internal paths hash to help ascertain which theme is being called.
8
+ * Added a fallback option to the cdn method, mainly to help with testing but also because it might be wanted.
9
+
10
+ ----
11
+
12
+
3
13
  ## Friday the 19th of July 2013, v2.1.1 ##
4
14
 
5
15
  * Removed rogue console logging statement in the fallback javascript.
data/Gemfile CHANGED
@@ -14,7 +14,8 @@ group :examples do
14
14
  gem "sinatra"
15
15
  gem "haml"
16
16
  gem "rack-jquery"
17
- gem "rack-jquery_ui", "2.0.0" # for jQuery UI 1.10.1
17
+ gem "rack-jquery_ui", "2.2.0" # for jQuery UI 1.10.3
18
+ gem "thin"
18
19
  end
19
20
 
20
21
  group :development do
data/README.md CHANGED
@@ -36,9 +36,9 @@ Have a look in the examples directory, but here's a snippet.
36
36
  = Rack::JQueryUI::Themes.cdn env, :organisation => :microsoft
37
37
  </code></pre>
38
38
 
39
- Now you have the script tags to Google's CDN in the head (you can also use Media Temple or Microsoft, see the docs).
39
+ Now you have the script tags to Microsoft's CDN in the head (you can also use Media Temple or Microsoft, see the docs).
40
40
 
41
- 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.1/themes/:THEME/jquery-ui.min.css" path (or, instead of 1.10.1, whatever is in {Rack::JQueryUI::JQUERY_UI_VERSION}), where `:THEME` is the name of the theme you specified, the default being `base`.
41
+ 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/themes/:THEME/jquery-ui.min.css" path (or, instead of 1.10.3, whatever is in {Rack::JQueryUI::JQUERY_UI_VERSION}), where `:THEME` is the name of the theme you specified, the default being `smoothness`.
42
42
 
43
43
  That was easy.
44
44
 
data/Rakefile CHANGED
@@ -38,6 +38,15 @@ namespace :spec do
38
38
 
39
39
  end
40
40
 
41
+ namespace :examples do
42
+
43
+ desc "Run the examples."
44
+ task :run do
45
+ exec "bundle exec rackup examples/config.ru"
46
+ end
47
+
48
+ end
49
+
41
50
  namespace :cdn do
42
51
  require 'open3'
43
52
  desc "An availability check, for sanity"
data/examples/config.rb CHANGED
@@ -9,7 +9,7 @@ class App < Sinatra::Base
9
9
  enable :inline_templates
10
10
  use Rack::JQuery
11
11
  use Rack::JQueryUI
12
- use Rack::JQueryUI::Themes, :theme => "vader"
12
+ use Rack::JQueryUI::Themes, :theme => "vader", :themes => Rack::JQueryUI::Themes::STANDARD_THEMES
13
13
 
14
14
  get "/" do
15
15
  haml :index, :layout => :unspecified
@@ -30,10 +30,28 @@ class App < Sinatra::Base
30
30
  get "/themes/?" do
31
31
  haml :themes_list, :layout => :unspecified
32
32
  end
33
- end
34
33
 
35
- class ThemeApp < Sinatra::Base
36
- get "/" do
34
+ get "/fallback/?" do
35
+ haml :themes_list, :layout => :unspecified
36
+ end
37
+
38
+
39
+ get "/themes/" do
40
+ haml :theme, :layout => :layout_theme
41
+ end
42
+
43
+ get "/themes/:theme" do |theme|
44
+ @theme = theme
37
45
  haml :theme, :layout => :layout_theme
38
46
  end
47
+
48
+
49
+ get "/fallback/" do
50
+ haml :theme, :layout => :layout_fallback
51
+ end
52
+
53
+ get "/fallback/:theme" do |theme|
54
+ @theme = theme
55
+ haml :theme, :layout => :layout_fallback
56
+ end
39
57
  end
data/examples/config.ru CHANGED
@@ -8,12 +8,4 @@ require File.expand_path( '../config.rb', __FILE__)
8
8
 
9
9
  map "/" do
10
10
  run App
11
- end
12
-
13
- # this is me cheating a bit
14
- Rack::JQueryUI::Themes::STANDARD_THEMES.each do |theme|
15
- map "/themes/#{theme}" do
16
- use Rack::JQueryUI::Themes, :theme => theme
17
- run ThemeApp
18
- end
19
11
  end
@@ -0,0 +1,15 @@
1
+ !!!
2
+ %html{:lang => "us"}
3
+ %head
4
+ %meta{:charset => "utf-8"}
5
+ %title jQuery UI Example Page
6
+ // load jQuery
7
+ = Rack::JQuery.cdn()
8
+ // load UI
9
+ = Rack::JQueryUI.cdn()
10
+ // load themes
11
+ = Rack::JQueryUI::Themes.cdn(env, :theme => @theme, :fallback => :only)
12
+ // load js for widgets
13
+ = haml :js_and_css_header
14
+ %body
15
+ = yield
@@ -8,7 +8,7 @@
8
8
  // load UI
9
9
  = Rack::JQueryUI.cdn()
10
10
  // load themes
11
- = Rack::JQueryUI::Themes.cdn(env)
11
+ = Rack::JQueryUI::Themes.cdn(env, :theme => @theme)
12
12
  // load js for widgets
13
13
  = haml :js_and_css_header
14
14
  %body
@@ -33,67 +33,28 @@ module Rack
33
33
 
34
34
  # This javascript checks if the jQuery-UI object has loaded by issuing a head request to the CDN. If it doesn't get a successful status, that most likely means the CDN is unreachable, so it uses the local jQuery-UI theme.
35
35
  FALLBACK = <<STR
36
+ <meta id='rack-jquery-ui-themes-fallback-beacon' />
37
+
36
38
  <script type="text/javascript">
37
- $.ajax({
38
- type: "HEAD",
39
- url: ':CDNURL',
40
- success: function(css,status) {
41
- // do nothing
42
- },
43
- error: function(xhr,status,error) {
44
- var link = document.createElement("link");
45
- link.rel = "stylesheet";
46
- link.href = ':FALLBACK_URL';
47
- document.getElementsByTagName("head")[0].appendChild(link);
48
- }
49
- });
39
+ var meta = $("#rack-jquery-ui-themes-fallback-beacon");
40
+ meta.addClass("ui-icon");
41
+ if ( meta.css('width') != "16px" ) {
42
+ $('<link rel="stylesheet" type="text/css" href="/js/jquery-ui/#{JQueryUI::JQUERY_UI_VERSION}/themes/:THEME/#{JQUERY_UI_THEME_FILE}" />').appendTo('head');
43
+ }
44
+ meta.remove();
50
45
  </script>
51
46
  STR
52
47
 
53
48
 
54
49
  # List of the standard themes provided by jQuery UI.
55
50
  STANDARD_THEMES = %w{black-tie blitzer cupertino dark-hive dot-luv eggplant excite-bike flick hot-sneaks humanity le-frog mint-choc overcast pepper-grinder redmond smoothness south-street start sunny swanky-purse trontastic ui-darkness ui-lightness vader}
56
-
57
-
58
- # The chosen theme name.
59
- # @return [String]
60
- # @see http://blog.jqueryui.com/2013/03/jquery-ui-1-10-2/ for why the default theme was changed to 'smoothness'.
61
- def self.theme
62
- @theme ||= "smoothness"
63
- end
64
-
65
-
66
- # Set the theme.
67
- # @param [String] name Name of the theme.
68
- # @return [String]
69
- def self.theme=( name )
70
- name = name.to_s
71
- fail ArgumentError, "That theme (#{name}) is unknown for this version of the rack-jquery_ui-themes library." unless STANDARD_THEMES.include? name
72
- @theme = name
73
- end
74
-
75
-
76
- # Set the themes to use.
77
- # @param [Array<String>] themes
78
- # @return [Array<String>]
79
- # @example
80
- # self.class.themes = ["smoothness", "swanky-purse"]
81
- def self.themes=( themes )
82
- themes = themes.pop if themes.first.respond_to? :each
83
- @themes = themes.map! &:to_s
84
- end
85
-
86
- # Get the selected themes
87
- # @return [Array<String>]
88
- def self.themes
89
- @themes ||= Array(self.theme)
90
- end
91
51
 
92
52
 
93
53
  # @param [Hash] env The rack env hash.
94
54
  # @param [Hash] opts
95
- # @option opts [#to_sym] organisation Choose which CDN to use, either :media_temple, :microsoft, or :media_temple.
55
+ # @option opts [#to_sym] :organisation Choose which CDN to use, either :media_temple, :microsoft, or :media_temple.
96
56
  # @option opts [#to_s] :theme Theme to use. Won't set any routes or permanent settings, see note.
57
+ # @option opts [TrueClass, Symbol] :fallback `true` if you want a fallback script, `false` if you don't, and `:only` if you don't want the CDN link but you do want just the fallback script. `true` is the default.
97
58
  # @return [String] The HTML script tags to get the CDN, with a JQuery function that will be called if the CDN fails and sets the fallback path.
98
59
  # @example
99
60
  # # The easiest, use the defaults:
@@ -113,8 +74,9 @@ STR
113
74
  # theme is favoured *from the already given set*.
114
75
  def self.cdn( env, opts={} )
115
76
  organisation = opts[:organisation] || :media_temple
116
- themes = env.fetch "rack.jquery_ui-themes", themes()
77
+ themes = env["rack.jquery_ui-themes"]
117
78
  theme, themes = sort_out_options opts.merge :themes => themes
79
+ fallback = opts[:fallback] || true
118
80
 
119
81
  # Get the CDN URL for the given organisation.
120
82
  url = case organisation.to_sym
@@ -131,11 +93,18 @@ STR
131
93
  fallback_script = FALLBACK.gsub(/\:CDNURL/, url)
132
94
  .sub /\:FALLBACK_URL/, fallback_url
133
95
 
134
- script = "<link rel='stylesheet' href='#{url}' type='text/css' />"
135
- [script,fallback_script].map{|x|
136
- x.gsub(/\:THEME/, theme)
137
- }.join("\n")
138
- #fallback_script.gsub(/\:THEME/, theme)
96
+ if fallback == :only
97
+ fallback_script.gsub(/\:THEME/, theme)
98
+ else
99
+ script = "<link rel='stylesheet' href='#{url}' type='text/css' />"
100
+ if fallback == false
101
+ script.gsub(/\:THEME/, theme)
102
+ else
103
+ [script,fallback_script].map{|x|
104
+ x.gsub(/\:THEME/, theme)
105
+ }.join("\n")
106
+ end
107
+ end
139
108
  end
140
109
 
141
110
 
@@ -163,7 +132,7 @@ STR
163
132
  (t + themes).uniq :
164
133
  t
165
134
  else
166
- themes = self.themes if themes.nil? || themes.empty?
135
+ themes = ["smoothness"] if themes.nil? || themes.empty?
167
136
  theme = themes.first
168
137
  end
169
138
 
@@ -212,7 +181,10 @@ STR
212
181
  # with the file path to the CSS file as the value
213
182
  paths.store(
214
183
  ::File.join( theme_url, JQUERY_UI_THEME_FILE ),
215
- ::File.join( theme_dir, JQUERY_UI_THEME_FILE)
184
+ {
185
+ :file => ::File.join( theme_dir, JQUERY_UI_THEME_FILE),
186
+ :theme => theme
187
+ }
216
188
  )
217
189
 
218
190
  images_dir = ::File.join theme_dir, "images"
@@ -227,7 +199,10 @@ STR
227
199
  }.each do |img|
228
200
  paths.store(
229
201
  ::File.join( theme_url, "images", img ), # url
230
- ::File.join( images_dir, img ) # file
202
+ {
203
+ :file => ::File.join( images_dir, img ),
204
+ :theme => theme
205
+ }
231
206
  )
232
207
  end
233
208
  end
@@ -253,12 +228,12 @@ STR
253
228
  response = Rack::Response.new
254
229
  if request.path_info.end_with? JQUERY_UI_THEME_FILE # CSS.
255
230
  # For caching:
256
- response.headers.merge! caching_headers("#{JQUERY_UI_THEME_FILE}-#{self.class.theme}-#{JQueryUI::JQUERY_UI_VERSION}", JQueryUI::JQUERY_UI_VERSION_DATE)
231
+ response.headers.merge! caching_headers("#{JQUERY_UI_THEME_FILE}-#{@paths[request.path_info][:theme]}-#{JQueryUI::JQUERY_UI_VERSION}", JQueryUI::JQUERY_UI_VERSION_DATE)
257
232
  # There's no need to test if the IF_MODIFIED_SINCE against the release date because the header will only be passed if the file was previously accessed by the requester, and the file is never updated. If it is updated then it is accessed by a different path.
258
- requested_file = open @paths[request.path_info], "r"
233
+ requested_file = open @paths[request.path_info][:file], "r"
259
234
  elsif request.path_info =~ /images/
260
235
  # serve images
261
- requested_file = open @paths[request.path_info], "rb"
236
+ requested_file = open @paths[request.path_info][:file], "rb"
262
237
  else # bad route
263
238
  response.status = 404
264
239
  return response.finish # finish early, 404
@@ -19,7 +19,7 @@ module Rack
19
19
 
20
20
  class Themes
21
21
  # version of this library
22
- VERSION = "2.1.1"
22
+ VERSION = "3.0.0"
23
23
  end
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-jquery_ui-themes
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
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-08-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -96,6 +96,7 @@ files:
96
96
  - examples/views/google.haml
97
97
  - examples/views/index.haml
98
98
  - examples/views/js_and_css_header.haml
99
+ - examples/views/layout_fallback.haml
99
100
  - examples/views/layout_theme.haml
100
101
  - examples/views/mediatemple.haml
101
102
  - examples/views/microsoft.haml