filter_form 0.0.5 → 0.0.6

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: 0aef1584f174e74d19da2a06e479a5bfb6ca9c2c
4
- data.tar.gz: 5173a78a306554918eab38acfd79799439f49d92
3
+ metadata.gz: 7a7c1d58fb2ba9912bb9c2c660473c86ccef6b15
4
+ data.tar.gz: 3eb6fb9a2b37a54faf157db67bc20ebaeb8dbad8
5
5
  SHA512:
6
- metadata.gz: ea6408cc040d3030b60ca0312ed9b645559827f44723b367d94d29d53725fd9fd121726bfa53b644ce1fe75e7cbf1f103bc6f6a076bf057edff9c6491a5b8f70
7
- data.tar.gz: 95fcbab79211432aeb981dd8c147a947043d17340e1554151ed28fa0808241a7d046f65202d9f346f03cbdd2eb6eb46205c0fafe00177c054ba9e226a2343c18
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
- For `integer` type (age) it will set predicate `eq`.
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
- And also you can customize your filter, like:
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/belongs_to_eq'
4
+ require 'filter_form/inputs/select/belongs_to'
5
5
 
6
6
  require 'filter_form/inputs/string/base'
7
- require 'filter_form/inputs/string/string_cont'
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, :options
13
+ attr_accessor :attribute_name, :object, :custom_predicate, :custom_type
16
14
 
17
15
  def build
18
- "FilterForm::Inputs::#{ input_type.camelize }".constantize.new attribute_name: attribute_name,
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 input_type
26
- if options[:as]
27
- "#{ options[:as] }/base"
28
- else
29
- "#{ type }_#{ predicate }"
30
- end
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
- 'string/string'
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 }_#{ predicate_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
@@ -1,7 +1,7 @@
1
1
  module FilterForm
2
2
  module Inputs
3
3
  module Select
4
- class BelongsToEq < FilterForm::Inputs::Select::Base
4
+ class BelongsTo < FilterForm::Inputs::Select::Base
5
5
  private
6
6
 
7
7
  def object_condition
@@ -1,7 +1,7 @@
1
1
  module FilterForm
2
2
  module Inputs
3
3
  module String
4
- class DateEq < FilterForm::Inputs::String::Base
4
+ class Date < FilterForm::Inputs::String::Base
5
5
  DATE_CLASS = 'filter_form_date'
6
6
 
7
7
  private
@@ -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
- filter_form_input = FilterForm::InputBuilder.new(attribute_name: attribute_name, options: options, object: object).build
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!(filter_form_input.options)
11
+ options.reverse_merge!(input_builder.build.options)
9
12
 
10
13
  input(attribute_name, options, &block)
11
14
  end
@@ -1,3 +1,3 @@
1
1
  module FilterForm
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
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.5
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-07 00:00:00.000000000 Z
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/belongs_to_eq.rb
101
+ - lib/filter_form/inputs/select/belongs_to.rb
102
102
  - lib/filter_form/inputs/string/base.rb
103
- - lib/filter_form/inputs/string/date_eq.rb
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
@@ -1,8 +0,0 @@
1
- module FilterForm
2
- module Inputs
3
- module String
4
- class IntegerEq < FilterForm::Inputs::String::Base
5
- end
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module FilterForm
2
- module Inputs
3
- module String
4
- class StringCont < FilterForm::Inputs::String::Base
5
- end
6
- end
7
- end
8
- end