auto_select2_tag 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7135570876f371fa423540127b4a28337230ef62
4
- data.tar.gz: 08d56515f4cb65d64f3e38166768aeb7e6a1445f
3
+ metadata.gz: 5764a48df80bed00b337ef2b0b43983d3c5d70b6
4
+ data.tar.gz: e64068435217dd57808436da0158305c2febec57
5
5
  SHA512:
6
- metadata.gz: 7114555077caa79911e48da5448ba5f3dfc69506afb87378f8825ec7fddd4038cb38b40bbfe2ef0f1171fdb188c185e0cd02aa1a819f0ec0203ca50e686106db
7
- data.tar.gz: c1e656be18e124c381ff027ce43e9638256ba3d3a272d7c46a73d34ff945e4194a233cdda6b5a2e1f34230da2bf55b84dbd3dd6ab84e0b20fd73a578cff960fe
6
+ metadata.gz: 65a88fb8c40000460e89624a7490ee3944954c0273c4f93a0bc5ad20597b7f643088d908a6c26e57d9a804a60c0bda4a3f067183126778511be634e82757518b
7
+ data.tar.gz: 9bc1ae2bd91e82f2217fb500afc3682e15892a61e50ecbc36ee190b3705f9636b411b0b3e8dc67cf7f7c4f56814b844fdb60fb04b07c3caee2d0b7a70b61667b
data/README.md CHANGED
@@ -15,6 +15,10 @@ And execute:
15
15
 
16
16
  $ bundle
17
17
 
18
+ ## Example
19
+
20
+ You can find example project [here](https://github.com/Loriowar/auto-select2_tag_example).
21
+
18
22
  ## Usage
19
23
 
20
24
  Gem provide only two helper methods for initialize select2 elements:
@@ -47,11 +51,14 @@ you can specify `:select2_options` in options. This parameter allow to set selec
47
51
  select2_ajax_tag(name, select2_searcher, value = nil, options = {})
48
52
 
49
53
  All allowed options for this helper can be found on
50
- [AutoSelect2](https://github.com/Loriowar/auto_select2#installation) page. look at example
54
+ [AutoSelect2](https://github.com/Loriowar/auto_select2#ajax-select2-usage) page. look at example
51
55
  below; this is an easy way to understand helper parameters.
52
56
 
53
57
  #### Example of usage select2_ajax_tag
54
58
 
59
+ If you define [SearchAdapter](https://github.com/Loriowar/auto_select2#example-of-minimalistic-searchadapter)
60
+ named `MySearchAdapterName`, you can use the follow code:
61
+
55
62
  = select2_ajax_tag :my_select2_name,
56
63
  :my_search_adapter_name,
57
64
  my_init_value_id,
@@ -60,6 +67,15 @@ below; this is an easy way to understand helper parameters.
60
67
  class: 'my-select2-input',
61
68
  select2_options: {additional_ajax_data: {selector: '.additional-elements'}}
62
69
 
70
+ If you want lightweight selection over columns of `ActiveRecord` model:
71
+
72
+ = select2_ajax_tag :my_select2_name,
73
+ {class_name: :your_model_name, text_column: :name, id_column: :id},
74
+ my_init_value_id,
75
+ placeholder: 'Fill me now!'
76
+
77
+ In this case you get select2 selent with search by `name` column over model `YourModelName`.
78
+
63
79
  ## Contributing
64
80
 
65
81
  1. Fork it ( http://github.com/Loriowar/auto_select2_tag/fork )
@@ -2,7 +2,11 @@ require 'auto_select2_tag/version'
2
2
  require 'auto_select2_tag/helpers'
3
3
 
4
4
  module AutoSelect2Tag
5
- class Engine < ::Rails::Engine
6
- # Get rails to add app, lib, vendor to load path
7
- end
5
+ # NOTE: redundant definition
6
+ # class Engine < ::Rails::Engine
7
+ # Get rails to add app, lib, vendor to load path
8
+ # initializer :autoload_auto_select2_tag_path do |app|
9
+ # app.config.autoload_paths << Rails.root.join('lib/auto_select2_tag')
10
+ # end
11
+ # end
8
12
  end
@@ -18,7 +18,15 @@ module AutoSelect2Tag
18
18
  original_data.merge!('s2options' => select2_options) if select2_options.present?
19
19
  search_method = options.delete(:search_method)
20
20
  classes = ['auto-ajax-select2', original_classes].compact.join(' ')
21
- controller_params = { class_name: select2_searcher }
21
+ controller_params = {}
22
+ if select2_searcher.is_a?(Hash)
23
+ # TODO: metaprogramming can help here
24
+ controller_params[:default_class_name] = select2_searcher[:class_name] if select2_searcher[:class_name].present?
25
+ controller_params[:default_text_column] = select2_searcher[:text_column] if select2_searcher[:text_column].present?
26
+ controller_params[:default_id_column] = select2_searcher[:id_column] if select2_searcher[:id_column].present?
27
+ else
28
+ controller_params[:class_name] = select2_searcher
29
+ end
22
30
  if search_method.present?
23
31
  controller_params.merge!({ search_method: search_method })
24
32
  end
@@ -26,6 +34,7 @@ module AutoSelect2Tag
26
34
  class: classes,
27
35
  data: original_data.merge(
28
36
  { href: select2_autocompletes_path(controller_params),
37
+ # TODO: move limit to config or delegate to SearchAdapter
29
38
  limit: limit.present? ? limit : 25 }
30
39
  )
31
40
  }
@@ -1,3 +1,3 @@
1
1
  module AutoSelect2Tag
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto_select2_tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Lisichkin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-26 00:00:00.000000000 Z
12
+ date: 2014-12-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties