flexible_filter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +8 -0
- data/app/assets/config/flexible_filter_manifest.js +1 -0
- data/app/assets/stylesheets/flexible_filter/application.css +15 -0
- data/app/controllers/flexible_filter/application_controller.rb +4 -0
- data/app/decorators/application_decorator.rb +8 -0
- data/app/helpers/flexible_filter/application_helper.rb +4 -0
- data/app/jobs/flexible_filter/application_job.rb +4 -0
- data/app/mailers/flexible_filter/application_mailer.rb +6 -0
- data/app/models/flexible_filter/application_record.rb +5 -0
- data/app/views/layouts/flexible_filter/application.html.erb +15 -0
- data/config/initializers/simple_form.rb +176 -0
- data/config/locales/simple_form.en.yml +31 -0
- data/config/routes.rb +2 -0
- data/lib/flexible_filter/engine.rb +5 -0
- data/lib/flexible_filter/field/equals.rb +14 -0
- data/lib/flexible_filter/field/singular.rb +16 -0
- data/lib/flexible_filter/field.rb +8 -0
- data/lib/flexible_filter/reflection/belongs_to.rb +19 -0
- data/lib/flexible_filter/version.rb +3 -0
- data/lib/flexible_filter.rb +7 -0
- data/lib/tasks/flexible_filter_tasks.rake +4 -0
- data/lib/templates/erb/scaffold/_form.html.erb +15 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8180aedd8cdbd147103800c09ff8336cf4e6af376653ad05b784de28cd22cc1a
|
4
|
+
data.tar.gz: 2f1d33e0440df7c73595a77a8c736d7cf97d850aa1f7d30d972e7830fcbfd234
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 02b4b1286755c8d78feca18cf8cc2fb5954d14056c06a816d439c63699c7cc485b5f34f92fcbfc0a8bc4bb2fdc6682f282a0c57aad523318e3b34176a7d1332c
|
7
|
+
data.tar.gz: 5bb188506b7f9c84e5a8d9144987b24629eebf1c573d2063b04fbe1add9ac2cb0b5adfc0c8e51dcc41cac7b16cb23b2858a1b6760b70c51c592926c0984ce3ef
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright Robert Ferney
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# FlexibleFilter
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem "flexible_filter"
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install flexible_filter
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
// = link_directory ../stylesheets/flexible_filter .css
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Flexible filter</title>
|
5
|
+
<%= csrf_meta_tags %>
|
6
|
+
<%= csp_meta_tag %>
|
7
|
+
|
8
|
+
<%= stylesheet_link_tag "flexible_filter/application", media: "all" %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
|
12
|
+
<%= yield %>
|
13
|
+
|
14
|
+
</body>
|
15
|
+
</html>
|
@@ -0,0 +1,176 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Uncomment this and change the path if necessary to include your own
|
4
|
+
# components.
|
5
|
+
# See https://github.com/heartcombo/simple_form#custom-components to know
|
6
|
+
# more about custom components.
|
7
|
+
# Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }
|
8
|
+
#
|
9
|
+
# Use this setup block to configure all options available in SimpleForm.
|
10
|
+
SimpleForm.setup do |config|
|
11
|
+
# Wrappers are used by the form builder to generate a
|
12
|
+
# complete input. You can remove any component from the
|
13
|
+
# wrapper, change the order or even add your own to the
|
14
|
+
# stack. The options given below are used to wrap the
|
15
|
+
# whole input.
|
16
|
+
config.wrappers :default, class: :input,
|
17
|
+
hint_class: :field_with_hint, error_class: :field_with_errors, valid_class: :field_without_errors do |b|
|
18
|
+
## Extensions enabled by default
|
19
|
+
# Any of these extensions can be disabled for a
|
20
|
+
# given input by passing: `f.input EXTENSION_NAME => false`.
|
21
|
+
# You can make any of these extensions optional by
|
22
|
+
# renaming `b.use` to `b.optional`.
|
23
|
+
|
24
|
+
# Determines whether to use HTML5 (:email, :url, ...)
|
25
|
+
# and required attributes
|
26
|
+
b.use :html5
|
27
|
+
|
28
|
+
# Calculates placeholders automatically from I18n
|
29
|
+
# You can also pass a string as f.input placeholder: "Placeholder"
|
30
|
+
b.use :placeholder
|
31
|
+
|
32
|
+
## Optional extensions
|
33
|
+
# They are disabled unless you pass `f.input EXTENSION_NAME => true`
|
34
|
+
# to the input. If so, they will retrieve the values from the model
|
35
|
+
# if any exists. If you want to enable any of those
|
36
|
+
# extensions by default, you can change `b.optional` to `b.use`.
|
37
|
+
|
38
|
+
# Calculates maxlength from length validations for string inputs
|
39
|
+
# and/or database column lengths
|
40
|
+
b.optional :maxlength
|
41
|
+
|
42
|
+
# Calculate minlength from length validations for string inputs
|
43
|
+
b.optional :minlength
|
44
|
+
|
45
|
+
# Calculates pattern from format validations for string inputs
|
46
|
+
b.optional :pattern
|
47
|
+
|
48
|
+
# Calculates min and max from length validations for numeric inputs
|
49
|
+
b.optional :min_max
|
50
|
+
|
51
|
+
# Calculates readonly automatically from readonly attributes
|
52
|
+
b.optional :readonly
|
53
|
+
|
54
|
+
## Inputs
|
55
|
+
# b.use :input, class: 'input', error_class: 'is-invalid', valid_class: 'is-valid'
|
56
|
+
b.use :label_input
|
57
|
+
b.use :hint, wrap_with: { tag: :span, class: :hint }
|
58
|
+
b.use :error, wrap_with: { tag: :span, class: :error }
|
59
|
+
|
60
|
+
## full_messages_for
|
61
|
+
# If you want to display the full error message for the attribute, you can
|
62
|
+
# use the component :full_error, like:
|
63
|
+
#
|
64
|
+
# b.use :full_error, wrap_with: { tag: :span, class: :error }
|
65
|
+
end
|
66
|
+
|
67
|
+
# The default wrapper to be used by the FormBuilder.
|
68
|
+
config.default_wrapper = :default
|
69
|
+
|
70
|
+
# Define the way to render check boxes / radio buttons with labels.
|
71
|
+
# Defaults to :nested for bootstrap config.
|
72
|
+
# inline: input + label
|
73
|
+
# nested: label > input
|
74
|
+
config.boolean_style = :nested
|
75
|
+
|
76
|
+
# Default class for buttons
|
77
|
+
config.button_class = 'btn'
|
78
|
+
|
79
|
+
# Method used to tidy up errors. Specify any Rails Array method.
|
80
|
+
# :first lists the first message for each field.
|
81
|
+
# Use :to_sentence to list all errors for each field.
|
82
|
+
# config.error_method = :first
|
83
|
+
|
84
|
+
# Default tag used for error notification helper.
|
85
|
+
config.error_notification_tag = :div
|
86
|
+
|
87
|
+
# CSS class to add for error notification helper.
|
88
|
+
config.error_notification_class = 'error_notification'
|
89
|
+
|
90
|
+
# Series of attempts to detect a default label method for collection.
|
91
|
+
# config.collection_label_methods = [ :to_label, :name, :title, :to_s ]
|
92
|
+
|
93
|
+
# Series of attempts to detect a default value method for collection.
|
94
|
+
# config.collection_value_methods = [ :id, :to_s ]
|
95
|
+
|
96
|
+
# You can wrap a collection of radio/check boxes in a pre-defined tag, defaulting to none.
|
97
|
+
# config.collection_wrapper_tag = nil
|
98
|
+
|
99
|
+
# You can define the class to use on all collection wrappers. Defaulting to none.
|
100
|
+
# config.collection_wrapper_class = nil
|
101
|
+
|
102
|
+
# You can wrap each item in a collection of radio/check boxes with a tag,
|
103
|
+
# defaulting to :span.
|
104
|
+
# config.item_wrapper_tag = :span
|
105
|
+
|
106
|
+
# You can define a class to use in all item wrappers. Defaulting to none.
|
107
|
+
# config.item_wrapper_class = nil
|
108
|
+
|
109
|
+
# How the label text should be generated altogether with the required text.
|
110
|
+
# config.label_text = lambda { |label, required, explicit_label| "#{required} #{label}" }
|
111
|
+
|
112
|
+
# You can define the class to use on all labels. Default is nil.
|
113
|
+
# config.label_class = nil
|
114
|
+
|
115
|
+
# You can define the default class to be used on forms. Can be overridden
|
116
|
+
# with `html: { :class }`. Defaulting to none.
|
117
|
+
# config.default_form_class = nil
|
118
|
+
|
119
|
+
# You can define which elements should obtain additional classes
|
120
|
+
# config.generate_additional_classes_for = [:wrapper, :label, :input]
|
121
|
+
|
122
|
+
# Whether attributes are required by default (or not). Default is true.
|
123
|
+
# config.required_by_default = true
|
124
|
+
|
125
|
+
# Tell browsers whether to use the native HTML5 validations (novalidate form option).
|
126
|
+
# These validations are enabled in SimpleForm's internal config but disabled by default
|
127
|
+
# in this configuration, which is recommended due to some quirks from different browsers.
|
128
|
+
# To stop SimpleForm from generating the novalidate option, enabling the HTML5 validations,
|
129
|
+
# change this configuration to true.
|
130
|
+
config.browser_validations = false
|
131
|
+
|
132
|
+
# Custom mappings for input types. This should be a hash containing a regexp
|
133
|
+
# to match as key, and the input type that will be used when the field name
|
134
|
+
# matches the regexp as value.
|
135
|
+
# config.input_mappings = { /count/ => :integer }
|
136
|
+
|
137
|
+
# Custom wrappers for input types. This should be a hash containing an input
|
138
|
+
# type as key and the wrapper that will be used for all inputs with specified type.
|
139
|
+
# config.wrapper_mappings = { string: :prepend }
|
140
|
+
|
141
|
+
# Namespaces where SimpleForm should look for custom input classes that
|
142
|
+
# override default inputs.
|
143
|
+
# config.custom_inputs_namespaces << "CustomInputs"
|
144
|
+
|
145
|
+
# Default priority for time_zone inputs.
|
146
|
+
# config.time_zone_priority = nil
|
147
|
+
|
148
|
+
# Default priority for country inputs.
|
149
|
+
# config.country_priority = nil
|
150
|
+
|
151
|
+
# When false, do not use translations for labels.
|
152
|
+
# config.translate_labels = true
|
153
|
+
|
154
|
+
# Automatically discover new inputs in Rails' autoload path.
|
155
|
+
# config.inputs_discovery = true
|
156
|
+
|
157
|
+
# Cache SimpleForm inputs discovery
|
158
|
+
# config.cache_discovery = !Rails.env.development?
|
159
|
+
|
160
|
+
# Default class for inputs
|
161
|
+
# config.input_class = nil
|
162
|
+
|
163
|
+
# Define the default class of the input wrapper of the boolean input.
|
164
|
+
config.boolean_label_class = 'checkbox'
|
165
|
+
|
166
|
+
# Defines if the default input wrapper class should be included in radio
|
167
|
+
# collection wrappers.
|
168
|
+
# config.include_default_input_wrapper_class = true
|
169
|
+
|
170
|
+
# Defines which i18n scope will be used in Simple Form.
|
171
|
+
# config.i18n_scope = 'simple_form'
|
172
|
+
|
173
|
+
# Defines validation classes to the input_field. By default it's nil.
|
174
|
+
# config.input_field_valid_class = 'is-valid'
|
175
|
+
# config.input_field_error_class = 'is-invalid'
|
176
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
en:
|
2
|
+
simple_form:
|
3
|
+
"yes": 'Yes'
|
4
|
+
"no": 'No'
|
5
|
+
required:
|
6
|
+
text: 'required'
|
7
|
+
mark: '*'
|
8
|
+
# You can uncomment the line below if you need to overwrite the whole required html.
|
9
|
+
# When using html, text and mark won't be used.
|
10
|
+
# html: '<abbr title="required">*</abbr>'
|
11
|
+
error_notification:
|
12
|
+
default_message: "Please review the problems below:"
|
13
|
+
# Examples
|
14
|
+
# labels:
|
15
|
+
# defaults:
|
16
|
+
# password: 'Password'
|
17
|
+
# user:
|
18
|
+
# new:
|
19
|
+
# email: 'E-mail to sign in.'
|
20
|
+
# edit:
|
21
|
+
# email: 'E-mail.'
|
22
|
+
# hints:
|
23
|
+
# defaults:
|
24
|
+
# username: 'User name to sign in.'
|
25
|
+
# password: 'No special characters, please.'
|
26
|
+
# include_blanks:
|
27
|
+
# defaults:
|
28
|
+
# age: 'Rather not say'
|
29
|
+
# prompts:
|
30
|
+
# defaults:
|
31
|
+
# age: 'Select your age'
|
data/config/routes.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
module FlexibleFilter
|
3
|
+
module Field
|
4
|
+
class Singular
|
5
|
+
attr_reader :model, :field, :value
|
6
|
+
|
7
|
+
def initialize(model, field, value)
|
8
|
+
@model = model
|
9
|
+
@field = field
|
10
|
+
@value = value
|
11
|
+
end
|
12
|
+
|
13
|
+
delegate :arel_table, :model_name, to: :model
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class FlexibleFilter::Reflection::BelongsTo
|
2
|
+
attr_reader :reflection
|
3
|
+
|
4
|
+
def initialize(reflection)
|
5
|
+
@reflection = reflection
|
6
|
+
end
|
7
|
+
|
8
|
+
delegate :join_primary_key, :join_foreign_key, to: :reflection
|
9
|
+
|
10
|
+
def primary_table
|
11
|
+
reflection.klass.arel_table
|
12
|
+
end
|
13
|
+
|
14
|
+
def foreign_table
|
15
|
+
reflection.active_record.arel_table
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%# frozen_string_literal: true %>
|
2
|
+
<%%= simple_form_for(@<%= singular_table_name %>) do |f| %>
|
3
|
+
<%%= f.error_notification %>
|
4
|
+
<%%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
|
5
|
+
|
6
|
+
<div class="form-inputs">
|
7
|
+
<%- attributes.each do |attribute| -%>
|
8
|
+
<%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
|
9
|
+
<%- end -%>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<div class="form-actions">
|
13
|
+
<%%= f.button :submit %>
|
14
|
+
</div>
|
15
|
+
<%% end %>
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flexible_filter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Ferney
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 7.1.3.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 7.1.3.4
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- rob@ferney.org
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- app/assets/config/flexible_filter_manifest.js
|
38
|
+
- app/assets/stylesheets/flexible_filter/application.css
|
39
|
+
- app/controllers/flexible_filter/application_controller.rb
|
40
|
+
- app/decorators/application_decorator.rb
|
41
|
+
- app/helpers/flexible_filter/application_helper.rb
|
42
|
+
- app/jobs/flexible_filter/application_job.rb
|
43
|
+
- app/mailers/flexible_filter/application_mailer.rb
|
44
|
+
- app/models/flexible_filter/application_record.rb
|
45
|
+
- app/views/layouts/flexible_filter/application.html.erb
|
46
|
+
- config/initializers/simple_form.rb
|
47
|
+
- config/locales/simple_form.en.yml
|
48
|
+
- config/routes.rb
|
49
|
+
- lib/flexible_filter.rb
|
50
|
+
- lib/flexible_filter/engine.rb
|
51
|
+
- lib/flexible_filter/field.rb
|
52
|
+
- lib/flexible_filter/field/equals.rb
|
53
|
+
- lib/flexible_filter/field/singular.rb
|
54
|
+
- lib/flexible_filter/reflection/belongs_to.rb
|
55
|
+
- lib/flexible_filter/version.rb
|
56
|
+
- lib/tasks/flexible_filter_tasks.rake
|
57
|
+
- lib/templates/erb/scaffold/_form.html.erb
|
58
|
+
homepage: https://github.com/capnregex/flexible_filter
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata:
|
62
|
+
homepage_uri: https://github.com/capnregex/flexible_filter
|
63
|
+
source_code_uri: https://github.com/capnregex/flexible_filter
|
64
|
+
changelog_uri: https://github.com/capnregex/flexible_filter/releases/tag/v0.0.1
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubygems_version: 3.5.15
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Provides An interface for more flexible user specified filtering
|
84
|
+
test_files: []
|