rails3-jquery-autocomplete 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest ADDED
@@ -0,0 +1,7 @@
1
+ README.rdoc
2
+ Rakefile
3
+ lib/autocomplete.rb
4
+ lib/generators/autocomplete_generator.rb
5
+ lib/generators/templates/autocomplete-rails.js
6
+ lib/generators/templates/autocomplete.rb
7
+ Manifest
data/README.rdoc ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('rails3-jquery-autocomplete', '0.0.1') do |p|
6
+ p.description = "Use jQuery's autocomplete plugin with Rails 3."
7
+ p.url = "http://github.com/crowdint/rails3-jquery-autocomplete"
8
+ p.author = "David Padilla"
9
+ p.email = "david@crowdint.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
@@ -0,0 +1,45 @@
1
+ module AutoComplete
2
+
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ # Inspired on DHH's autocomplete plugin
8
+ #
9
+ # Usage:
10
+ #
11
+ # class ProductsController < Admin::BaseController
12
+ # autocomplete :brand, :name
13
+ # end
14
+ #
15
+ # This will magically generate an action autocomplete_brand_name, so,
16
+ # don't forget to add it on your routes file
17
+ #
18
+ # resources :products do
19
+ # get :autocomplete_brand_name, :on => :collection
20
+ # end
21
+ #
22
+ # Now, on your view, all you have to do is have a text field like:
23
+ #
24
+ # f.text_field :brand_name, :autocomplete => autocomplete_brand_name_products_path
25
+ #
26
+ # That's it!
27
+ #
28
+ #
29
+ module ClassMethods
30
+ def autocomplete(object, method, options = {})
31
+ limit = options[:limit] || 10
32
+ order = options[:order] || "#{method} ASC"
33
+
34
+ define_method("autocomplete_#{object}_#{method}") do
35
+ unless params[:q] && params[:q].empty?
36
+ items = object.to_s.camelize.constantize.where(["LOWER(#{method}) LIKE ?", "#{params[:q]}%"]).limit(limit).order(order)
37
+ else
38
+ items = []
39
+ end
40
+
41
+ render :text => items.collect {|i| i[method]}.join("\n")
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,14 @@
1
+ require 'rails/generators'
2
+
3
+ class AutocompleteGenerator < Rails::Generators::Base
4
+ def install
5
+ # Copy the unobtrusive JS file
6
+ copy_file('autocomplete-rails.js', 'public/autocomplete-rails.js')
7
+ # Rails initializer
8
+ copy_file('autocomplete.rb', 'initializers/autocomplete.rb')
9
+ end
10
+
11
+ def self.source_root
12
+ File.join(File.dirname(__FILE__), 'templates')
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Unobtrusive autocomplete
3
+ *
4
+ * To use it, you just have to include the HTML attribute autocomplete
5
+ * with the autocomplete URL as the value
6
+ *
7
+ * Example:
8
+ * <input type="text" autocomplete="/url/to/autocomplete">
9
+ *
10
+ */
11
+
12
+ $(document).ready(function(){
13
+ $('input[autocomplete]').each(function(i){
14
+ $(this).autocomplete($(this).attr('autocomplete'));
15
+ });
16
+ });
@@ -0,0 +1,2 @@
1
+ require 'autocomplete'
2
+ ActionController::Base.send :include, AutoComplete
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rails3-jquery-autocomplete}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["David Padilla"]
9
+ s.date = %q{2010-07-13}
10
+ s.description = %q{Use jQuery's autocomplete plugin with Rails 3.}
11
+ s.email = %q{david@crowdint.com}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/autocomplete.rb", "lib/generators/autocomplete_generator.rb", "lib/generators/templates/autocomplete-rails.js", "lib/generators/templates/autocomplete.rb"]
13
+ s.files = ["README.rdoc", "Rakefile", "lib/autocomplete.rb", "lib/generators/autocomplete_generator.rb", "lib/generators/templates/autocomplete-rails.js", "lib/generators/templates/autocomplete.rb", "Manifest", "rails3-jquery-autocomplete.gemspec"]
14
+ s.homepage = %q{http://github.com/crowdint/rails3-jquery-autocomplete}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rails3-jquery-autocomplete", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{rails3-jquery-autocomplete}
18
+ s.rubygems_version = %q{1.3.7}
19
+ s.summary = %q{Use jQuery's autocomplete plugin with Rails 3.}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails3-jquery-autocomplete
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - David Padilla
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-13 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Use jQuery's autocomplete plugin with Rails 3.
23
+ email: david@crowdint.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ - lib/autocomplete.rb
31
+ - lib/generators/autocomplete_generator.rb
32
+ - lib/generators/templates/autocomplete-rails.js
33
+ - lib/generators/templates/autocomplete.rb
34
+ files:
35
+ - README.rdoc
36
+ - Rakefile
37
+ - lib/autocomplete.rb
38
+ - lib/generators/autocomplete_generator.rb
39
+ - lib/generators/templates/autocomplete-rails.js
40
+ - lib/generators/templates/autocomplete.rb
41
+ - Manifest
42
+ - rails3-jquery-autocomplete.gemspec
43
+ has_rdoc: true
44
+ homepage: http://github.com/crowdint/rails3-jquery-autocomplete
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --line-numbers
50
+ - --inline-source
51
+ - --title
52
+ - Rails3-jquery-autocomplete
53
+ - --main
54
+ - README.rdoc
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 11
72
+ segments:
73
+ - 1
74
+ - 2
75
+ version: "1.2"
76
+ requirements: []
77
+
78
+ rubyforge_project: rails3-jquery-autocomplete
79
+ rubygems_version: 1.3.7
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Use jQuery's autocomplete plugin with Rails 3.
83
+ test_files: []
84
+