filter_form 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/lib/filter_form/{inputs → input_options}/base.rb +10 -10
- data/lib/filter_form/{inputs → input_options}/select/base.rb +7 -3
- data/lib/filter_form/{inputs → input_options}/select/belongs_to.rb +3 -3
- data/lib/filter_form/{inputs → input_options}/string/base.rb +2 -2
- data/lib/filter_form/input_options/string/date.rb +13 -0
- data/lib/filter_form/{inputs → input_options}/string/money.rb +2 -2
- data/lib/filter_form/{input_builder.rb → input_options_builder.rb} +16 -13
- data/lib/filter_form/simple_form/form_builder.rb +7 -7
- data/lib/filter_form/version.rb +1 -1
- metadata +9 -10
- data/lib/filter_form/inputs/select/select2.rb +0 -9
- data/lib/filter_form/inputs/string/date.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72ec8aa3c0d7466d80687239848d0e71ac1091a4
|
4
|
+
data.tar.gz: d59e186f531264052324f54ad175fc5cc90a25a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ee9bd15ec95c1485d19f8e464a11647ddf35e0b307e77b1fcb67e4088da8c9a33b994424b21a11470aebc2f7cad8871bea64a0c1168eb915ae36fdd7dd02dc9
|
7
|
+
data.tar.gz: 4bebe228358abc58495d3bf955c7cf616d1ad69e21a65fe5205f049e96d10cba5d634f15f84ba3520308af331c4a3f611c85db681fa5ba6c9c4f5a760d206e6c
|
data/README.md
CHANGED
@@ -47,7 +47,6 @@ In your view file:
|
|
47
47
|
Mapping | Database Column Type | Default predicate | Generated HTML Element |
|
48
48
|
--------------- |:------------------------------------------------|:----------------------|:--------------------------|
|
49
49
|
`string` | `string` | `cont` | `input[type=text]` |
|
50
|
-
`select2` | `string` | `eq` | `select` |
|
51
50
|
`integer` | `integer` | `eq` | `input[type=text]` |
|
52
51
|
`datetime` | `datetime` | `eq` | `input[type=text]` |
|
53
52
|
`date` | `date` | `eq` | `input[type=text]` |
|
@@ -60,7 +59,7 @@ Of course you can customize your filter, like:
|
|
60
59
|
|
61
60
|
```erb
|
62
61
|
<%= filter_form_for @q do |f| %>
|
63
|
-
<%= f.filter_input :title, as: :select2 %>
|
62
|
+
<%= f.filter_input :title, as: :select, in: :select2 %>
|
64
63
|
<%= f.filter_input :year, as: :select, collection: (2000..2013).to_a, predicate: :not_eq %>
|
65
64
|
<%= f.button :submit %>
|
66
65
|
<% end %>
|
@@ -1,16 +1,12 @@
|
|
1
1
|
module FilterForm
|
2
|
-
module
|
2
|
+
module InputOptions
|
3
3
|
class Base
|
4
4
|
include ActiveModel::Model
|
5
5
|
|
6
|
-
|
6
|
+
attr_accessor :attribute_name, :object, :predicate, :options
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
def options
|
11
|
-
result = default_options.merge(additional_options)
|
12
|
-
result[:input_html].merge!(additional_input_options)
|
13
|
-
result
|
8
|
+
def simple_form_options
|
9
|
+
default_options.merge(additional_options).merge(options)
|
14
10
|
end
|
15
11
|
|
16
12
|
private
|
@@ -18,7 +14,7 @@ module FilterForm
|
|
18
14
|
def default_options
|
19
15
|
{
|
20
16
|
required: false,
|
21
|
-
input_html: { name: input_name }
|
17
|
+
input_html: { name: input_name }.merge(additional_input_options).merge(options.delete(:input_html) || {})
|
22
18
|
}
|
23
19
|
end
|
24
20
|
|
@@ -27,7 +23,11 @@ module FilterForm
|
|
27
23
|
end
|
28
24
|
|
29
25
|
def additional_input_options
|
30
|
-
{ class:
|
26
|
+
input_class ? { class: input_class } : {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def input_class
|
30
|
+
nil
|
31
31
|
end
|
32
32
|
|
33
33
|
def input_name
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module FilterForm
|
2
|
-
module
|
2
|
+
module InputOptions
|
3
3
|
module Select
|
4
|
-
class Base < FilterForm::
|
4
|
+
class Base < FilterForm::InputOptions::Base
|
5
5
|
private
|
6
6
|
|
7
7
|
def additional_options
|
@@ -14,7 +14,11 @@ module FilterForm
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def collection
|
17
|
-
object.klass.uniq.pluck(attribute_name)
|
17
|
+
options[:collection] || object.klass.uniq.pluck(attribute_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def input_class
|
21
|
+
options[:in] == :select2 ? 'filter_form_select2' : super
|
18
22
|
end
|
19
23
|
end
|
20
24
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module FilterForm
|
2
|
-
module
|
2
|
+
module InputOptions
|
3
3
|
module Select
|
4
|
-
class BelongsTo < FilterForm::
|
4
|
+
class BelongsTo < FilterForm::InputOptions::Select::Base
|
5
5
|
private
|
6
6
|
|
7
7
|
def object_condition
|
@@ -9,7 +9,7 @@ module FilterForm
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def collection
|
12
|
-
attribute_name.to_s.camelize.constantize.all
|
12
|
+
options[:collection] || attribute_name.to_s.camelize.constantize.all
|
13
13
|
end
|
14
14
|
|
15
15
|
def input_name
|
@@ -1,31 +1,34 @@
|
|
1
|
-
require 'filter_form/
|
1
|
+
require 'filter_form/input_options/base'
|
2
2
|
|
3
|
-
require 'filter_form/
|
4
|
-
require 'filter_form/
|
5
|
-
require 'filter_form/inputs/select/select2'
|
3
|
+
require 'filter_form/input_options/select/base'
|
4
|
+
require 'filter_form/input_options/select/belongs_to'
|
6
5
|
|
7
|
-
require 'filter_form/
|
8
|
-
require 'filter_form/
|
9
|
-
require 'filter_form/
|
6
|
+
require 'filter_form/input_options/string/base'
|
7
|
+
require 'filter_form/input_options/string/date'
|
8
|
+
require 'filter_form/input_options/string/money'
|
10
9
|
|
11
10
|
module FilterForm
|
12
|
-
class
|
11
|
+
class InputOptionsBuilder
|
13
12
|
include ActiveModel::Model
|
14
13
|
|
15
14
|
attr_accessor :attribute_name, :object, :custom_predicate, :custom_type
|
16
15
|
|
17
|
-
def build
|
18
|
-
|
16
|
+
def build(options)
|
17
|
+
input_options_class.new(attribute_name: attribute_name, object: object, predicate: predicate, options: options)
|
19
18
|
end
|
20
19
|
|
21
20
|
private
|
22
21
|
|
23
|
-
def
|
24
|
-
result = "
|
22
|
+
def input_options_class
|
23
|
+
result = constantize_input_options_class("#{ type }".camelize)
|
25
24
|
raise NameError if result.class == Module
|
26
25
|
result
|
27
26
|
rescue NameError
|
28
|
-
"
|
27
|
+
constantize_input_options_class("#{ type }/base".camelize)
|
28
|
+
end
|
29
|
+
|
30
|
+
def constantize_input_options_class(class_name)
|
31
|
+
"FilterForm::InputOptions::#{ class_name }".constantize
|
29
32
|
end
|
30
33
|
|
31
34
|
def predicate
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require 'filter_form/
|
1
|
+
require 'filter_form/input_options_builder'
|
2
2
|
|
3
3
|
module SimpleForm
|
4
4
|
class FormBuilder < ActionView::Helpers::FormBuilder
|
5
5
|
def filter_input(attribute_name, options = {}, &block)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
input_options_builder = FilterForm::InputOptionsBuilder.new attribute_name: attribute_name,
|
7
|
+
object: object,
|
8
|
+
custom_type: options.delete(:as),
|
9
|
+
custom_predicate: options.delete(:predicate)
|
10
10
|
|
11
|
-
|
11
|
+
filter_form_input_options = input_options_builder.build(options)
|
12
12
|
|
13
|
-
input(attribute_name,
|
13
|
+
input(attribute_name, filter_form_input_options.simple_form_options, &block)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
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.1
|
4
|
+
version: 0.2.1
|
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-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple_form
|
@@ -110,14 +110,13 @@ files:
|
|
110
110
|
- lib/assets/stylesheets/filter_form.css.sass
|
111
111
|
- lib/filter_form.rb
|
112
112
|
- lib/filter_form/form_helper.rb
|
113
|
-
- lib/filter_form/
|
114
|
-
- lib/filter_form/
|
115
|
-
- lib/filter_form/
|
116
|
-
- lib/filter_form/
|
117
|
-
- lib/filter_form/
|
118
|
-
- lib/filter_form/
|
119
|
-
- lib/filter_form/
|
120
|
-
- lib/filter_form/inputs/string/money.rb
|
113
|
+
- lib/filter_form/input_options/base.rb
|
114
|
+
- lib/filter_form/input_options/select/base.rb
|
115
|
+
- lib/filter_form/input_options/select/belongs_to.rb
|
116
|
+
- lib/filter_form/input_options/string/base.rb
|
117
|
+
- lib/filter_form/input_options/string/date.rb
|
118
|
+
- lib/filter_form/input_options/string/money.rb
|
119
|
+
- lib/filter_form/input_options_builder.rb
|
121
120
|
- lib/filter_form/ransack/search.rb
|
122
121
|
- lib/filter_form/simple_form/form_builder.rb
|
123
122
|
- lib/filter_form/version.rb
|