rails3-jquery-autocomplete 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.markdown +24 -8
- data/Rakefile +49 -9
- data/VERSION +1 -0
- data/lib/{autocomplete.rb → rails3-jquery-autocomplete.rb} +2 -4
- data/rails3-jquery-autocomplete.gemspec +32 -8
- data/test/test_helper.rb +9 -9
- metadata +16 -22
- data/Manifest +0 -11
- data/init.rb +0 -1
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 David Padilla
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
CHANGED
@@ -13,13 +13,13 @@ You can find more info about that here:
|
|
13
13
|
* http://jqueryui.com/demos/autocomplete/
|
14
14
|
* http://github.com/rails/jquery-ujs
|
15
15
|
|
16
|
-
I'd
|
16
|
+
I'd encourage you to understand how to use those 3 amazing tools before attempting to use this gem.
|
17
17
|
|
18
18
|
## Installing
|
19
19
|
|
20
20
|
Include the gem on your Gemfile
|
21
21
|
|
22
|
-
gem 'rails3-jquery-autocomplete', '>= 0.
|
22
|
+
gem 'rails3-jquery-autocomplete', '>= 0.2.0'
|
23
23
|
|
24
24
|
Install it
|
25
25
|
|
@@ -35,17 +35,27 @@ And include autocomplete-rails.js on your layouts
|
|
35
35
|
|
36
36
|
## Usage
|
37
37
|
|
38
|
+
### Model Example
|
39
|
+
|
40
|
+
Assuming you have a Brand model:
|
41
|
+
|
42
|
+
class Brand < ActiveRecord::Base
|
43
|
+
end
|
44
|
+
|
45
|
+
create_table :brand do |t|
|
46
|
+
t.column :name, :string
|
47
|
+
end
|
48
|
+
|
38
49
|
### Controller
|
39
50
|
|
40
|
-
To set up
|
51
|
+
To set up the required action on your controller, all you have to do is call it with the class name and the method
|
41
52
|
as in the following example:
|
42
53
|
|
43
54
|
class ProductsController < Admin::BaseController
|
44
55
|
autocomplete :brand, :name
|
45
56
|
end
|
46
57
|
|
47
|
-
This will
|
48
|
-
don't forget to add it on your routes file
|
58
|
+
This will create an action _autocomplete_brand_name_ on your controller, don't forget to add it on your routes file
|
49
59
|
|
50
60
|
resources :products do
|
51
61
|
get :autocomplete_brand_name, :on => :collection
|
@@ -57,12 +67,20 @@ By default, the search starts from the beginning of the string you're searching
|
|
57
67
|
autocomplete :brand, :name, :full => true
|
58
68
|
end
|
59
69
|
|
60
|
-
|
70
|
+
#### :full => true
|
71
|
+
|
72
|
+
The following terms would match the query 'un':
|
61
73
|
|
62
74
|
* Luna
|
63
75
|
* Unacceptable
|
64
76
|
* Rerun
|
65
77
|
|
78
|
+
#### :full => false
|
79
|
+
|
80
|
+
Only the following terms mould match the query 'un':
|
81
|
+
|
82
|
+
* Unacceptable
|
83
|
+
|
66
84
|
### View
|
67
85
|
|
68
86
|
On your view, all you have to do is include the attribute autocomplete on the text field
|
@@ -76,5 +94,3 @@ This will generate an HTML tag that looks like:
|
|
76
94
|
<input type="text" autocomplete="products/autocomplete_brand_name">
|
77
95
|
|
78
96
|
Now your autocomplete JS code is unobtrusive, Rails 3 style.
|
79
|
-
|
80
|
-
And... That's it!
|
data/Rakefile
CHANGED
@@ -1,12 +1,52 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rails3-jquery-autocomplete"
|
8
|
+
gem.summary = %Q{Use jQuery's autocomplete plugin with Rails 3.}
|
9
|
+
gem.description = %Q{Use jQuery's autocomplete plugin with Rails 3.}
|
10
|
+
gem.email = "david.padilla@crowdint.com"
|
11
|
+
gem.homepage = "http://github.com/crowdint/rails3-jquery-autocomplete"
|
12
|
+
gem.authors = ["David Padilla"]
|
13
|
+
# gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/*_test.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "rails3-jquery-autocomplete #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
12
52
|
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Rails3JQueryAutocomplete
|
2
2
|
def self.included(base)
|
3
3
|
base.extend(ClassMethods)
|
4
4
|
end
|
@@ -22,8 +22,6 @@ module Autocomplete
|
|
22
22
|
#
|
23
23
|
# f.text_field :brand_name, :autocomplete => autocomplete_brand_name_products_path
|
24
24
|
#
|
25
|
-
# That's it!
|
26
|
-
#
|
27
25
|
#
|
28
26
|
module ClassMethods
|
29
27
|
def autocomplete(object, method, options = {})
|
@@ -50,5 +48,5 @@ module Autocomplete
|
|
50
48
|
end
|
51
49
|
|
52
50
|
class ActionController::Base
|
53
|
-
include
|
51
|
+
include Rails3JQueryAutocomplete
|
54
52
|
end
|
@@ -1,23 +1,46 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
1
4
|
# -*- encoding: utf-8 -*-
|
2
5
|
|
3
6
|
Gem::Specification.new do |s|
|
4
7
|
s.name = %q{rails3-jquery-autocomplete}
|
5
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
6
9
|
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">=
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
11
|
s.authors = ["David Padilla"]
|
9
12
|
s.date = %q{2010-07-25}
|
10
13
|
s.description = %q{Use jQuery's autocomplete plugin with Rails 3.}
|
11
|
-
s.email = %q{david@crowdint.com}
|
12
|
-
s.extra_rdoc_files = [
|
13
|
-
|
14
|
+
s.email = %q{david.padilla@crowdint.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.markdown",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/generators/autocomplete_generator.rb",
|
27
|
+
"lib/generators/templates/autocomplete-rails.js",
|
28
|
+
"lib/rails3-jquery-autocomplete.rb",
|
29
|
+
"rails3-jquery-autocomplete.gemspec",
|
30
|
+
"test/autocomplete_generator_test.rb",
|
31
|
+
"test/controller_module_test.rb",
|
32
|
+
"test/test_helper.rb"
|
33
|
+
]
|
14
34
|
s.homepage = %q{http://github.com/crowdint/rails3-jquery-autocomplete}
|
15
|
-
s.rdoc_options = ["--
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
16
36
|
s.require_paths = ["lib"]
|
17
|
-
s.rubyforge_project = %q{rails3-jquery-autocomplete}
|
18
37
|
s.rubygems_version = %q{1.3.7}
|
19
38
|
s.summary = %q{Use jQuery's autocomplete plugin with Rails 3.}
|
20
|
-
s.test_files = [
|
39
|
+
s.test_files = [
|
40
|
+
"test/autocomplete_generator_test.rb",
|
41
|
+
"test/controller_module_test.rb",
|
42
|
+
"test/test_helper.rb"
|
43
|
+
]
|
21
44
|
|
22
45
|
if s.respond_to? :specification_version then
|
23
46
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
@@ -29,3 +52,4 @@ Gem::Specification.new do |s|
|
|
29
52
|
else
|
30
53
|
end
|
31
54
|
end
|
55
|
+
|
data/test/test_helper.rb
CHANGED
@@ -3,31 +3,31 @@ require 'test/unit'
|
|
3
3
|
require 'rubygems'
|
4
4
|
gem 'rails', '>=3.0.0.beta4'
|
5
5
|
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
|
6
9
|
require "active_support"
|
7
10
|
require "active_record"
|
8
11
|
require "active_model"
|
9
12
|
require "action_controller"
|
10
13
|
require "rails/railtie"
|
11
14
|
|
12
|
-
|
13
|
-
RAILS_ROOT = "anywhere"
|
14
|
-
|
15
|
-
require "#{File.dirname(__FILE__)}/../init"
|
15
|
+
require 'rails3-jquery-autocomplete'
|
16
16
|
|
17
17
|
class ApplicationController < ActionController::Base; end
|
18
18
|
|
19
19
|
ActionController::Base.view_paths = File.join(File.dirname(__FILE__), 'views')
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
Rails3JQueryAutocomplete::Routes = ActionDispatch::Routing::RouteSet.new
|
22
|
+
Rails3JQueryAutocomplete::Routes.draw do |map|
|
23
23
|
map.connect ':controller/:action/:id'
|
24
24
|
map.connect ':controller/:action'
|
25
25
|
end
|
26
26
|
|
27
|
-
ActionController::Base.send :include,
|
27
|
+
ActionController::Base.send :include, Rails3JQueryAutocomplete::Routes.url_helpers
|
28
28
|
|
29
29
|
class ActiveSupport::TestCase
|
30
30
|
setup do
|
31
|
-
@routes =
|
31
|
+
@routes = Rails3JQueryAutocomplete::Routes
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails3-jquery-autocomplete
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Padilla
|
@@ -20,40 +20,35 @@ default_executable:
|
|
20
20
|
dependencies: []
|
21
21
|
|
22
22
|
description: Use jQuery's autocomplete plugin with Rails 3.
|
23
|
-
email: david@crowdint.com
|
23
|
+
email: david.padilla@crowdint.com
|
24
24
|
executables: []
|
25
25
|
|
26
26
|
extensions: []
|
27
27
|
|
28
28
|
extra_rdoc_files:
|
29
|
+
- LICENSE
|
29
30
|
- README.markdown
|
30
|
-
- lib/autocomplete.rb
|
31
|
-
- lib/generators/autocomplete_generator.rb
|
32
|
-
- lib/generators/templates/autocomplete-rails.js
|
33
31
|
files:
|
32
|
+
- .document
|
33
|
+
- .gitignore
|
34
|
+
- LICENSE
|
34
35
|
- README.markdown
|
35
36
|
- Rakefile
|
36
|
-
-
|
37
|
-
- lib/autocomplete.rb
|
37
|
+
- VERSION
|
38
38
|
- lib/generators/autocomplete_generator.rb
|
39
39
|
- lib/generators/templates/autocomplete-rails.js
|
40
|
+
- lib/rails3-jquery-autocomplete.rb
|
40
41
|
- rails3-jquery-autocomplete.gemspec
|
41
42
|
- test/autocomplete_generator_test.rb
|
42
43
|
- test/controller_module_test.rb
|
43
44
|
- test/test_helper.rb
|
44
|
-
- Manifest
|
45
45
|
has_rdoc: true
|
46
46
|
homepage: http://github.com/crowdint/rails3-jquery-autocomplete
|
47
47
|
licenses: []
|
48
48
|
|
49
49
|
post_install_message:
|
50
50
|
rdoc_options:
|
51
|
-
- --
|
52
|
-
- --inline-source
|
53
|
-
- --title
|
54
|
-
- Rails3-jquery-autocomplete
|
55
|
-
- --main
|
56
|
-
- README.markdown
|
51
|
+
- --charset=UTF-8
|
57
52
|
require_paths:
|
58
53
|
- lib
|
59
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -70,14 +65,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
65
|
requirements:
|
71
66
|
- - ">="
|
72
67
|
- !ruby/object:Gem::Version
|
73
|
-
hash:
|
68
|
+
hash: 3
|
74
69
|
segments:
|
75
|
-
-
|
76
|
-
|
77
|
-
version: "1.2"
|
70
|
+
- 0
|
71
|
+
version: "0"
|
78
72
|
requirements: []
|
79
73
|
|
80
|
-
rubyforge_project:
|
74
|
+
rubyforge_project:
|
81
75
|
rubygems_version: 1.3.7
|
82
76
|
signing_key:
|
83
77
|
specification_version: 3
|
data/Manifest
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
README.markdown
|
2
|
-
Rakefile
|
3
|
-
init.rb
|
4
|
-
lib/autocomplete.rb
|
5
|
-
lib/generators/autocomplete_generator.rb
|
6
|
-
lib/generators/templates/autocomplete-rails.js
|
7
|
-
rails3-jquery-autocomplete.gemspec
|
8
|
-
test/autocomplete_generator_test.rb
|
9
|
-
test/controller_module_test.rb
|
10
|
-
test/test_helper.rb
|
11
|
-
Manifest
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'autocomplete'
|