rails-jquery-autocomplete 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75f1d8fc10d956833a2e3c8bc8f55c08d9e6f0c1
4
- data.tar.gz: f33455b827bc5793fe83682250d40542636d9b18
3
+ metadata.gz: 5a1346b1232c8b075f528ed7febe0ad71acfe963
4
+ data.tar.gz: 8c520a4fd5310b32717974bc85631ae943187a55
5
5
  SHA512:
6
- metadata.gz: f64ae0807e77f728ae0f666650c6ee68e4ed0db2f44392058269e38407f51a31a90ad1e761a6f52328e0ae785f85aca45584c29d4f7c3ad05f9a9784e0095721
7
- data.tar.gz: ed1f836c1705b34c2811be92c0596dd498ffd1c17cd6fee6d98522500f2f5a1b59c3c3d9bf60df6bc7ecf4a055ca54878f01f3005c6fa40e46a2e69f77ec0cf1
6
+ metadata.gz: a8366b4f9a586efc35cafc47270bb0588f6f1e4083931c2ca8279a8e27ac35585c0f7b61a321f75d0521a3e0579e56b743903555e69c2541771dfba644ab4bed
7
+ data.tar.gz: e09d682607f6999ede171e01c69e4376554ea17e4bb3c4a6122fdb16e1325c93b6c2b7b98bfd36516e8e86650e8f27cf962f3c4c64c5ead617352f6bdada07e3
@@ -1,5 +1,7 @@
1
1
  # Changelog
2
2
 
3
+ * 1.0.3
4
+ * Fixes issue with SQLITE to support schemas
3
5
  * 1.0.2
4
6
  * Fixes compatibility with newer versions of Simple Form gem
5
7
  * Fixes issue of not propagating events and issue of selected value not a string
@@ -9,7 +11,7 @@
9
11
  * Option to enable/disable no matches found labeling
10
12
  * 1.0.0
11
13
  * Adds support for Rails 4
12
-
14
+
13
15
  ___
14
16
 
15
17
  Changes from here on are for the rails3-jquery-autocomplete gem release versions
data/README.md CHANGED
@@ -3,9 +3,7 @@
3
3
  1. This is the officially maintained fork of
4
4
  [rails3-jquery-autocomplete](http://github.com/crowdint/rails3-jquery-autocomplete)
5
5
  2. All new features and support of Rails 4 and above will occur here
6
- going forward. If you are still using Rails 3 please continue to use
7
- the previous fork. No new features will be added there, but bug fixes &
8
- security patches will continue until Rails 3 is EOL.
6
+ going forward. Rails 3 is also supported on this fork; bug fixes and security fixes for Rails 3 will continue until Rails 3 is EOL.
9
7
 
10
8
  # rails-jquery-autocomplete
11
9
 
@@ -89,21 +87,21 @@ Just add it to your app/assets/javascripts/application.js file
89
87
 
90
88
  ### Demo Application by [Yifei](https://github.com/yifeiwu)
91
89
 
92
- A live demo can be seen
90
+ A live demo can be seen
93
91
 
94
92
  [here](https://rocky-thicket-9286.herokuapp.com/)
95
93
 
96
94
  [source](https://github.com/yifeiwu/rails4-autocomplete-demo)
97
95
 
98
- As a new developer, I had some issues getting this to work by following the documentation. However after trying some things and reading [Yoni Weisbrod](http://www.yoniweisbrod.com/autocomplete-magic-with-rails/)'s blog post, I was able to make the autocomplete work and implement a few useful features.
96
+ As a new developer, I had some issues getting this to work by following the documentation. However after trying some things and reading [Yoni Weisbrod](http://www.yoniweisbrod.com/autocomplete-magic-with-rails/)'s blog post, I was able to make the autocomplete work and implement a few useful features.
99
97
 
100
98
  ##Some implemented features
101
99
 
102
- 1. The css has been changed such that the results show up better against the box of suggestions. See `<app/assets/stylesheets/food.scss>` for details. I obtained this from a gist(forgive me I don't remember who the author is at the moment, please contact me if you do and I'll give credit). Upon mouseover/arrowkey presses, the selection will be highlighted.
100
+ 1. The css has been changed such that the results show up better against the box of suggestions. See `<app/assets/stylesheets/food.scss>` for details. I obtained this from a gist(forgive me I don't remember who the author is at the moment, please contact me if you do and I'll give credit). Upon mouseover/arrowkey presses, the selection will be highlighted.
103
101
 
104
- 2. One Yoni's improvements, you can click on a suggested item to submit the search, instead of having to click on the submit button after clicking on the item. This is an example of how to hook onto the *railsAutocomplete.select* event.
102
+ 2. One Yoni's improvements, you can click on a suggested item to submit the search, instead of having to click on the submit button after clicking on the item. This is an example of how to hook onto the *railsAutocomplete.select* event.
105
103
 
106
- 3. The autocomplete is implemented in the context of a search form with a simple scope search(see the food model and controller).
104
+ 3. The autocomplete is implemented in the context of a search form with a simple scope search(see the food model and controller).
107
105
 
108
106
  ### Model Example
109
107
 
@@ -130,7 +128,7 @@ This will create an action _autocomplete_brand_name_ on your controller, don't f
130
128
  resources :products do
131
129
  get :autocomplete_brand_name, :on => :collection
132
130
  end
133
-
131
+
134
132
  Verify this path using `rake routes`, you will need it later for the **view** section.
135
133
 
136
134
  ### Options
@@ -194,27 +192,30 @@ Only the object's id and the column you are searching on will be returned in JSO
194
192
 
195
193
  #### :hstore
196
194
 
197
- Added option to support searching in hstore columns.
195
+ Added option to support searching in hstore columns.
198
196
 
199
- Pass a hash with two keys: `:method` and `:key` with values: the hstore field name and the key of the hstore to search.
197
+ Pass a hash with two keys: `:method` and `:key` with values: the hstore field name and the key of the hstore to search.
200
198
 
201
- e.g `autocomplete :feature, :name, :hstore => {:method => 'name_translations', :key => 'en'}`
199
+ e.g `autocomplete :feature, :name, :hstore => {:method => 'name_translations', :key => 'en'}`
202
200
 
203
201
 
204
202
  #### :scopes
205
- Added option to use scopes. Pass scopes in an array.
206
- e.g `:scopes => [:scope1, :scope2]`
203
+
204
+ Added option to use scopes. Pass scopes in an array.
205
+ e.g `:scopes => [:scope1, :scope2]`
207
206
 
208
207
  #### :column_name
209
- By default autocomplete uses method name as column name. Now it can be specified using column_name options
210
- `:column_name => 'name'`
208
+
209
+ By default autocomplete uses method name as column name. Now it can be specified using column_name options
210
+ `:column_name => 'name'`
211
211
 
212
212
  #### json encoder
213
+
213
214
  Autocomplete uses Yajl as JSON encoder/decoder, but you can specify your own
214
215
 
215
216
  class ProductsController < Admin::BaseController
216
217
  autocomplete :brand, :name do |items|
217
- CustomJSON::Encoder.encode(items)
218
+ CustomJSON::Encoder.encode(items)
218
219
  end
219
220
  end
220
221
 
@@ -253,10 +254,10 @@ NOTE: Setting the `:multiple` option to `true` will result in the chosen values
253
254
 
254
255
  To have the first item be automatically focused on when the autocomplete menu is shown, add the `'data-auto-focus'` option and set it to `true`.
255
256
 
256
- form_for @product do |f|
257
- f.autocomplete_field :brand_names, autocomplete_brand_name_products_path,
258
- 'data-auto-focus' => true
259
- end
257
+ form_for @product do |f|
258
+ f.autocomplete_field :brand_names, autocomplete_brand_name_products_path,
259
+ 'data-auto-focus' => true
260
+ end
260
261
 
261
262
  Now your autocomplete code is unobtrusive, Rails style.
262
263
 
@@ -269,10 +270,10 @@ To configure the behaviour if no matches are found, you can set the following op
269
270
 
270
271
  These will change the behaviour globally. To set them on a single input field use:
271
272
 
272
- f.autocomplete_field :brand_names, autocomplete_brand_name_products_path,
273
+ f.autocomplete_field :brand_names, autocomplete_brand_name_products_path,
273
274
  'data-showNoMatches' => false
274
275
  #or
275
- f.autocomplete_field :brand_names, autocomplete_brand_name_products_path,
276
+ f.autocomplete_field :brand_names, autocomplete_brand_name_products_path,
276
277
  'data-noMatchesLabel' => 'no brands found'
277
278
 
278
279
 
@@ -469,10 +470,3 @@ the future. Thanks!
469
470
 
470
471
  Everyone on [this list](https://github.com/crowdint/rails3-jquery-autocomplete/contributors)
471
472
 
472
- # About the Author
473
-
474
- [Crowd Interactive](http://www.crowdint.com) is an American web design and development company that happens to work in Colima, Mexico.
475
- We specialize in building and growing online retail stores. We don’t work with everyone – just companies we believe in. Call us today to see if there’s a fit.
476
- Find more info [here](http://www.crowdint.com)!
477
-
478
-
@@ -5,7 +5,11 @@ module RailsJQueryAutocomplete
5
5
  order = options[:order]
6
6
 
7
7
  table_prefix = model ? "#{model.table_name}." : ""
8
- order || "LOWER(#{table_prefix}#{method}) ASC"
8
+ if sqlite?
9
+ order || "LOWER(#{method}) ASC"
10
+ else
11
+ order || "LOWER(#{table_prefix}#{method}) ASC"
12
+ end
9
13
  end
10
14
 
11
15
  def active_record_get_autocomplete_items(parameters)
@@ -18,7 +22,6 @@ module RailsJQueryAutocomplete
18
22
  limit = get_autocomplete_limit(options)
19
23
  order = active_record_get_autocomplete_order(method, options, model)
20
24
 
21
-
22
25
  items = (::Rails::VERSION::MAJOR * 10 + ::Rails::VERSION::MINOR) >= 40 ? model.where(nil) : model.scoped
23
26
 
24
27
  scopes.each { |scope| items = items.send(scope) } unless scopes.empty?
@@ -32,8 +35,16 @@ module RailsJQueryAutocomplete
32
35
  end
33
36
 
34
37
  def get_autocomplete_select_clause(model, method, options)
35
- table_name = model.table_name
36
- (["#{table_name}.#{model.primary_key}", "#{table_name}.#{method}"] + (options[:extra_data].blank? ? [] : options[:extra_data]))
38
+ if sqlite?
39
+ table_name = model.quoted_table_name
40
+ ([
41
+ "#{table_name}.#{model.connection.quote_column_name(model.primary_key)} as #{model.primary_key}",
42
+ "#{table_name}.#{model.connection.quote_column_name(method)} as #{method}"
43
+ ] + (options[:extra_data].blank? ? [] : options[:extra_data]))
44
+ else
45
+ table_name = model.table_name
46
+ (["#{table_name}.#{model.primary_key}", "#{table_name}.#{method}"] + (options[:extra_data].blank? ? [] : options[:extra_data]))
47
+ end
37
48
  end
38
49
 
39
50
  def get_autocomplete_where_clause(model, term, method, options)
@@ -42,15 +53,28 @@ module RailsJQueryAutocomplete
42
53
  like_clause = (postgres?(model) ? 'ILIKE' : 'LIKE')
43
54
  if options[:hstore]
44
55
  ["LOWER(#{table_name}.#{method} -> '#{options[:hstore][:key]}') LIKE ?", "#{(is_full_search ? '%' : '')}#{term.downcase}%"]
56
+ elsif sqlite?
57
+ ["LOWER(#{method}) #{like_clause} ?", "#{(is_full_search ? '%' : '')}#{term.downcase}%"]
45
58
  else
46
59
  ["LOWER(#{table_name}.#{method}) #{like_clause} ?", "#{(is_full_search ? '%' : '')}#{term.downcase}%"]
47
60
  end
48
61
  end
49
62
 
50
- def postgres?(model)
51
- # Figure out if this particular model uses the PostgreSQL adapter
52
- model.connection.class.to_s.match(/PostgreSQLAdapter/)
53
- end
63
+ protected
64
+
65
+ def sqlite?
66
+ begin
67
+ return ::ActiveRecord::Base.connection.to_s.match(/SQLite/)
68
+ rescue ::ActiveRecord::ConnectionNotEstablished
69
+ return false
70
+ end
71
+ return false
72
+ end
73
+
74
+ def postgres?(model)
75
+ # Figure out if this particular model uses the PostgreSQL adapter
76
+ model.connection.class.to_s.match(/PostgreSQLAdapter/)
77
+ end
54
78
  end
55
79
  end
56
80
  end
@@ -1,3 +1,3 @@
1
1
  module RailsJQueryAutocomplete
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-jquery-autocomplete
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Padilla
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-08-19 00:00:00.000000000 Z
13
+ date: 2015-10-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -180,8 +180,22 @@ dependencies:
180
180
  - - "~>"
181
181
  - !ruby/object:Gem::Version
182
182
  version: '1.5'
183
+ - !ruby/object:Gem::Dependency
184
+ name: byebug
185
+ requirement: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ type: :development
191
+ prerelease: false
192
+ version_requirements: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
183
197
  description: Use jQuery's autocomplete plugin with Rails 4+.
184
- email: david.padilla@crowdint.com joiey.seeley@gmail.com sundusahmedyousuf@gmail.com
198
+ email: david@padilla.cc joiey.seeley@gmail.com sundusahmedyousuf@gmail.com
185
199
  executables: []
186
200
  extensions: []
187
201
  extra_rdoc_files: []
@@ -239,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
253
  version: '0'
240
254
  requirements: []
241
255
  rubyforge_project:
242
- rubygems_version: 2.4.6
256
+ rubygems_version: 2.4.5.1
243
257
  signing_key:
244
258
  specification_version: 4
245
259
  summary: Use jQuery's autocomplete plugin with Rails 4+.