simple_form_ransack 0.0.17 → 0.0.21
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 +5 -5
- data/README.md +60 -0
- data/lib/simple_form_ransack/attribute_inspector.rb +4 -0
- data/lib/simple_form_ransack/form_proxy.rb +3 -1
- data/lib/simple_form_ransack/input_manipulator.rb +8 -4
- data/lib/simple_form_ransack/version.rb +1 -1
- data/lib/simple_form_ransack.rb +5 -1
- metadata +44 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7541a435186f0cdaf1e54ef693cca47a72280821cb776d40f3f1cdc5194b2085
|
4
|
+
data.tar.gz: 4c64863709a3833f46602c16c4e44bbaaccfacfd7b4affc07e47b162f34abdb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 394d9db741220ab6b56e3d99ed52608c1ebb761102c654be65a65ada0369954ce738ff76ea4d7c57af8ac20c4a740f60ba3e8217ab6bdd09174d829cd4a92c32
|
7
|
+
data.tar.gz: b68f041a36cbff3502b663d85ad86230363ba18d52eecaae9d7f12fc459447a83f732d1df4e23631bbb72cd3d0574b156374f783854294c5cf3e2049ffadf7c5
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# SimpleFormRansack
|
2
|
+
|
3
|
+
SimpleForm and Ransack combined.
|
4
|
+
|
5
|
+
|
6
|
+
# Installation
|
7
|
+
|
8
|
+
In your Gemfile:
|
9
|
+
```ruby
|
10
|
+
gem 'simple_form_ransack'
|
11
|
+
```
|
12
|
+
|
13
|
+
In your ApplicationHlper:
|
14
|
+
```ruby
|
15
|
+
module ApplicationHelper
|
16
|
+
include SimpleFormRansackHelper
|
17
|
+
...
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
In "application.rb" (for translations):
|
22
|
+
```ruby
|
23
|
+
class Application
|
24
|
+
# It's important that available locales is defined before calling SimpleFormRansack.locale_files
|
25
|
+
config.i18n.available_locales = [:da, :en]
|
26
|
+
|
27
|
+
config.i18n.load_path += SimpleFormRansack.locale_files
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
# Usage
|
32
|
+
|
33
|
+
In your controller:
|
34
|
+
```ruby
|
35
|
+
class CustomerController < ApplicationController
|
36
|
+
def index
|
37
|
+
@ransack_params = params[:q] || {}
|
38
|
+
@ransack = Customer.ransack(@ransack_params)
|
39
|
+
@customers = @ransack.result
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
In your views:
|
45
|
+
```erb
|
46
|
+
<%= simple_search_form_for @ransack do |f| %>
|
47
|
+
<%= f.input :name_cont %>
|
48
|
+
<%= f.submit %>
|
49
|
+
<% end %>
|
50
|
+
```
|
51
|
+
|
52
|
+
Instead of something like this with a combination of Ransack and SimpleForm:
|
53
|
+
```erb
|
54
|
+
<%= search_form_for @ransack, builder: SimpleForm::FormBuilder do |f| %>
|
55
|
+
<%= f.input :name_cont, label: t(".attribute_contains", attribute: User.human_attribute_name(:name)), input_html: {value: @ransack_params[:name_cont]} %>
|
56
|
+
<%= f.submit %>
|
57
|
+
<% end %>
|
58
|
+
```
|
59
|
+
|
60
|
+
The `name_cont` input field now gets it label, hint and more translated as normally for a input with `name` but functions with the input-name `q[name_cont]`, making it much easier to use Ransack and SimpleForm, because you don't have to give label, hint or anything else manually.
|
@@ -26,6 +26,7 @@ class SimpleFormRansack::AttributeInspector
|
|
26
26
|
if index == @name_parts.length - 1
|
27
27
|
attribute_result = attribute_by_builtup
|
28
28
|
next unless attribute_result
|
29
|
+
|
29
30
|
@attribute = attribute_result.fetch(:name)
|
30
31
|
break
|
31
32
|
end
|
@@ -45,6 +46,7 @@ class SimpleFormRansack::AttributeInspector
|
|
45
46
|
# Returns true if a complicated label could be generated and simple form should not do this itself.
|
46
47
|
def generated_label?
|
47
48
|
return true if @attribute && @generated_name_classes.any?
|
49
|
+
|
48
50
|
false
|
49
51
|
end
|
50
52
|
|
@@ -82,6 +84,7 @@ private
|
|
82
84
|
total_name = @name_builtup.join("_")
|
83
85
|
result = @current_clazz.reflections.find { |name, _reflection| name.to_s == total_name }
|
84
86
|
return {name: result[0], reflection: result[1]} if result
|
87
|
+
|
85
88
|
false
|
86
89
|
end
|
87
90
|
|
@@ -89,6 +92,7 @@ private
|
|
89
92
|
total_name = @name_builtup.join("_")
|
90
93
|
result = @current_clazz.attribute_names.find { |name| name.to_s == total_name }
|
91
94
|
return {name: result} if result
|
95
|
+
|
92
96
|
false
|
93
97
|
end
|
94
98
|
|
@@ -4,6 +4,7 @@ class SimpleFormRansack::FormProxy
|
|
4
4
|
if Object.const_defined?(:Ransack)
|
5
5
|
predicates = Ransack::Configuration
|
6
6
|
.predicates
|
7
|
+
.sorted_names_with_underscores
|
7
8
|
.map(&:first)
|
8
9
|
.map { |predicate| Regexp.escape(predicate) }
|
9
10
|
.join("|")
|
@@ -32,13 +33,14 @@ class SimpleFormRansack::FormProxy
|
|
32
33
|
name: name,
|
33
34
|
args: args,
|
34
35
|
params: @params,
|
36
|
+
search_key: @ransack.context.search_key,
|
35
37
|
class: @class
|
36
38
|
)
|
37
39
|
|
38
40
|
@form.input(input_manipulator.attribute_name, *args)
|
39
41
|
end
|
40
42
|
|
41
|
-
def method_missing(method_name, *args, &blk)
|
43
|
+
def method_missing(method_name, *args, &blk) # rubocop:disable Style/MissingRespondToMissing
|
42
44
|
@form.__send__(method_name, *args, &blk)
|
43
45
|
end
|
44
46
|
end
|
@@ -5,6 +5,7 @@ class SimpleFormRansack::InputManipulator
|
|
5
5
|
@args = args.fetch(:args)
|
6
6
|
@name = args.fetch(:name)
|
7
7
|
@params = args.fetch(:params)
|
8
|
+
@search_key = args.fetch(:search_key)
|
8
9
|
@class = args.fetch(:class)
|
9
10
|
|
10
11
|
if @args.last.is_a?(Hash)
|
@@ -79,11 +80,11 @@ private
|
|
79
80
|
def set_name
|
80
81
|
# This overrides the individual check boxes and messes up the label targets
|
81
82
|
# There won't be any main input anyway, so it doesn't mess anything up either
|
82
|
-
@input_html[:id] = "
|
83
|
+
@input_html[:id] = "#{@search_key}_#{@name}" unless @as == "check_boxes"
|
83
84
|
|
84
85
|
return if @input_html.key?(:name)
|
85
86
|
|
86
|
-
@input_html[:name] = "
|
87
|
+
@input_html[:name] = "#{@search_key}[#{@name}]"
|
87
88
|
@input_html[:name] << "[]" if @as == "check_boxes"
|
88
89
|
end
|
89
90
|
|
@@ -119,9 +120,10 @@ private
|
|
119
120
|
return if label_parts.empty?
|
120
121
|
|
121
122
|
@opts[:label] = label_parts.join
|
122
|
-
prepend_label_for = %w
|
123
|
+
prepend_label_for = %w[cont gteq lteq]
|
123
124
|
|
124
125
|
return unless prepend_label_for.include?(@match_type)
|
126
|
+
|
125
127
|
@opts[:label] << " #{I18n.t("simple_form_ransack.match_types.#{@match_type}")}"
|
126
128
|
end
|
127
129
|
|
@@ -141,7 +143,7 @@ private
|
|
141
143
|
end
|
142
144
|
|
143
145
|
def set_value
|
144
|
-
if @as == "select" || @as == "country"
|
146
|
+
if @as == "select" || @as == "country" || @as == "select2"
|
145
147
|
set_value_for_select
|
146
148
|
elsif @as == "check_boxes" || @as == "radio_buttons"
|
147
149
|
set_value_for_checked
|
@@ -174,6 +176,7 @@ private
|
|
174
176
|
|
175
177
|
def set_value_for_boolean
|
176
178
|
return if @input_html.key?(:checked)
|
179
|
+
|
177
180
|
@input_html[:checked] = ("checked" if @params[@name] == "1")
|
178
181
|
end
|
179
182
|
|
@@ -190,6 +193,7 @@ private
|
|
190
193
|
def set_include_blank
|
191
194
|
return if @opts.key?(:include_blank)
|
192
195
|
return if @as != "select" && @as != "country"
|
196
|
+
|
193
197
|
@opts[:include_blank] = true
|
194
198
|
end
|
195
199
|
|
data/lib/simple_form_ransack.rb
CHANGED
@@ -5,7 +5,11 @@ module SimpleFormRansack
|
|
5
5
|
|
6
6
|
def self.locale_files
|
7
7
|
files = []
|
8
|
-
|
8
|
+
|
9
|
+
available_locales = []
|
10
|
+
available_locales += I18n.available_locales if I18n.available_locales
|
11
|
+
available_locales += Rails.application.config.i18n.available_locales if Rails.application.config.i18n.available_locales
|
12
|
+
available_locales.uniq!
|
9
13
|
|
10
14
|
available_locales.each do |locale|
|
11
15
|
path = "#{File.realpath("#{File.dirname(__FILE__)}/../config/locales")}/#{locale}.yml"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form_ransack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kasper Johansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,56 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.0.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
|
-
version:
|
26
|
+
version: 5.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: ransack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
type: :
|
33
|
+
version: 1.8.6
|
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
|
-
version:
|
40
|
+
version: 1.8.6
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: capybara
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: country_select
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: factory_girl_rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: pry
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: rspec-rails
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: rubocop
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -137,7 +137,7 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: rubocop-performance
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - ">="
|
@@ -151,7 +151,7 @@ dependencies:
|
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: rubocop-rspec
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - ">="
|
@@ -165,7 +165,21 @@ dependencies:
|
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
168
|
+
name: simple_form
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: sqlite3
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|
170
184
|
requirements:
|
171
185
|
- - ">="
|
@@ -187,6 +201,7 @@ extensions: []
|
|
187
201
|
extra_rdoc_files: []
|
188
202
|
files:
|
189
203
|
- MIT-LICENSE
|
204
|
+
- README.md
|
190
205
|
- Rakefile
|
191
206
|
- app/helpers/simple_form_ransack_helper.rb
|
192
207
|
- config/locales/da.yml
|
@@ -200,7 +215,8 @@ files:
|
|
200
215
|
- lib/tasks/simple_form_ransack_tasks.rake
|
201
216
|
homepage: https://www.github.com/kaspernj/simple_form_ransack
|
202
217
|
licenses: []
|
203
|
-
metadata:
|
218
|
+
metadata:
|
219
|
+
rubygems_mfa_required: 'true'
|
204
220
|
post_install_message:
|
205
221
|
rdoc_options: []
|
206
222
|
require_paths:
|
@@ -216,8 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
232
|
- !ruby/object:Gem::Version
|
217
233
|
version: '0'
|
218
234
|
requirements: []
|
219
|
-
|
220
|
-
rubygems_version: 2.2.2
|
235
|
+
rubygems_version: 3.1.6
|
221
236
|
signing_key:
|
222
237
|
specification_version: 4
|
223
238
|
summary: Ransack and SimpleForm combined.
|