rails3-jquery-autocomplete 0.9.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  # Changelog
2
2
 
3
+ * 1.0.0 Rails 3.1 asset pipeline support
3
4
  * 0.9.1 Fixes issues #96 and #32
4
5
  * 0.9.0 Massive rewrite
5
6
  * 0.8.0 Compressed JS file
data/README.markdown CHANGED
@@ -17,10 +17,6 @@ on how to use this gem with ActiveRecord [here](http://github.com/crowdint/rails
17
17
  You can find a [detailed example](http://github.com/crowdint/rails3-jquery-autocomplete-app/tree/mongoid)
18
18
  on how to use this gem with MongoID [here](http://github.com/crowdint/rails3-jquery-autocomplete-app/tree/mongoid). (Same thing, different branch)
19
19
 
20
- ## MongoMapper
21
-
22
- TODO
23
-
24
20
  ## Before you start
25
21
 
26
22
  Make sure your project is using jQuery-UI and the autocomplete widget
@@ -44,6 +40,8 @@ Install it
44
40
 
45
41
  bundle install
46
42
 
43
+ ### Rails 3.0.x
44
+
47
45
  Run the generator
48
46
 
49
47
  rails generate autocomplete:install
@@ -52,6 +50,14 @@ And include autocomplete-rails.js on your layouts
52
50
 
53
51
  javascript_include_tag "autocomplete-rails.js"
54
52
 
53
+ ### Rails 3.1.x
54
+
55
+ Just add it to your app/assets/javascripts/application.js file
56
+
57
+ //= require jquery
58
+ //= require jquery_ujs
59
+ //= require autocomplete
60
+
55
61
  ## Upgrading from older versions
56
62
 
57
63
  If you are upgrading from a previous version, run the generator after installing to replace the javascript file.
@@ -226,7 +232,7 @@ A javascript event named *railsAutocomplete.select* is fired on the input field
226
232
  If you are using [Formtastic](http://github.com/justinfrench/formtastic), you automatically get the *autocompleted_input* helper on *semantic_form_for*:
227
233
 
228
234
  semantic_form_for @product do |f|
229
- f.autocompleted_input :brand_name, :url => autocomplete_brand_name_products_path
235
+ f.input :brand_name, :as => :autocomplete, :url => autocomplete_brand_name_products_path
230
236
  end
231
237
 
232
238
  The only difference with the original helper is that you must specify the autocomplete url using the *:url* option.
@@ -281,9 +287,9 @@ Then you'll have access to the following helper:
281
287
  An example on how to use it:
282
288
 
283
289
  scenario "Autocomplete" do
284
- lambda do
290
+ lambda do
285
291
  Brand.create! [
286
- {:name => "Alpha"},
292
+ {:name => "Alpha"},
287
293
  {:name => "Beta"},
288
294
  {:name => "Gamma"}
289
295
  ]
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ end
14
14
 
15
15
  task :uglify do
16
16
  require 'uglifier'
17
- file_folder = "lib/generators/templates"
17
+ file_folder = "lib/assets/javascripts"
18
18
  File.open("#{file_folder}/autocomplete-rails.js", "w") do |f|
19
19
  f << Uglifier.compile(File.read("#{file_folder}/autocomplete-rails-uncompressed.js"))
20
20
  end
@@ -13,4 +13,4 @@
13
13
  * Example:
14
14
  * <input type="text" data-autocomplete="/url/to/autocomplete" data-id-element="#id_field">
15
15
  */
16
- $(document).ready(function(){$("input[data-autocomplete]").railsAutocomplete()}),function(a){var b=null;a.fn.railsAutocomplete=function(){return this.live("focus",function(){this.railsAutoCompleter||(this.railsAutoCompleter=new a.railsAutocomplete(this))})},a.railsAutocomplete=function(a){_e=a,this.init(_e)},a.railsAutocomplete.fn=a.railsAutocomplete.prototype={railsAutocomplete:"0.0.1"},a.railsAutocomplete.fn.extend=a.railsAutocomplete.extend=a.extend,a.railsAutocomplete.fn.extend({init:function(a){function c(a){return b(a).pop().replace(/^\s+/,"")}function b(b){return b.split(a.delimiter)}a.delimiter=$(a).attr("data-delimiter")||null,$(a).autocomplete({source:function(b,d){$.getJSON($(a).attr("data-autocomplete"),{term:c(b.term)},function(){$(arguments[0]).each(function(b,c){var d={};d[c.id]=c,$(a).data(d)}),d.apply(null,arguments)})},search:function(){var a=c(this.value);if(a.length<2)return!1},focus:function(){return!1},select:function(c,d){var f=b(this.value);f.pop(),f.push(d.item.value);if(a.delimiter!=null)f.push(""),this.value=f.join(a.delimiter);else{this.value=f.join(""),$(this).attr("data-id-element")&&$($(this).attr("data-id-element")).val(d.item.id);if($(this).attr("data-update-elements")){var g=$(this).data(d.item.id.toString()),h=$.parseJSON($(this).attr("data-update-elements"));for(var i in h)$(h[i]).val(g[i])}}var j=this.value;$(this).bind("keyup.clearId",function(){$(this).val().trim()!=j.trim()&&($($(this).attr("data-id-element")).val(""),$(this).unbind("keyup.clearId"))}),$(this).trigger("railsAutocomplete.select",d);return!1}})}})}(jQuery)
16
+ $(document).ready(function(){$("input[data-autocomplete]").railsAutocomplete()}),function(a){var b=null;a.fn.railsAutocomplete=function(){return this.live("focus",function(){this.railsAutoCompleter||(this.railsAutoCompleter=new a.railsAutocomplete(this))})},a.railsAutocomplete=function(a){_e=a,this.init(_e)},a.railsAutocomplete.fn=a.railsAutocomplete.prototype={railsAutocomplete:"0.0.1"},a.railsAutocomplete.fn.extend=a.railsAutocomplete.extend=a.extend,a.railsAutocomplete.fn.extend({init:function(a){function b(b){return b.split(a.delimiter)}function c(a){return b(a).pop().replace(/^\s+/,"")}a.delimiter=$(a).attr("data-delimiter")||null,$(a).autocomplete({source:function(b,d){$.getJSON($(a).attr("data-autocomplete"),{term:c(b.term)},function(){$(arguments[0]).each(function(b,c){var d={};d[c.id]=c,$(a).data(d)}),d.apply(null,arguments)})},search:function(){var a=c(this.value);if(a.length<2)return!1},focus:function(){return!1},select:function(c,d){var f=b(this.value);f.pop(),f.push(d.item.value);if(a.delimiter!=null)f.push(""),this.value=f.join(a.delimiter);else{this.value=f.join(""),$(this).attr("data-id-element")&&$($(this).attr("data-id-element")).val(d.item.id);if($(this).attr("data-update-elements")){var g=$(this).data(d.item.id.toString()),h=$.parseJSON($(this).attr("data-update-elements"));for(var i in h)$(h[i]).val(g[i])}}var j=this.value;return $(this).bind("keyup.clearId",function(){$(this).val().trim()!=j.trim()&&($($(this).attr("data-id-element")).val(""),$(this).unbind("keyup.clearId"))}),$(this).trigger("railsAutocomplete.select",d),!1}})}})}(jQuery)
@@ -8,7 +8,7 @@ module Autocomplete
8
8
  end
9
9
 
10
10
  def self.source_root
11
- File.join(File.dirname(__FILE__), '..', 'templates')
11
+ File.join(File.dirname(__FILE__), '..', '..', 'assets', 'javascripts')
12
12
  end
13
13
  end
14
14
  end
@@ -8,7 +8,7 @@ module Autocomplete
8
8
  end
9
9
 
10
10
  def self.source_root
11
- File.join(File.dirname(__FILE__), '..', 'templates')
11
+ File.join(File.dirname(__FILE__), '..', '..', 'assets', 'javascripts')
12
12
  end
13
13
  end
14
14
  end
@@ -4,6 +4,10 @@ require 'rails3-jquery-autocomplete/autocomplete'
4
4
  module Rails3JQueryAutocomplete
5
5
  autoload :Orm , 'rails3-jquery-autocomplete/orm'
6
6
  autoload :FormtasticPlugin , 'rails3-jquery-autocomplete/formtastic_plugin'
7
+
8
+ unless ::Rails.version < "3.1"
9
+ require 'rails3-jquery-autocomplete/rails/engine'
10
+ end
7
11
  end
8
12
 
9
13
  class ActionController::Base
@@ -22,7 +22,11 @@ module Rails3JQueryAutocomplete
22
22
  limit = get_autocomplete_limit(options)
23
23
  order = get_autocomplete_order(method, options)
24
24
 
25
- search = (is_full_search ? '.*' : '^') + term + '.*'
25
+ if is_full_search
26
+ search = '.*' + term + '.*'
27
+ else
28
+ search = '^' + term
29
+ end
26
30
  items = model.where(method.to_sym => /#{search}/i).limit(limit).order_by(order)
27
31
  end
28
32
  end
@@ -0,0 +1,5 @@
1
+ module Rails3JQueryAutocomplete
2
+ module Rails
3
+ class Engine < ::Rails::Engine ; end
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Rails3JQueryAutocomplete
2
- VERSION = '0.9.1'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -37,7 +37,7 @@ module Rails3JQueryAutocomplete
37
37
 
38
38
  context 'not a full search' do
39
39
  should 'do stuff' do
40
- mock(@model).where({:field=>/^query.*/i}).mock!.limit(10).
40
+ mock(@model).where({:field=>/^query/i}).mock!.limit(10).
41
41
  mock!.order_by([[:order, :asc]])
42
42
 
43
43
  get_autocomplete_items(@parameters)
data/test/test_helper.rb CHANGED
@@ -15,7 +15,7 @@ require 'rails/test_help'
15
15
  require 'rails3-jquery-autocomplete'
16
16
 
17
17
  module Rails3JQueryAutocomplete
18
- class Application < Rails::Application
18
+ class Application < ::Rails::Application
19
19
  end
20
20
  end
21
21
 
metadata CHANGED
@@ -1,171 +1,126 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rails3-jquery-autocomplete
3
- version: !ruby/object:Gem::Version
4
- hash: 57
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 9
9
- - 1
10
- version: 0.9.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - David Padilla
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-08-08 00:00:00 -06:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-09-20 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rails
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70272998070460 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 0
33
- version: "3.0"
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: sqlite3-ruby
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70272998070460
25
+ - !ruby/object:Gem::Dependency
26
+ name: sqlite3-ruby
27
+ requirement: &70272998069940 !ruby/object:Gem::Requirement
40
28
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 0
47
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
48
33
  type: :development
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: mongoid
52
34
  prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70272998069940
36
+ - !ruby/object:Gem::Dependency
37
+ name: mongoid
38
+ requirement: &70272998069320 !ruby/object:Gem::Requirement
54
39
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 15
59
- segments:
60
- - 2
61
- - 0
62
- - 0
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
63
43
  version: 2.0.0
64
44
  type: :development
65
- version_requirements: *id003
66
- - !ruby/object:Gem::Dependency
67
- name: mongo_mapper
68
45
  prerelease: false
69
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70272998069320
47
+ - !ruby/object:Gem::Dependency
48
+ name: mongo_mapper
49
+ requirement: &70272998068800 !ruby/object:Gem::Requirement
70
50
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 25
75
- segments:
76
- - 0
77
- - 9
78
- version: "0.9"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
79
55
  type: :development
80
- version_requirements: *id004
81
- - !ruby/object:Gem::Dependency
82
- name: bson_ext
83
56
  prerelease: false
84
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *70272998068800
58
+ - !ruby/object:Gem::Dependency
59
+ name: bson_ext
60
+ requirement: &70272998068200 !ruby/object:Gem::Requirement
85
61
  none: false
86
- requirements:
62
+ requirements:
87
63
  - - ~>
88
- - !ruby/object:Gem::Version
89
- hash: 27
90
- segments:
91
- - 1
92
- - 3
93
- - 0
64
+ - !ruby/object:Gem::Version
94
65
  version: 1.3.0
95
66
  type: :development
96
- version_requirements: *id005
97
- - !ruby/object:Gem::Dependency
98
- name: shoulda
99
67
  prerelease: false
100
- requirement: &id006 !ruby/object:Gem::Requirement
68
+ version_requirements: *70272998068200
69
+ - !ruby/object:Gem::Dependency
70
+ name: shoulda
71
+ requirement: &70272998067700 !ruby/object:Gem::Requirement
101
72
  none: false
102
- requirements:
73
+ requirements:
103
74
  - - ~>
104
- - !ruby/object:Gem::Version
105
- hash: 33
106
- segments:
107
- - 2
108
- - 11
109
- - 1
75
+ - !ruby/object:Gem::Version
110
76
  version: 2.11.1
111
77
  type: :development
112
- version_requirements: *id006
113
- - !ruby/object:Gem::Dependency
114
- name: uglifier
115
78
  prerelease: false
116
- requirement: &id007 !ruby/object:Gem::Requirement
79
+ version_requirements: *70272998067700
80
+ - !ruby/object:Gem::Dependency
81
+ name: uglifier
82
+ requirement: &70272998067300 !ruby/object:Gem::Requirement
117
83
  none: false
118
- requirements:
119
- - - ">="
120
- - !ruby/object:Gem::Version
121
- hash: 3
122
- segments:
123
- - 0
124
- version: "0"
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
125
88
  type: :development
126
- version_requirements: *id007
127
- - !ruby/object:Gem::Dependency
128
- name: rr
129
89
  prerelease: false
130
- requirement: &id008 !ruby/object:Gem::Requirement
90
+ version_requirements: *70272998067300
91
+ - !ruby/object:Gem::Dependency
92
+ name: rr
93
+ requirement: &70272998066840 !ruby/object:Gem::Requirement
131
94
  none: false
132
- requirements:
133
- - - ">="
134
- - !ruby/object:Gem::Version
135
- hash: 3
136
- segments:
137
- - 0
138
- version: "0"
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
139
99
  type: :development
140
- version_requirements: *id008
141
- - !ruby/object:Gem::Dependency
142
- name: rcov
143
100
  prerelease: false
144
- requirement: &id009 !ruby/object:Gem::Requirement
101
+ version_requirements: *70272998066840
102
+ - !ruby/object:Gem::Dependency
103
+ name: rcov
104
+ requirement: &70272998047460 !ruby/object:Gem::Requirement
145
105
  none: false
146
- requirements:
147
- - - ">="
148
- - !ruby/object:Gem::Version
149
- hash: 3
150
- segments:
151
- - 0
152
- version: "0"
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
153
110
  type: :development
154
- version_requirements: *id009
111
+ prerelease: false
112
+ version_requirements: *70272998047460
155
113
  description: Use jQuery's autocomplete plugin with Rails 3.
156
114
  email: david.padilla@crowdint.com
157
115
  executables: []
158
-
159
116
  extensions: []
160
-
161
117
  extra_rdoc_files: []
162
-
163
- files:
118
+ files:
119
+ - lib/assets/javascripts/autocomplete-rails-uncompressed.js
120
+ - lib/assets/javascripts/autocomplete-rails.js
164
121
  - lib/cucumber/autocomplete.rb
165
122
  - lib/generators/autocomplete/install_generator.rb
166
123
  - lib/generators/autocomplete/uncompressed_generator.rb
167
- - lib/generators/templates/autocomplete-rails-uncompressed.js
168
- - lib/generators/templates/autocomplete-rails.js
169
124
  - lib/rails3-jquery-autocomplete/autocomplete.rb
170
125
  - lib/rails3-jquery-autocomplete/form_helper.rb
171
126
  - lib/rails3-jquery-autocomplete/formtastic_plugin.rb
@@ -173,11 +128,12 @@ files:
173
128
  - lib/rails3-jquery-autocomplete/orm/mongo_mapper.rb
174
129
  - lib/rails3-jquery-autocomplete/orm/mongoid.rb
175
130
  - lib/rails3-jquery-autocomplete/orm.rb
131
+ - lib/rails3-jquery-autocomplete/rails/engine.rb
176
132
  - lib/rails3-jquery-autocomplete/simple_form_plugin.rb
177
133
  - lib/rails3-jquery-autocomplete/version.rb
178
134
  - lib/rails3-jquery-autocomplete.rb
179
135
  - lib/steak/autocomplete.rb
180
- - CHANGELOG.MD
136
+ - CHANGELOG.md
181
137
  - LICENSE
182
138
  - README.markdown
183
139
  - Rakefile
@@ -190,41 +146,31 @@ files:
190
146
  - test/lib/rails3-jquery-autocomplete/orm/mongoid_test.rb
191
147
  - test/lib/rails3-jquery-autocomplete_test.rb
192
148
  - test/test_helper.rb
193
- has_rdoc: true
194
149
  homepage: http://github.com/crowdint/rails3-jquery-autocomplete
195
150
  licenses: []
196
-
197
151
  post_install_message:
198
152
  rdoc_options: []
199
-
200
- require_paths:
153
+ require_paths:
201
154
  - lib
202
- required_ruby_version: !ruby/object:Gem::Requirement
155
+ required_ruby_version: !ruby/object:Gem::Requirement
203
156
  none: false
204
- requirements:
205
- - - ">="
206
- - !ruby/object:Gem::Version
207
- hash: 3
208
- segments:
209
- - 0
210
- version: "0"
211
- required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ! '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
212
162
  none: false
213
- requirements:
214
- - - ">="
215
- - !ruby/object:Gem::Version
216
- hash: 3
217
- segments:
218
- - 0
219
- version: "0"
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
220
167
  requirements: []
221
-
222
168
  rubyforge_project:
223
- rubygems_version: 1.3.7
169
+ rubygems_version: 1.8.6
224
170
  signing_key:
225
171
  specification_version: 3
226
172
  summary: Use jQuery's autocomplete plugin with Rails 3.
227
- test_files:
173
+ test_files:
228
174
  - test/form_helper_test.rb
229
175
  - test/generators/autocomplete/install_generator_test.rb
230
176
  - test/generators/autocomplete/uncompressed_generator_test.rb