filter_form 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -10
- data/lib/filter_form/input_builder.rb +16 -18
- data/lib/filter_form/inputs/base.rb +1 -5
- data/lib/filter_form/inputs/select/{belongs_to_eq.rb → belongs_to.rb} +1 -1
- data/lib/filter_form/inputs/string/{date_eq.rb → date.rb} +1 -1
- data/lib/filter_form/simple_form/form_builder.rb +5 -2
- data/lib/filter_form/version.rb +1 -1
- metadata +4 -6
- data/lib/filter_form/inputs/string/integer_eq.rb +0 -8
- data/lib/filter_form/inputs/string/string_cont.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a7c1d58fb2ba9912bb9c2c660473c86ccef6b15
|
4
|
+
data.tar.gz: 3eb6fb9a2b37a54faf157db67bc20ebaeb8dbad8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eefd55897f30e589ec381a3adc540f3a866c9e38b6bed0a1313e35e746533fe736905ff20da89a99caf4b7bb766d13065f97f4daa963a360869a66885685872e
|
7
|
+
data.tar.gz: 075413fb4d0ba0084573ca482b628fb00a7ffeb394374610f0bf6f3ec12a682079de7a63dcd7ee578faf61c9d655fdfbe563f350541896f9ba6fefabd7817e59
|
data/README.md
CHANGED
@@ -41,15 +41,12 @@ In your view file:
|
|
41
41
|
<% end %>
|
42
42
|
```
|
43
43
|
|
44
|
-
For `string` attribute (like name) it will automatically create a text input with predicate `cont` (contains).
|
44
|
+
* For `string` attribute (like name) it will automatically create a text input with predicate `cont` (contains).
|
45
|
+
* For `integer` type (age) it will set predicate `eq`.
|
46
|
+
* For association `belongs_to` (city) it will automatically build a select tag with `eq`.
|
47
|
+
* For `date` and `datetime` (birthday) it will automatically add jQuery [datepicker](http://jqueryui.com/datepicker/) and set predicate `eq`.
|
45
48
|
|
46
|
-
|
47
|
-
|
48
|
-
For association `belongs_to` (city) it will automatically build a select tag.
|
49
|
-
|
50
|
-
For `date` and `datetime` (birthday) it will automatically add jQuery [datepicker](http://jqueryui.com/datepicker/) and set predicate `eq`.
|
51
|
-
|
52
|
-
If you want to use datepicker add to your application.js file:
|
49
|
+
To use datepicker add to your application.js file:
|
53
50
|
|
54
51
|
```js
|
55
52
|
//= require jquery
|
@@ -63,7 +60,7 @@ And application.css:
|
|
63
60
|
*= require jquery.ui.datepicker
|
64
61
|
```
|
65
62
|
|
66
|
-
|
63
|
+
Of course you can customize your filter, like:
|
67
64
|
|
68
65
|
```erb
|
69
66
|
<%= filter_form_for @q do |f| %>
|
@@ -72,7 +69,6 @@ And also you can customize your filter, like:
|
|
72
69
|
<% end %>
|
73
70
|
```
|
74
71
|
|
75
|
-
|
76
72
|
For more information about predicates visit [ransack](https://github.com/ernie/ransack).
|
77
73
|
|
78
74
|
If you want to customize your form visit [simple_form](https://github.com/plataformatec/simple_form).
|
@@ -1,36 +1,34 @@
|
|
1
1
|
require 'filter_form/inputs/base'
|
2
2
|
|
3
3
|
require 'filter_form/inputs/select/base'
|
4
|
-
require 'filter_form/inputs/select/
|
4
|
+
require 'filter_form/inputs/select/belongs_to'
|
5
5
|
|
6
6
|
require 'filter_form/inputs/string/base'
|
7
|
-
require 'filter_form/inputs/string/
|
8
|
-
require 'filter_form/inputs/string/integer_eq'
|
9
|
-
require 'filter_form/inputs/string/date_eq'
|
7
|
+
require 'filter_form/inputs/string/date'
|
10
8
|
|
11
9
|
module FilterForm
|
12
10
|
class InputBuilder
|
13
11
|
include ActiveModel::Model
|
14
12
|
|
15
|
-
attr_accessor :attribute_name, :object, :
|
13
|
+
attr_accessor :attribute_name, :object, :custom_predicate, :custom_type
|
16
14
|
|
17
15
|
def build
|
18
|
-
|
19
|
-
object: object,
|
20
|
-
predicate: options[:predicate]
|
16
|
+
input_class.new(attribute_name: attribute_name, object: object, predicate: predicate)
|
21
17
|
end
|
22
18
|
|
23
19
|
private
|
24
20
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
21
|
+
def input_class
|
22
|
+
result = "FilterForm::Inputs::#{ "#{ type }".camelize }".constantize
|
23
|
+
raise NameError if result.class == Module
|
24
|
+
result
|
25
|
+
rescue NameError
|
26
|
+
"FilterForm::Inputs::#{ "#{ type }/base".camelize }".constantize
|
31
27
|
end
|
32
28
|
|
33
29
|
def predicate
|
30
|
+
return custom_predicate if custom_predicate
|
31
|
+
|
34
32
|
case attribute_type
|
35
33
|
when :string
|
36
34
|
:cont
|
@@ -40,11 +38,11 @@ module FilterForm
|
|
40
38
|
end
|
41
39
|
|
42
40
|
def type
|
41
|
+
return custom_type if custom_type
|
42
|
+
|
43
43
|
case attribute_type
|
44
|
-
when :string
|
45
|
-
|
46
|
-
when :integer
|
47
|
-
'string/integer'
|
44
|
+
when :string, :integer
|
45
|
+
:string
|
48
46
|
when :datetime, :date
|
49
47
|
'string/date'
|
50
48
|
when :belongs_to
|
@@ -15,17 +15,13 @@ module FilterForm
|
|
15
15
|
private
|
16
16
|
|
17
17
|
def input_name
|
18
|
-
"q[#{ attribute_name }_#{
|
18
|
+
"q[#{ attribute_name }_#{ predicate }]"
|
19
19
|
end
|
20
20
|
|
21
21
|
def input_value
|
22
22
|
object_condition.values.first.value if object_condition
|
23
23
|
end
|
24
24
|
|
25
|
-
def predicate_name
|
26
|
-
predicate || self.class.to_s.underscore.split('_').last
|
27
|
-
end
|
28
|
-
|
29
25
|
def object_condition
|
30
26
|
object.base.conditions.select { |c| c.a.first.name == attribute_name.to_s }.first
|
31
27
|
end
|
@@ -3,9 +3,12 @@ require 'filter_form/input_builder'
|
|
3
3
|
module SimpleForm
|
4
4
|
class FormBuilder < ActionView::Helpers::FormBuilder
|
5
5
|
def filter_input(attribute_name, options = {}, &block)
|
6
|
-
|
6
|
+
input_builder = FilterForm::InputBuilder.new attribute_name: attribute_name,
|
7
|
+
object: object,
|
8
|
+
custom_type: options[:as],
|
9
|
+
custom_predicate: options[:predicate]
|
7
10
|
|
8
|
-
options.reverse_merge!(
|
11
|
+
options.reverse_merge!(input_builder.build.options)
|
9
12
|
|
10
13
|
input(attribute_name, options, &block)
|
11
14
|
end
|
data/lib/filter_form/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filter_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
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-
|
11
|
+
date: 2013-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jquery-rails
|
@@ -98,11 +98,9 @@ files:
|
|
98
98
|
- lib/filter_form/input_builder.rb
|
99
99
|
- lib/filter_form/inputs/base.rb
|
100
100
|
- lib/filter_form/inputs/select/base.rb
|
101
|
-
- lib/filter_form/inputs/select/
|
101
|
+
- lib/filter_form/inputs/select/belongs_to.rb
|
102
102
|
- lib/filter_form/inputs/string/base.rb
|
103
|
-
- lib/filter_form/inputs/string/
|
104
|
-
- lib/filter_form/inputs/string/integer_eq.rb
|
105
|
-
- lib/filter_form/inputs/string/string_cont.rb
|
103
|
+
- lib/filter_form/inputs/string/date.rb
|
106
104
|
- lib/filter_form/simple_form/form_builder.rb
|
107
105
|
- lib/filter_form/version.rb
|
108
106
|
homepage: https://github.com/exAspArk/filter_form
|