rack-jquery_ui 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/.travis.yml +12 -0
- data/CHANGES.md +5 -0
- data/Gemfile +25 -0
- data/JQUERY-UI-LICENCE.txt +26 -0
- data/LICENCE.txt +22 -0
- data/README.md +61 -0
- data/Rakefile +39 -0
- data/examples/config.rb +78 -0
- data/examples/config.ru +6 -0
- data/lib/rack/jquery_ui.rb +97 -0
- data/lib/rack/jquery_ui/version.rb +10 -0
- data/rack-jquery_ui.gemspec +24 -0
- data/spec/rack_jquery_ui_spec.rb +99 -0
- data/spec/spec_helper.rb +26 -0
- data/spec/support/shared/all_pages.rb +14 -0
- data/vendor/assets/javascripts/jquery-ui/1.10.1/jquery-ui.min.js +5 -0
- metadata +115 -0
data/.gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
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
|
18
|
+
.rbx/
|
19
|
+
.rspec
|
20
|
+
vendor/assets/javascripts/jquery-*.min.js
|
data/.travis.yml
ADDED
data/CHANGES.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in rack-jquery.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem 'rspec'
|
8
|
+
gem 'simplecov'
|
9
|
+
gem 'rack-test'
|
10
|
+
gem "timecop"
|
11
|
+
end
|
12
|
+
|
13
|
+
group :examples do
|
14
|
+
gem "sinatra"
|
15
|
+
gem "haml"
|
16
|
+
gem "rack-jquery"
|
17
|
+
end
|
18
|
+
|
19
|
+
group :development do
|
20
|
+
gem "wirble"
|
21
|
+
gem "pry"
|
22
|
+
gem "pry-nav"
|
23
|
+
gem "yard"
|
24
|
+
gem "maruku"
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright 2013 jQuery Foundation and other contributors,
|
2
|
+
http://jqueryui.com/
|
3
|
+
|
4
|
+
This software consists of voluntary contributions made by many
|
5
|
+
individuals (AUTHORS.txt, http://jqueryui.com/about) For exact
|
6
|
+
contribution history, see the revision history and logs, available
|
7
|
+
at http://jquery-ui.googlecode.com/svn/
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
10
|
+
a copy of this software and associated documentation files (the
|
11
|
+
"Software"), to deal in the Software without restriction, including
|
12
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
13
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
14
|
+
permit persons to whom the Software is furnished to do so, subject to
|
15
|
+
the following conditions:
|
16
|
+
|
17
|
+
The above copyright notice and this permission notice shall be
|
18
|
+
included in all copies or substantial portions of the Software.
|
19
|
+
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
21
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
23
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
24
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
25
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
26
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LICENCE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Iain Barnett
|
2
|
+
|
3
|
+
MIT Licence
|
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,61 @@
|
|
1
|
+
# Rack::JQueryUI
|
2
|
+
|
3
|
+
[jQuery-UI](http://jqueryui.com/) CDN script tags and fallback in one neat package.
|
4
|
+
|
5
|
+
### Build status ###
|
6
|
+
|
7
|
+
Master branch:
|
8
|
+
[![Build Status](https://secure.travis-ci.org/yb66/rack-jquery_ui.png?branch=master)](http://travis-ci.org/yb66/rack-jquery_ui)
|
9
|
+
|
10
|
+
## Why? ##
|
11
|
+
|
12
|
+
I get tired of copy and pasting and downloading and moving… jQuery files and script tags etc. This does it for me (along with https://github.com/yb66/rack-jquery), and keeps version management nice 'n' easy.
|
13
|
+
|
14
|
+
## Usage ##
|
15
|
+
|
16
|
+
Have a look in the examples directory, but here's a snippet.
|
17
|
+
|
18
|
+
* Install it (see below)
|
19
|
+
* `require 'rack/jquery_ui'`.
|
20
|
+
* Put this in the head of your layout (the example is Haml but you can use whatever you like)
|
21
|
+
|
22
|
+
<pre><code>
|
23
|
+
%head
|
24
|
+
= Rack::JQueryUI.cdn
|
25
|
+
</code></pre>
|
26
|
+
|
27
|
+
Now you have the script tags to Google's CDN in the head (you can also use Media Temple or Microsoft, see the docs).
|
28
|
+
|
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.1/jquery-ui.min.js" path (or, instead of 1.10.1, whatever is in {Rack::JQuery::VERSION}). You can change the "/js" bit if you like (see the docs).
|
30
|
+
|
31
|
+
That was easy.
|
32
|
+
|
33
|
+
## Note ##
|
34
|
+
|
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.
|
36
|
+
|
37
|
+
## Version numbers ##
|
38
|
+
|
39
|
+
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.
|
40
|
+
|
41
|
+
## Installation
|
42
|
+
|
43
|
+
Add this line to your application's Gemfile:
|
44
|
+
|
45
|
+
gem 'rack-jquery_ui'
|
46
|
+
|
47
|
+
And then execute:
|
48
|
+
|
49
|
+
$ bundle
|
50
|
+
|
51
|
+
Or install it yourself as:
|
52
|
+
|
53
|
+
$ gem install rack-jquery_ui
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
1. Fork it
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
61
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
|
4
|
+
desc "(Re-) generate documentation and place it in the docs/ dir. Open the index.html file in there to read it."
|
5
|
+
task :docs => [:"docs:environment", :"docs:yard"]
|
6
|
+
namespace :docs do
|
7
|
+
|
8
|
+
task :environment do
|
9
|
+
ENV["RACK_ENV"] = "documentation"
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'yard'
|
13
|
+
|
14
|
+
YARD::Rake::YardocTask.new :yard do |t|
|
15
|
+
t.files = ['lib/**/*.rb', 'app/*.rb', 'spec/**/*.rb']
|
16
|
+
t.options = ['-odocs/'] # optional
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
task :default => "spec"
|
22
|
+
|
23
|
+
task :spec => :"spec:run"
|
24
|
+
task :rspec => :spec
|
25
|
+
namespace :spec do
|
26
|
+
task :environment do
|
27
|
+
ENV["RACK_ENV"] = "test"
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Run specs"
|
31
|
+
task :run, [:any_args] => :"spec:environment" do |t,args|
|
32
|
+
warn "Entering spec task."
|
33
|
+
any_args = args[:any_args] || ""
|
34
|
+
cmd = "bin/rspec #{any_args}"
|
35
|
+
warn cmd
|
36
|
+
system cmd
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/examples/config.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'haml'
|
3
|
+
require 'rack/jquery'
|
4
|
+
require 'rack/jquery_ui'
|
5
|
+
|
6
|
+
class App < Sinatra::Base
|
7
|
+
|
8
|
+
enable :inline_templates
|
9
|
+
use Rack::JQuery
|
10
|
+
use Rack::JQueryUI
|
11
|
+
|
12
|
+
get "/" do
|
13
|
+
"RUNNING"
|
14
|
+
end
|
15
|
+
|
16
|
+
get "/google-cdn" do
|
17
|
+
haml :index, :layout => :google
|
18
|
+
end
|
19
|
+
|
20
|
+
get "/media-temple-cdn" do
|
21
|
+
haml :index, :layout => :mediatemple
|
22
|
+
end
|
23
|
+
|
24
|
+
get "/microsoft-cdn" do
|
25
|
+
haml :index, :layout => :microsoft
|
26
|
+
end
|
27
|
+
|
28
|
+
get "/unspecified-cdn" do
|
29
|
+
haml :index, :layout => :unspecified
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
__END__
|
34
|
+
|
35
|
+
@@google
|
36
|
+
%html
|
37
|
+
%head
|
38
|
+
= Rack::JQuery.cdn( :google )
|
39
|
+
= Rack::JQueryUI.cdn( :organisation => :google )
|
40
|
+
= yield
|
41
|
+
|
42
|
+
@@microsoft
|
43
|
+
%html
|
44
|
+
%head
|
45
|
+
= Rack::JQuery.cdn( :microsoft )
|
46
|
+
= Rack::JQueryUI.cdn( :organisation => :microsoft )
|
47
|
+
= yield
|
48
|
+
|
49
|
+
@@mediatemple
|
50
|
+
%html
|
51
|
+
%head
|
52
|
+
= Rack::JQuery.cdn( :media_temple )
|
53
|
+
= Rack::JQueryUI.cdn( :organisation => :media_temple )
|
54
|
+
= yield
|
55
|
+
|
56
|
+
@@unspecified
|
57
|
+
%html
|
58
|
+
%head
|
59
|
+
= Rack::JQuery.cdn()
|
60
|
+
= Rack::JQueryUI.cdn()
|
61
|
+
= yield
|
62
|
+
|
63
|
+
@@index
|
64
|
+
|
65
|
+
%p.aclass
|
66
|
+
"NOTHING TO SEE HERE… "
|
67
|
+
%p.aclass
|
68
|
+
"MOVE ALONG… "
|
69
|
+
%p.aclass
|
70
|
+
"MOVE ALONG… "
|
71
|
+
#placeholder
|
72
|
+
:javascript
|
73
|
+
all_text = $('.aclass').text();
|
74
|
+
$('#placeholder').text(all_text + " (draggable!)").mouseover(function() {
|
75
|
+
$(this).css({ 'color': 'red', 'font-size': '150%' });
|
76
|
+
}).mouseout(function() {
|
77
|
+
$(this).css({ 'color': 'blue', 'font-size': '100%' });
|
78
|
+
}).draggable();
|
data/examples/config.ru
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require "rack/jquery_ui/version"
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
|
5
|
+
# jQuery CDN script tags and fallback in one neat package.
|
6
|
+
class JQueryUI
|
7
|
+
|
8
|
+
JQUERY_UI_FILE_NAME = "jquery-ui.min.js"
|
9
|
+
|
10
|
+
# Script tags for the Media Temple CDN
|
11
|
+
MEDIA_TEMPLE = "<script src='http://code.jquery.com/ui/1.10.1/jquery-ui.js'></script>"
|
12
|
+
|
13
|
+
# Script tags for the Google CDN
|
14
|
+
GOOGLE = "<script src='//ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js'></script>"
|
15
|
+
|
16
|
+
# Script tags for the Microsoft CDN
|
17
|
+
MICROSOFT = "<script src='//ajax.aspnetcdn.com/ajax/jquery.ui/1.10.1/jquery-ui.min.js'></script>"
|
18
|
+
|
19
|
+
# 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.
|
20
|
+
FALLBACK = <<STR
|
21
|
+
<script type="text/javascript">
|
22
|
+
!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"))
|
23
|
+
</script>
|
24
|
+
STR
|
25
|
+
|
26
|
+
|
27
|
+
# Ten years in seconds.
|
28
|
+
TEN_YEARS = 60 * 60 * 24 * 365 * 10
|
29
|
+
|
30
|
+
|
31
|
+
# default options when setting up the CDN
|
32
|
+
CDN_DEFAULTS = {css: true, js: true, fallback: true}
|
33
|
+
|
34
|
+
# @param [Symbol] organisation Choose which CDN to use, either :google, :microsoft or :media_temple
|
35
|
+
# @return [String] The HTML script tags to get the CDN.
|
36
|
+
def self.cdn( opts={} )
|
37
|
+
opts = CDN_DEFAULTS.merge opts
|
38
|
+
organisation = opts.fetch :organisation, :google
|
39
|
+
script = case organisation
|
40
|
+
when :media_temple then MEDIA_TEMPLE
|
41
|
+
when :microsoft then MICROSOFT
|
42
|
+
else GOOGLE
|
43
|
+
end
|
44
|
+
"#{script}\n#{FALLBACK}"
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
# Default options hash for the middleware.
|
49
|
+
DEFAULT_OPTIONS = {
|
50
|
+
:http_path => "/js/jquery-ui/#{JQUERY_UI_VERSION}"
|
51
|
+
}
|
52
|
+
|
53
|
+
|
54
|
+
# @param [#call] app
|
55
|
+
# @param [Hash] options
|
56
|
+
# @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}".
|
57
|
+
# @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!
|
58
|
+
# @example
|
59
|
+
# # The default:
|
60
|
+
# use Rack::JQueryUI
|
61
|
+
# # With a different route to the fallback:
|
62
|
+
# use Rack::JQueryUI, :http_path => "/assets/js/#{Rack::JQueryUI::JQUERY_UI_VERSION}"
|
63
|
+
def initialize( app, options={} )
|
64
|
+
@app, @options = app, DEFAULT_OPTIONS.merge(options)
|
65
|
+
@http_path_to_jquery = ::File.join @options[:http_path], JQUERY_UI_FILE_NAME
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
# @param [Hash] env Rack request environment hash.
|
70
|
+
def call( env )
|
71
|
+
request = Rack::Request.new(env.dup)
|
72
|
+
if request.path_info == @http_path_to_jquery
|
73
|
+
response = Rack::Response.new
|
74
|
+
# for caching
|
75
|
+
response.headers.merge!( {
|
76
|
+
"Last-Modified" => JQUERY_UI_VERSION_DATE,
|
77
|
+
"Expires" => Rack::Utils.rfc2109(Time.now + TEN_YEARS),
|
78
|
+
"Cache-Control" => "max-age=#{TEN_YEARS},public",
|
79
|
+
"Etag" => "#{JQUERY_UI_FILE_NAME}-#{JQUERY_UI_VERSION}",
|
80
|
+
'Content-Type' =>'application/javascript; charset=utf-8'
|
81
|
+
})
|
82
|
+
|
83
|
+
# 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.
|
84
|
+
if request.env['HTTP_IF_MODIFIED_SINCE']
|
85
|
+
response.status = 304
|
86
|
+
else
|
87
|
+
response.status = 200
|
88
|
+
response.write ::File.read( ::File.expand_path "../../../vendor/assets/javascripts/jquery-ui/#{JQUERY_UI_VERSION}/#{JQUERY_UI_FILE_NAME}", __FILE__)
|
89
|
+
end
|
90
|
+
response.finish
|
91
|
+
else
|
92
|
+
@app.call(env)
|
93
|
+
end
|
94
|
+
end # call
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Rack
|
2
|
+
class JQueryUI
|
3
|
+
VERSION = "0.0.1"
|
4
|
+
JQUERY_UI_VERSION = "1.10.1"
|
5
|
+
|
6
|
+
# This is the release date of the jQuery file, it makes an easy "Last-Modified" date for setting the headers around caching.
|
7
|
+
# @todo remember to change Last-Modified with each release!
|
8
|
+
JQUERY_UI_VERSION_DATE = "Fri, 15 Feb 2013 00:00:00 GMT"
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/jquery_ui/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rack-jquery_ui"
|
8
|
+
spec.version = Rack::JQueryUI::VERSION
|
9
|
+
spec.authors = ["Iain Barnett"]
|
10
|
+
spec.email = ["iainspeed@gmail.com"]
|
11
|
+
spec.description = %q{jQuery-UI CDN script tags and fallback in one neat package. Current version is for jQuery-UI v#{Rack::JQueryUI::JQUERY_UI_VERSION}}
|
12
|
+
spec.summary = %q{The description says it all.}
|
13
|
+
spec.homepage = "https://github.com/yb66/rack-jquery_ui"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.2"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency("rack")
|
24
|
+
end
|