satis 2.1.5 → 2.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab24a057287e49bf11f24ca8f304df57020c3904a79160fa8b4a625e55380d5a
4
- data.tar.gz: bdd35c925b3c002640195b642cd652719f24931b27fe4915f528d9800b27fb24
3
+ metadata.gz: b5d37ea4bc5bcbf39336bf85e880827d7431a601fde0a1ff08caf96f0fb52c3e
4
+ data.tar.gz: 5d11ce8f1e7177d5b864230787a1804e65ce0d1245764c73142e20a23e50107d
5
5
  SHA512:
6
- metadata.gz: db13c90b7bf3e47ada1d6ee10d386c6bb135a183b4bb0f365f12fc42205dd25000e9da2210e8c5ea5e6245aafaf877584c2bec618144e9445b9eee44d98a072f
7
- data.tar.gz: 729675b75520efe3b592af046c999dda0a59a58d55f25f80647f96bc28ce4debe2499918cb3719be2e39978fab353df24dd3e249ecad73886f5a854baf1a0b3d
6
+ metadata.gz: 55ff583894557956618c0a183422c92e55ff2da16cfdf3e2757c63acb0e9f7b34fc92938efdfbd67e00fda47e88c93d132b9ad3971da067bad68a3358ca03c9c
7
+ data.tar.gz: d16b710b624a602d9e5e5e77b4f3c1d280e6fc97b6e898bc0752b356dcd351498531028a6f3025ff11cc183e2b5a7cb1bdd370e39b6aec806e0079d7f1ba68f4
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'satis/concerns/contextual_translations'
4
- require 'satis/forms/concerns/buttons'
5
- require 'satis/forms/concerns/file'
6
- require 'satis/forms/concerns/required'
7
- require 'satis/forms/concerns/select'
8
- require 'satis/forms/concerns/options'
3
+ require "satis/concerns/contextual_translations"
4
+ require "satis/forms/concerns/buttons"
5
+ require "satis/forms/concerns/file"
6
+ require "satis/forms/concerns/required"
7
+ require "satis/forms/concerns/select"
8
+ require "satis/forms/concerns/options"
9
9
 
10
10
  module Satis
11
11
  module Forms
@@ -27,13 +27,13 @@ module Satis
27
27
  end
28
28
 
29
29
  # Regular input
30
- def input(method, options = {}, &block)
30
+ def input(method, options = {}, &)
31
31
  @form_options = options
32
32
 
33
33
  options[:input_html] ||= {}
34
34
  options[:input_html][:disabled] = options.delete(:disabled)
35
35
 
36
- send(input_type_for(method, options), method, options, &block)
36
+ send(input_type_for(method, options), method, options, &)
37
37
  end
38
38
 
39
39
  # NOTE: TDG - seems to be overwritten below
@@ -44,14 +44,14 @@ module Satis
44
44
  # end
45
45
 
46
46
  # A codemirror editor, backed by a text-area
47
- def editor(method, options = {}, &block)
47
+ def editor(method, options = {}, &)
48
48
  @form_options = options
49
49
 
50
- editor_input(method, options, &block)
50
+ editor_input(method, options, &)
51
51
  end
52
52
 
53
53
  # Simple-form like association
54
- def association(name, options, &block)
54
+ def association(name, options, &)
55
55
  @form_options = options
56
56
 
57
57
  @association = name
@@ -59,10 +59,10 @@ module Satis
59
59
 
60
60
  method = reflection.join_foreign_key
61
61
 
62
- send(input_type_for(method, options), method, options, &block)
62
+ send(input_type_for(method, options), method, options, &)
63
63
  end
64
64
 
65
- alias rails_fields_for fields_for
65
+ alias_method :rails_fields_for, :fields_for
66
66
 
67
67
  # Wrapper around fields_for, using Satis::Forms::Builder
68
68
  # Example:
@@ -73,7 +73,7 @@ module Satis
73
73
  # printers_form.input :name
74
74
  # end
75
75
  # end
76
- def fields_for(*args, &block)
76
+ def fields_for(*args, &)
77
77
  options = args.extract_options!
78
78
  name = args.first
79
79
  template_object = args.second
@@ -88,14 +88,14 @@ module Satis
88
88
  html_options[:data] ||= {}
89
89
  html_options[:data] = flatten_hash(html_options[:data])
90
90
  html_options[:data][:controller] =
91
- ['satis-fields-for'].concat(options[:html]&.[](:data)&.[](:controller).to_s.split).join(' ')
92
- html_options[:class] = ['fields_for'].concat(options[:html]&.[](:class).to_s.split).join(' ')
91
+ ["satis-fields-for"].concat(options[:html]&.[](:data)&.[](:controller).to_s.split).join(" ")
92
+ html_options[:class] = ["fields_for"].concat(options[:html]&.[](:class).to_s.split).join(" ")
93
93
 
94
94
  options[:builder] ||= if self.class < ActionView::Helpers::FormBuilder
95
- self.class
96
- else
97
- Satis::Forms::Builder
98
- end
95
+ self.class
96
+ else
97
+ Satis::Forms::Builder
98
+ end
99
99
 
100
100
  # Only do the whole nested-form thing with a collection
101
101
  if show_actions
@@ -106,7 +106,7 @@ module Satis
106
106
  options: options
107
107
  }
108
108
  tag.div(**html_options) do
109
- render 'shared/fields_for', view_options, &block
109
+ render "shared/fields_for", view_options, &block
110
110
  end
111
111
 
112
112
  # FIXME: You would want to do this:
@@ -116,13 +116,13 @@ module Satis
116
116
  else
117
117
  invalid_feedback = nil
118
118
  if @object.errors.messages[name].present?
119
- invalid_feedback = tag.div(@object.errors.messages[name].join(', '),
120
- class: 'invalid-feedback')
119
+ invalid_feedback = tag.div(@object.errors.messages[name].join(", "),
120
+ class: "invalid-feedback")
121
121
  end
122
122
  safe_join [
123
- invalid_feedback,
124
- rails_fields_for(*args, options, &block)
125
- ].compact
123
+ invalid_feedback,
124
+ rails_fields_for(*args, options, &)
125
+ ].compact
126
126
  end
127
127
  end
128
128
 
@@ -130,24 +130,24 @@ module Satis
130
130
  options = args.extract_options!
131
131
  form_group(*args, options) do
132
132
  safe_join [
133
- (custom_label(*args, options[:label]) unless options[:label] == false),
134
- rich_text_area(*args, options)
135
- ]
133
+ (custom_label(*args, options[:label]) unless options[:label] == false),
134
+ rich_text_area(*args, options)
135
+ ]
136
136
  end
137
137
  end
138
138
 
139
139
  # A switch backed by a hidden value
140
- def switch(method, options = {}, &block)
140
+ def switch(method, options = {}, &)
141
141
  @form_options = options
142
142
 
143
- switch_input(method, options, &block)
143
+ switch_input(method, options, &)
144
144
  end
145
145
 
146
146
  # A hidden input
147
- def hidden(method, options = {}, &block)
147
+ def hidden(method, options = {}, &)
148
148
  @form_options = options
149
149
 
150
- hidden_input(method, options, &block)
150
+ hidden_input(method, options, &)
151
151
  end
152
152
 
153
153
  # Non public
@@ -155,19 +155,19 @@ module Satis
155
155
  def input_type_for(method, options)
156
156
  object_type = object_type_for_method(method)
157
157
  input_type = case object_type
158
- when :date then :date_time
159
- when :datetime then :date_time
160
- when :integer then :string
161
- when :float then :string
162
- else object_type
163
- end
158
+ when :date then :date_time
159
+ when :datetime then :date_time
160
+ when :integer then :string
161
+ when :float then :string
162
+ else object_type
163
+ end
164
164
  override_input_type = if options[:as]
165
- options[:as]
166
- elsif options[:collection]
167
- :select
168
- elsif options[:url]
169
- :dropdown
170
- end
165
+ options[:as]
166
+ elsif options[:collection]
167
+ :select
168
+ elsif options[:url]
169
+ :dropdown
170
+ end
171
171
 
172
172
  "#{override_input_type || input_type}_input"
173
173
  end
@@ -175,38 +175,38 @@ module Satis
175
175
  def form_group(method, options = {}, &block)
176
176
  tag.div(class: "form-group form-group-#{method}", data: options.delete(:data)) do
177
177
  safe_join [
178
- block.call,
179
- hint_text(options[:hint]),
180
- error_text(method)
181
- ].compact
178
+ block.call,
179
+ hint_text(options[:hint]),
180
+ error_text(method)
181
+ ].compact
182
182
  end
183
183
  end
184
184
 
185
185
  def hint_text(text)
186
186
  return if text.nil?
187
187
 
188
- tag.small text, class: 'form-text text-muted'
188
+ tag.small text, class: "form-text text-muted"
189
189
  end
190
190
 
191
191
  # FIXME: These don't work for relations or location_id, error is on location
192
192
  # When using the association helper, we need to set a @assocation variable
193
193
  # any other input should clear it
194
194
  def error_text(method)
195
- return if !has_error?(method) && !has_error?(method.to_s.gsub(/_id$/, ''))
195
+ return if !has_error?(method) && !has_error?(method.to_s.gsub(/_id$/, ""))
196
196
 
197
197
  all_errors = @object.errors[method].dup
198
- all_errors += @object.errors[method.to_s.gsub(/_id$/, '')] if method.to_s.ends_with?('_id')
198
+ all_errors += @object.errors[method.to_s.gsub(/_id$/, "")] if method.to_s.ends_with?("_id")
199
199
 
200
- tag.div(all_errors.uniq.join('<br />').html_safe,
201
- class: 'invalid-feedback')
200
+ tag.div(all_errors.uniq.join("<br />").html_safe,
201
+ class: "invalid-feedback")
202
202
  end
203
203
 
204
204
  def object_type_for_method(method)
205
205
  result = if @object.respond_to?(:type_for_attribute) && @object.has_attribute?(method)
206
- @object.type_for_attribute(method.to_s).try(:type)
207
- elsif @object.respond_to?(:column_for_attribute) && @object.has_attribute?(method)
208
- @object.column_for_attribute(method).try(:type)
209
- end
206
+ @object.type_for_attribute(method.to_s).try(:type)
207
+ elsif @object.respond_to?(:column_for_attribute) && @object.has_attribute?(method)
208
+ @object.column_for_attribute(method).try(:type)
209
+ end
210
210
  result || :string
211
211
  end
212
212
 
@@ -220,40 +220,40 @@ module Satis
220
220
  all_classes = "#{options[:class]} form-label".strip
221
221
  label(method, title, class: all_classes, data: options[:data]) do |translation|
222
222
  safe_join [
223
- tag.span(title || translation, class: required?(method) ? 'required' : ''),
224
- ' ',
225
- required(method, options),
226
- help(method, options)
227
- ]
223
+ tag.span(title || translation, class: required?(method) ? "required" : ""),
224
+ " ",
225
+ required(method, options),
226
+ help(method, options)
227
+ ]
228
228
  end
229
229
  end
230
230
 
231
231
  def required(method, _options = {})
232
232
  return unless required?(method)
233
233
 
234
- tag.i(class: 'fas fa-hexagon-exclamation')
234
+ tag.i(class: "fas fa-hexagon-exclamation")
235
235
  end
236
236
 
237
237
  def help(method, options = {})
238
- text = if options[:help].present?
239
- options[:help]
240
- else
241
- Satis.config.default_help_text.call(@template, @object, method,
242
- @options[:help_scope] || options[:help_scope])
243
- end
238
+ text = options[:help].presence || Satis.config.default_help_text.call(@template, @object, method,
239
+ @options[:help_scope] || options[:help_scope])
244
240
 
245
241
  return if text.blank?
246
242
 
247
- tag.i(class: 'fal fa-circle-info', 'data-controller': 'help', 'data-help-content-value': text)
243
+ tag.i(class: "fal fa-circle-info", "data-controller": "help", "data-help-content-value": text)
248
244
  end
249
245
 
250
246
  def hidden_input(method, options = {})
251
247
  hidden_field(method, options[:input_html] || {})
252
248
  end
253
249
 
250
+ def password_input(method, options = {})
251
+ string_input(method, options.merge(as: :password))
252
+ end
253
+
254
254
  # Inputs and helpers
255
255
  def string_input(method, options = {})
256
- orig_data = options.fetch(:data, {}).merge(controller: 'satis-input')
256
+ orig_data = options.fetch(:data, {}).merge(controller: "satis-input")
257
257
  scrollable = options.fetch(:scrollable, false)
258
258
 
259
259
  css_class = ["form-control"]
@@ -261,58 +261,58 @@ module Satis
261
261
  css_class << "noscroll" unless scrollable
262
262
 
263
263
  data = options[:input_html].fetch(:data, {})
264
- data = data.merge('satis-input-target' => 'input')
264
+ data = data.merge("satis-input-target" => "input")
265
265
  options[:input_html] = options[:input_html].merge(data: data)
266
266
 
267
267
  form_group(method, options.merge(data: orig_data)) do
268
268
  safe_join [
269
- (custom_label(method, options[:label], options) unless options[:label] == false),
270
- string_field(method, merge_input_options({ as: options[:as], class: "#{css_class.join(' ')}" }, options[:input_html]))
271
- ]
269
+ (custom_label(method, options[:label], options) unless options[:label] == false),
270
+ string_field(method, merge_input_options({as: options[:as], class: "#{css_class.join(" ")}"}, options[:input_html]))
271
+ ]
272
272
  end
273
273
  end
274
274
 
275
275
  def number_input(method, options = {})
276
276
  form_group(method, options) do
277
277
  safe_join [
278
- (custom_label(method, options[:label], options) unless options[:label] == false),
279
- number_field(method,
280
- merge_input_options({ class: "form-control #{
278
+ (custom_label(method, options[:label], options) unless options[:label] == false),
279
+ number_field(method,
280
+ merge_input_options({class: "form-control #{
281
281
  if has_error?(method)
282
- 'is-invalid'
283
- end}" }, options[:input_html]))
284
- ]
282
+ "is-invalid"
283
+ end}"}, options[:input_html]))
284
+ ]
285
285
  end
286
286
  end
287
287
 
288
288
  def text_input(method, options = {})
289
289
  form_group(method, options) do
290
290
  safe_join [
291
- (custom_label(method, options[:label], options) unless options[:label] == false),
292
- text_area(method,
293
- merge_input_options({ class: "form-control #{
291
+ (custom_label(method, options[:label], options) unless options[:label] == false),
292
+ text_area(method,
293
+ merge_input_options({class: "form-control #{
294
294
  if has_error?(method)
295
- 'is-invalid'
296
- end}" }, options[:input_html]))
297
- ]
295
+ "is-invalid"
296
+ end}"}, options[:input_html]))
297
+ ]
298
298
  end
299
299
  end
300
300
 
301
301
  def input_array(method, options = {})
302
302
  form_group(method, options) do
303
303
  safe_join [
304
- (custom_label(method, options[:label], options) unless options[:label] == false),
305
- render(Satis::InputArray::Component.new(form: self, attribute: method, **options))
306
- ]
304
+ (custom_label(method, options[:label], options) unless options[:label] == false),
305
+ render(Satis::InputArray::Component.new(form: self, attribute: method, **options))
306
+ ]
307
307
  end
308
308
  end
309
309
 
310
310
  def editor_input(method, options = {}, &block)
311
311
  form_group(method, options) do
312
312
  safe_join [
313
- (custom_label(method, options[:label], options) unless options[:label] == false),
314
- @template.render(Satis::Editor::Component.new(form: self, attribute: method, **options, &block))
315
- ]
313
+ (custom_label(method, options[:label], options) unless options[:label] == false),
314
+ @template.render(Satis::Editor::Component.new(form: self, attribute: method, **options, &block))
315
+ ]
316
316
  end
317
317
  # form_group(method, options) do
318
318
  # safe_join [
@@ -343,11 +343,11 @@ module Satis
343
343
 
344
344
  def boolean_input(method, options = {})
345
345
  form_group(method, options) do
346
- tag.div(class: 'custom-control custom-checkbox') do
346
+ tag.div(class: "custom-control custom-checkbox") do
347
347
  safe_join [
348
- check_box(method, merge_input_options({ class: 'custom-control-input' }, options[:input_html])),
349
- label(method, options[:label], class: 'custom-control-label')
350
- ]
348
+ check_box(method, merge_input_options({class: "custom-control-input"}, options[:input_html])),
349
+ label(method, options[:label], class: "custom-control-label")
350
+ ]
351
351
  end
352
352
  end
353
353
  end
@@ -357,7 +357,7 @@ module Satis
357
357
  def switch_input(method, options = {}, &block)
358
358
  form_group(method, options) do
359
359
  render(Satis::Switch::Component.new(form: self, attribute: method, title: options[:label], **options,
360
- &block))
360
+ &block))
361
361
  end
362
362
  end
363
363
 
@@ -371,10 +371,10 @@ module Satis
371
371
  end
372
372
  form_group(method, options) do
373
373
  safe_join [
374
- (custom_label(method, options[:label], options) unless options[:label] == false),
375
- render(Satis::DateTimePicker::Component.new(form: self, attribute: method, title: options[:label], **options,
376
- &block))
377
- ]
374
+ (custom_label(method, options[:label], options) unless options[:label] == false),
375
+ render(Satis::DateTimePicker::Component.new(form: self, attribute: method, title: options[:label], **options,
376
+ &block))
377
+ ]
378
378
  end
379
379
  end
380
380
 
@@ -385,43 +385,43 @@ module Satis
385
385
  # 'data-phone-number-target': 'input',
386
386
  # 'data-action': 'keyup->phone-number#change blur->phone-number#change' }
387
387
 
388
- tag.div('data-controller' => 'phone-number') do
388
+ tag.div("data-controller" => "phone-number") do
389
389
  safe_join [
390
- hidden_field(method,
391
- merge_input_options({ class: 'form-control', 'data-phone-number-target': 'hiddenInput' },
392
- options[:input_html])),
393
- @template.text_field_tag('dummy', @object.try(method), class: "form-control #{
390
+ hidden_field(method,
391
+ merge_input_options({class: "form-control", "data-phone-number-target": "hiddenInput"},
392
+ options[:input_html])),
393
+ @template.text_field_tag("dummy", @object.try(method), class: "form-control #{
394
394
  if has_error?(method)
395
- 'is-invalid'
396
- end}", 'data-phone-number-target': 'input',
397
- 'data-action': 'input->phone-number#change')
398
- ]
395
+ "is-invalid"
396
+ end}", "data-phone-number-target": "input",
397
+ "data-action": "input->phone-number#change")
398
+ ]
399
399
  end
400
400
  end
401
401
 
402
402
  def collection_of(input_type, method, options = {})
403
403
  form_builder_method, custom_class, input_builder_method = case input_type
404
- when :radio_buttons then [:collection_radio_buttons,
405
- 'custom-radio', :radio_button]
406
- when :check_boxes then [:collection_check_boxes,
407
- 'custom-checkbox', :check_box]
408
- else raise 'Invalid input_type for collection_of, valid input_types are ":radio_buttons", ":check_boxes"'
409
- end
404
+ when :radio_buttons then [:collection_radio_buttons,
405
+ "custom-radio", :radio_button]
406
+ when :check_boxes then [:collection_check_boxes,
407
+ "custom-checkbox", :check_box]
408
+ else raise 'Invalid input_type for collection_of, valid input_types are ":radio_buttons", ":check_boxes"'
409
+ end
410
410
  options[:value_method] ||= :last
411
411
  options[:text_method] ||= options[:label_method] || :first
412
412
  form_group(method, options) do
413
413
  safe_join [
414
- (custom_label(method, options[:label], options) unless options[:label] == false),
415
- (send(form_builder_method, method, options[:collection], options[:value_method],
416
- options[:text_method]) do |b|
417
- tag.div(class: "custom-control #{custom_class}") do
418
- safe_join [
419
- b.send(input_builder_method, options.fetch(:input_html, {}).merge(class: 'custom-control-input')),
420
- b.label(class: 'custom-control-label')
421
- ]
422
- end
423
- end)
424
- ]
414
+ (custom_label(method, options[:label], options) unless options[:label] == false),
415
+ (send(form_builder_method, method, options[:collection], options[:value_method],
416
+ options[:text_method]) do |b|
417
+ tag.div(class: "custom-control #{custom_class}") do
418
+ safe_join [
419
+ b.send(input_builder_method, options.fetch(:input_html, {}).merge(class: "custom-control-input")),
420
+ b.label(class: "custom-control-label")
421
+ ]
422
+ end
423
+ end)
424
+ ]
425
425
  end
426
426
  end
427
427
 
@@ -447,9 +447,9 @@ module Satis
447
447
  when /password/ then password_field(method, options)
448
448
  # FIXME: Possibly use time_zone_select with dropdown?
449
449
  when /time_zone/ then time_zone_select(method, options.delete(:priority_zones), options,
450
- { class: 'custom-select form-control' })
450
+ {class: "custom-select form-control"})
451
451
  # FIXME: Possibly use country_select with dropdown?
452
- when /country/ then country_select(method, options, class: 'custom-select form-control')
452
+ when /country/ then country_select(method, options, class: "custom-select form-control")
453
453
  when /email/ then email_field(method, options)
454
454
  when /phone/ then phone_input(method, options)
455
455
  when /url/ then url_field(method, options)
@@ -470,7 +470,7 @@ module Satis
470
470
  hash.each_with_object({}) do |(k, v), h|
471
471
  if v.is_a? Hash
472
472
  flatten_hash(v).map do |h_k, h_v|
473
- h["#{k}_#{h_k}".to_sym] = h_v
473
+ h[:"#{k}_#{h_k}"] = h_v
474
474
  end
475
475
  else
476
476
  h[k] = v
data/lib/satis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Satis
2
- VERSION = "2.1.5"
2
+ VERSION = "2.1.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: satis
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 2.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom de Grunt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-07 00:00:00.000000000 Z
11
+ date: 2024-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: browser