jquery-rails 0.1.3 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of jquery-rails might be problematic. Click here for more details.
- data/.gitignore +2 -1
- data/README.md +1 -1
- data/Rakefile +8 -0
- data/lib/generators/jquery/install/install_generator.rb +15 -5
- data/lib/jquery-rails.rb +4 -2
- data/lib/jquery-rails/version.rb +1 -1
- data/spec/jquery-rails_spec.rb +6 -2
- data/spec/support/custom_app/Gemfile.lock +1 -1
- data/spec/support/default_app/Gemfile.lock +1 -1
- data/test/lib/generators/jquery/install_generator_test.rb +24 -0
- data/test/test_helper.rb +23 -0
- metadata +6 -5
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -12,6 +12,6 @@ In your Gemfile, add this line:
|
|
12
12
|
|
13
13
|
Then, run `bundle install`. To invoke the generator, run:
|
14
14
|
|
15
|
-
rails generate jquery:install #--ui to enable jQuery UI
|
15
|
+
rails generate jquery:install #--ui to enable jQuery UI --version to install specific version of JQuery (default is 1.4.2)
|
16
16
|
|
17
17
|
You're done! Don't forget to output `csrf_meta_tag` somewhere inside your `<head>` tag in your layout!
|
data/Rakefile
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
module Jquery
|
2
2
|
module Generators
|
3
3
|
class InstallGenerator < ::Rails::Generators::Base
|
4
|
-
desc "This generator downloads and installs jQuery
|
5
|
-
class_option :ui, :type => :boolean, :default => false, :desc => "
|
4
|
+
desc "This generator downloads and installs jQuery, jQuery-ujs HEAD, and (optionally) jQuery UI 1.8.4"
|
5
|
+
class_option :ui, :type => :boolean, :default => false, :desc => "Whether to Include JQueryUI"
|
6
|
+
class_option :version, :type => :string, :default => "1.4.2", :desc => "Which version of JQuery to fetch"
|
7
|
+
@@versions = %w( 1.4.2 1.4.1 1.4.0 1.3.2 1.3.1 1.3.0 1.2.6 )
|
8
|
+
|
6
9
|
|
7
10
|
def remove_prototype
|
8
11
|
%w(controls.js dragdrop.js effects.js prototype.js).each do |js|
|
@@ -12,8 +15,15 @@ module Jquery
|
|
12
15
|
|
13
16
|
def download_jquery
|
14
17
|
# Downloading latest jQuery
|
15
|
-
|
16
|
-
|
18
|
+
if @@versions.include?(options.version)
|
19
|
+
puts "Fetching JQuery version #{options.version}!"
|
20
|
+
get "http://ajax.googleapis.com/ajax/libs/jquery/#{options.version}/jquery.min.js", "public/javascripts/jquery.min.js"
|
21
|
+
get "http://ajax.googleapis.com/ajax/libs/jquery/#{options.version}/jquery.js", "public/javascripts/jquery.js"
|
22
|
+
else
|
23
|
+
puts "JQuery #{options.version} is invalid; fetching #{@@versions[0]} instead."
|
24
|
+
get "http://ajax.googleapis.com/ajax/libs/jquery/#{@@versions[0]}/jquery.min.js", "public/javascripts/jquery.min.js"
|
25
|
+
get "http://ajax.googleapis.com/ajax/libs/jquery/#{@@versions[0]}/jquery.js", "public/javascripts/jquery.js"
|
26
|
+
end
|
17
27
|
|
18
28
|
# Downloading latest jQueryUI minified
|
19
29
|
get "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js", "public/javascripts/jquery-ui.min.js" if options.ui?
|
@@ -27,4 +37,4 @@ module Jquery
|
|
27
37
|
|
28
38
|
end
|
29
39
|
end
|
30
|
-
end
|
40
|
+
end
|
data/lib/jquery-rails.rb
CHANGED
@@ -3,10 +3,12 @@ module Jquery
|
|
3
3
|
class Railtie < ::Rails::Railtie
|
4
4
|
config.before_configuration do
|
5
5
|
if ::Rails.root.join("public/javascripts/jquery-ui.min.js").exist?
|
6
|
-
|
6
|
+
jq_defaults = %w(jquery jquery-ui)
|
7
|
+
jq_defaults.map!{|a| a + ".min" } unless ::Rails.env.development?
|
7
8
|
else
|
8
|
-
|
9
|
+
jq_defaults = ::Rails.env.development? ? %w(jquery) : %w(jquery.min)
|
9
10
|
end
|
11
|
+
config.action_view.javascript_expansions[:defaults] = jq_defaults + %w(rails)
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
data/lib/jquery-rails/version.rb
CHANGED
data/spec/jquery-rails_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
describe "jQuery-Rails" do
|
2
|
-
def get_js_defaults(name)
|
2
|
+
def get_js_defaults(name, env = "production")
|
3
3
|
dir = File.expand_path("../support/#{name}_app", __FILE__)
|
4
4
|
Dir.chdir(dir) do
|
5
5
|
`bundle install --local`
|
6
|
-
`rails runner 'puts Rails.application.config.action_view.
|
6
|
+
`rails runner -e #{env} 'puts Rails.application.config.action_view.
|
7
7
|
javascript_expansions[:defaults].inspect'`.chomp
|
8
8
|
end
|
9
9
|
end
|
@@ -12,6 +12,10 @@ describe "jQuery-Rails" do
|
|
12
12
|
get_js_defaults("default").should == ["jquery.min", "rails"].inspect
|
13
13
|
end
|
14
14
|
|
15
|
+
it "uses non-minified js in development" do
|
16
|
+
get_js_defaults("default", "development").should == %w(jquery rails).inspect
|
17
|
+
end
|
18
|
+
|
15
19
|
it "changes allows overriding the javascript expansion" do
|
16
20
|
get_js_defaults("custom").should == ["foo", "bar", "baz"].inspect
|
17
21
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'generators/jquery/install/install_generator'
|
3
|
+
|
4
|
+
class Jquery::Generators::InstallGeneratorTest < Rails::Generators::TestCase
|
5
|
+
destination File.join(Rails.root)
|
6
|
+
tests Jquery::Generators::InstallGenerator
|
7
|
+
arguments []
|
8
|
+
|
9
|
+
setup :prepare_destination
|
10
|
+
|
11
|
+
test 'jquery is installed' do
|
12
|
+
run_generator
|
13
|
+
|
14
|
+
%w(jquery.min.js jquery.js rails.js).each { |js| assert_file "public/javascripts/#{js}" }
|
15
|
+
%w(controls.js dragdrop.js effects.js prototype.js).each { |js| assert_no_file "public/javascripts/#{js}" }
|
16
|
+
end
|
17
|
+
|
18
|
+
test 'jquery is installed with jqueyui' do
|
19
|
+
run_generator %w(--ui)
|
20
|
+
|
21
|
+
%w(jquery.min.js jquery.js jquery-ui.min.js jquery-ui.js rails.js).each { |js| assert_file "public/javascripts/#{js}" }
|
22
|
+
%w(controls.js dragdrop.js effects.js prototype.js).each { |js| assert_no_file "public/javascripts/#{js}" }
|
23
|
+
end
|
24
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rails/all'
|
4
|
+
require 'rails/generators'
|
5
|
+
require 'rails/generators/test_case'
|
6
|
+
|
7
|
+
class TestApp < Rails::Application
|
8
|
+
config.root = File.dirname(__FILE__)
|
9
|
+
end
|
10
|
+
Rails.application = TestApp
|
11
|
+
|
12
|
+
module Rails
|
13
|
+
def self.root
|
14
|
+
@root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'rails'))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
Rails.application.config.root = Rails.root
|
18
|
+
|
19
|
+
# Call configure to load the settings from
|
20
|
+
# Rails.application.config.generators to Rails::Generators
|
21
|
+
Rails::Generators.configure!
|
22
|
+
|
23
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jquery-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.1.3
|
8
|
+
- 2
|
9
|
+
version: "0.2"
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- "Andr\xC3\xA9 Arko"
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-10-02 00:00:00 -07:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -96,6 +95,8 @@ files:
|
|
96
95
|
- spec/support/default_app/config/environments/test.rb
|
97
96
|
- spec/support/default_app/config/routes.rb
|
98
97
|
- spec/support/default_app/script/rails
|
98
|
+
- test/lib/generators/jquery/install_generator_test.rb
|
99
|
+
- test/test_helper.rb
|
99
100
|
has_rdoc: true
|
100
101
|
homepage: http://rubygems.org/gems/jquery-rails
|
101
102
|
licenses: []
|