filter_form 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7dcaf4e227c17f563b101cefe9a484d9fd066d48
4
- data.tar.gz: 7bdd04c0838a27f3e04789a51de8b73e0d4b3d80
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWYwNGI3ZjY3OGZhZDIxOGQ5Mzc1N2QxMTBlYWQ2NmUwMTZiMWM0ZQ==
5
+ data.tar.gz: !binary |-
6
+ YjlhZjZmNDZmYmNjM2QzMDM0OTE1ZGQzMzkwZDg0NzMxNWY1N2NiMg==
5
7
  SHA512:
6
- metadata.gz: 2f17dca9f965ebf77df3b5b2c7cbb6982cd706e0f41f20573d24c0076aba27896f769124aefac747d9ff03e401a0d2fb4f5c82a1938fdbaeb175f7c427c0dee7
7
- data.tar.gz: ccfbb999edd00621a83ff4e968816572cbab2667ef9c40c340f6205b78ad0568de7e8e305b88963442c1b5e08d2669c1cd23a28b9aef2938b24531933ec82310
8
+ metadata.gz: !binary |-
9
+ Y2UzNTJiYjMyM2Y2Y2E4MTAxZWNlYTllZmQ5Y2E5YjRiZjI0NThmZTFiMTZl
10
+ YzkxOGIxY2U4MzY0ZGE1MjhkZTYyODJiYTg3MDVjZDQ0ZTQ5NmU2NmYwZGM2
11
+ NzNmOTlmMGE1OGNiMTgyNDhkYjAzZjQ3MDcxMDRiMmQ5NDA4MDU=
12
+ data.tar.gz: !binary |-
13
+ MDBkYjkxYTJiNjhmNjJkOTYyZDZkOGUyMTQzNGI4ZDk1YzcxNTNmMjZhZTNk
14
+ ZTk5MzgzNThiZjJiM2FiOWRmZjliYzhlZWQ2ZmQxNzE0ZTQwYTI2NTg1ODI5
15
+ Nzk5YjhmZDRhYjZmODE0ZTAzNTc4ZjczMjU4N2Q2ODA4NDA5M2U=
data/README.md CHANGED
@@ -40,6 +40,7 @@ In your view file:
40
40
  <%= f.filter_input :city # belongs_to %>
41
41
  <%= f.filter_input :parents # has_many %>
42
42
  <%= f.filter_input :amount # money %>
43
+ <%= f.filter_input :gender, as: :check_boxes, collection: [[:male, 'Male'], [:female, 'Female']] # checkboxes %>
43
44
  <%= f.button :submit %>
44
45
  <% end %>
45
46
  ```
@@ -56,8 +57,9 @@ In your view file:
56
57
  `decimal` | `decimal` | `eq` | `input[type="number"]` |
57
58
  `date` | `date` | `eq` | `input[type="text"]` |
58
59
  `datetime` | `datetime` | `eq` | `input[type="text"]` |
59
- `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations | `eq` | `select` |
60
- `money` | `money` [monetized](https://github.com/RubyMoney/money-rails) attribute | `eq` | `input[type="number"]` |
60
+ `select` | `belongs_to`/`has_many`/`has_and_belongs_to_many` associations | `eq` | `select` |
61
+ `money` | [monetized](https://github.com/RubyMoney/money-rails) attribute | `eq` | `input[type="number"]` |
62
+ `check_boxes` | `any' | `in` | `input[type=checkbox]` |
61
63
 
62
64
  ### Customization
63
65
 
@@ -0,0 +1,20 @@
1
+ module FilterForm
2
+ module InputOptions
3
+ module Boolean
4
+ class Base < FilterForm::InputOptions::Base
5
+ DEFAULT_PREDICATE = :true
6
+
7
+ private
8
+
9
+ def additional_options
10
+ { as: :boolean }
11
+ end
12
+
13
+ def additional_input_options
14
+ super.merge(checked: !!input_value)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
@@ -2,19 +2,19 @@ module FilterForm
2
2
  module InputOptions
3
3
  module Checkbox
4
4
  class Base < FilterForm::InputOptions::Base
5
- DEFAULT_PREDICATE = :true
5
+ include FilterForm::InputOptions::Shared::WithAssociations
6
+
7
+ DEFAULT_PREDICATE = :in
6
8
 
7
9
  private
8
10
 
9
11
  def additional_options
10
- { as: :boolean }
11
- end
12
-
13
- def additional_input_options
14
- super.merge(checked: !!input_value)
12
+ {
13
+ as: :check_boxes,
14
+ collection: collection
15
+ }
15
16
  end
16
17
  end
17
18
  end
18
19
  end
19
20
  end
20
-
@@ -2,6 +2,8 @@ module FilterForm
2
2
  module InputOptions
3
3
  module Select
4
4
  class Base < FilterForm::InputOptions::Base
5
+ include FilterForm::InputOptions::Shared::WithAssociations
6
+
5
7
  DEFAULT_PREDICATE = :eq
6
8
 
7
9
  private
@@ -15,18 +17,6 @@ module FilterForm
15
17
  }
16
18
  end
17
19
 
18
- def collection
19
- if options[:collection]
20
- options[:collection]
21
- elsif belongs_to?
22
- attribute_name.to_s.camelize.constantize.all
23
- elsif collection?
24
- attribute_name.to_s.camelize.singularize.constantize.all
25
- else
26
- object.klass.uniq.pluck(attribute_name)
27
- end
28
- end
29
-
30
20
  def input_attribute_name
31
21
  if association
32
22
  "#{ attribute_name }_id"
@@ -42,18 +32,6 @@ module FilterForm
42
32
  super
43
33
  end
44
34
  end
45
-
46
- def association
47
- object.klass.reflections[attribute_name]
48
- end
49
-
50
- def belongs_to?
51
- association && association.belongs_to?
52
- end
53
-
54
- def collection?
55
- association && association.collection?
56
- end
57
35
  end
58
36
  end
59
37
  end
@@ -0,0 +1,31 @@
1
+ module FilterForm
2
+ module InputOptions
3
+ module Shared
4
+ module WithAssociations
5
+ def collection
6
+ if options[:collection]
7
+ options[:collection]
8
+ elsif belongs_to?
9
+ attribute_name.to_s.camelize.constantize.all
10
+ elsif collection?
11
+ attribute_name.to_s.camelize.singularize.constantize.all
12
+ else
13
+ object.klass.uniq.pluck(attribute_name)
14
+ end
15
+ end
16
+
17
+ def association
18
+ object.klass.reflections[attribute_name]
19
+ end
20
+
21
+ def belongs_to?
22
+ association && association.belongs_to?
23
+ end
24
+
25
+ def collection?
26
+ association && association.collection?
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,4 +1,5 @@
1
1
  require 'filter_form/input_options/base'
2
+ require 'filter_form/input_options/shared/with_associations'
2
3
 
3
4
  require 'filter_form/input_options/select/base'
4
5
 
@@ -8,6 +9,8 @@ require 'filter_form/input_options/string/date'
8
9
  require 'filter_form/input_options/number/base'
9
10
  require 'filter_form/input_options/number/money'
10
11
 
12
+ require 'filter_form/input_options/boolean/base'
13
+
11
14
  require 'filter_form/input_options/checkbox/base'
12
15
 
13
16
  module FilterForm
@@ -51,6 +54,8 @@ module FilterForm
51
54
  when :select2
52
55
  'select/select2'
53
56
  when :boolean
57
+ 'boolean/base'
58
+ when :check_boxes
54
59
  'checkbox/base'
55
60
  else
56
61
  _type
@@ -1,3 +1,3 @@
1
1
  module FilterForm
2
- VERSION = '0.7.1'
2
+ VERSION = '0.7.2'
3
3
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filter_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeny Li
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-29 00:00:00.000000000 Z
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: simple_form
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ransack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: jquery-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: select2-rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
@@ -84,14 +84,14 @@ dependencies:
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ! '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ! '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: Build filter forms easily
@@ -111,10 +111,12 @@ files:
111
111
  - lib/filter_form.rb
112
112
  - lib/filter_form/form_helper.rb
113
113
  - lib/filter_form/input_options/base.rb
114
+ - lib/filter_form/input_options/boolean/base.rb
114
115
  - lib/filter_form/input_options/checkbox/base.rb
115
116
  - lib/filter_form/input_options/number/base.rb
116
117
  - lib/filter_form/input_options/number/money.rb
117
118
  - lib/filter_form/input_options/select/base.rb
119
+ - lib/filter_form/input_options/shared/with_associations.rb
118
120
  - lib/filter_form/input_options/string/base.rb
119
121
  - lib/filter_form/input_options/string/date.rb
120
122
  - lib/filter_form/input_options_builder.rb
@@ -131,18 +133,19 @@ require_paths:
131
133
  - lib
132
134
  required_ruby_version: !ruby/object:Gem::Requirement
133
135
  requirements:
134
- - - '>='
136
+ - - ! '>='
135
137
  - !ruby/object:Gem::Version
136
138
  version: '0'
137
139
  required_rubygems_version: !ruby/object:Gem::Requirement
138
140
  requirements:
139
- - - '>='
141
+ - - ! '>='
140
142
  - !ruby/object:Gem::Version
141
143
  version: '0'
142
144
  requirements: []
143
145
  rubyforge_project:
144
- rubygems_version: 2.0.3
146
+ rubygems_version: 2.1.5
145
147
  signing_key:
146
148
  specification_version: 4
147
149
  summary: Build your filter forms automatically
148
150
  test_files: []
151
+ has_rdoc: