effective_bootstrap 0.9.2 → 0.9.3
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 +4 -4
- data/app/models/effective/form_input.rb +33 -19
- data/app/models/effective/form_logic.rb +1 -1
- data/lib/effective_bootstrap/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 653ce4dc21d9961a88154cbfb0b3c59e4d4f85615e3edc4d89f774fbca7a0026
|
4
|
+
data.tar.gz: 724f3a374fe198d935fb72773e0e411c070bb9365c93228ca64c01bf93893a27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8d946e930a29d18016012f49f2df1b72a43da46504fdc7e0c943bc111c92d85d34f394fe77a708bb93a27b10bb25c0ef003024d3b29606449057c8d156546ef
|
7
|
+
data.tar.gz: 4d23bd8f9fb754f318a3115ae72ddd924714e9704bfad6d4e489510503dcbdead65f13abef5b0ab2867f18e2377700aa4c672fd7126e0d4889d6a21158d9b112
|
@@ -1,11 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Effective
|
2
4
|
class FormInput
|
3
5
|
attr_accessor :name, :options
|
4
6
|
|
5
7
|
BLANK = ''.html_safe
|
8
|
+
EMPTY_HASH = {}
|
9
|
+
|
6
10
|
EXCLUSIVE_CLASS_PREFIXES = [] # None
|
7
11
|
EXCLUSIVE_CLASS_SUFFIXES = ['-primary', '-secondary', '-success', '-danger', '-warning', '-info', '-light', '-dark']
|
8
12
|
|
13
|
+
DEFAULT_INPUT_GROUP_OPTIONS = { input_group: { class: 'input-group' }, prepend: false, append: false }
|
14
|
+
|
15
|
+
HORIZONTAL_LABEL_OPTIONS = { class: 'col-sm-2 col-form-label'}
|
16
|
+
INLINE_LABEL_OPTIONS = { class: 'sr-only' }
|
17
|
+
|
18
|
+
DEFAULT_FEEDBACK_OPTIONS = { valid: { class: 'valid-feedback' }, invalid: { class: 'invalid-feedback' } }
|
19
|
+
|
20
|
+
HORIZONTAL_WRAPPER_OPTIONS = { class: 'form-group row' }
|
21
|
+
VERTICAL_WRAPPER_OPTIONS = { class: 'form-group' }
|
22
|
+
|
9
23
|
delegate :object, to: :@builder
|
10
24
|
delegate :capture, :content_tag, :image_tag, :link_to, :icon, :asset_path, to: :@template
|
11
25
|
|
@@ -20,7 +34,7 @@ module Effective
|
|
20
34
|
end
|
21
35
|
|
22
36
|
def input_group_options
|
23
|
-
|
37
|
+
DEFAULT_INPUT_GROUP_OPTIONS
|
24
38
|
end
|
25
39
|
|
26
40
|
def input_html_options
|
@@ -28,17 +42,17 @@ module Effective
|
|
28
42
|
end
|
29
43
|
|
30
44
|
def input_js_options
|
31
|
-
|
45
|
+
EMPTY_HASH
|
32
46
|
end
|
33
47
|
|
34
48
|
def label_options
|
35
49
|
case layout
|
36
50
|
when :horizontal
|
37
|
-
|
51
|
+
HORIZONTAL_LABEL_OPTIONS
|
38
52
|
when :inline
|
39
|
-
|
53
|
+
INLINE_LABEL_OPTIONS
|
40
54
|
else
|
41
|
-
|
55
|
+
EMPTY_HASH
|
42
56
|
end
|
43
57
|
end
|
44
58
|
|
@@ -47,7 +61,7 @@ module Effective
|
|
47
61
|
when :inline
|
48
62
|
false
|
49
63
|
else
|
50
|
-
|
64
|
+
DEFAULT_FEEDBACK_OPTIONS
|
51
65
|
end
|
52
66
|
end
|
53
67
|
|
@@ -63,9 +77,9 @@ module Effective
|
|
63
77
|
def wrapper_options
|
64
78
|
case layout
|
65
79
|
when :horizontal
|
66
|
-
|
80
|
+
HORIZONTAL_WRAPPER_OPTIONS
|
67
81
|
else
|
68
|
-
|
82
|
+
VERTICAL_WRAPPER_OPTIONS
|
69
83
|
end
|
70
84
|
end
|
71
85
|
|
@@ -166,7 +180,7 @@ module Effective
|
|
166
180
|
|
167
181
|
invalid = object.errors[name].to_sentence.presence if object.respond_to?(:errors)
|
168
182
|
invalid ||= options[:feedback][:invalid].delete(:text).presence
|
169
|
-
invalid ||= [("can't be blank" if options[:input][:required]), ('must be valid' if validated?(name))].compact.join(' and ').presence
|
183
|
+
invalid ||= [("can't be blank" if options[:input][:required]), ('must be valid' if validated?(name))].tap(&:compact!).join(' and ').presence
|
170
184
|
invalid ||= "can't be blank or is invalid"
|
171
185
|
|
172
186
|
valid = options[:feedback][:valid].delete(:text) || 'Looks good!'
|
@@ -268,7 +282,7 @@ module Effective
|
|
268
282
|
item_value = (item.send(value_method).to_s.parameterize.presence rescue nil)
|
269
283
|
end
|
270
284
|
|
271
|
-
[tag_id, item_value, object_id].compact.join('_')
|
285
|
+
[tag_id, item_value, object_id].tap(&:compact!).join('_')
|
272
286
|
end
|
273
287
|
|
274
288
|
private
|
@@ -282,7 +296,7 @@ module Effective
|
|
282
296
|
# effective_bootstrap specific options
|
283
297
|
layout = options.delete(:layout) # Symbol
|
284
298
|
wrapper = options.delete(:wrapper) # Hash
|
285
|
-
input_group = { append: options.delete(:append), prepend: options.delete(:prepend), input_group: options.delete(:input_group) }.compact
|
299
|
+
input_group = { append: options.delete(:append), prepend: options.delete(:prepend), input_group: options.delete(:input_group) }.tap(&:compact!)
|
286
300
|
|
287
301
|
feedback = options.delete(:feedback) # Hash
|
288
302
|
label = options.delete(:label) # String or Hash
|
@@ -317,11 +331,11 @@ module Effective
|
|
317
331
|
# Server side validation
|
318
332
|
if has_error?
|
319
333
|
if has_error?(name)
|
320
|
-
options[:input][:class] = [options[:input][:class]
|
334
|
+
options[:input][:class] = (options[:input][:class] ? "#{options[:input][:class]} is-invalid" : 'is-invalid')
|
321
335
|
elsif reset_feedback?
|
322
336
|
# Nothing
|
323
337
|
else
|
324
|
-
options[:input][:class] = [options[:input][:class]
|
338
|
+
options[:input][:class] = (options[:input][:class] ? "#{options[:input][:class]} is-valid" : 'is-valid')
|
325
339
|
end
|
326
340
|
end
|
327
341
|
|
@@ -333,7 +347,7 @@ module Effective
|
|
333
347
|
options[:input][:readonly] = 'readonly'
|
334
348
|
|
335
349
|
unless options[:input][:class].to_s.include?('form-control-plaintext')
|
336
|
-
options[:input][:class] = options[:input][:class].
|
350
|
+
options[:input][:class] = (options[:input][:class] || '').sub('form-control', 'form-control-plaintext')
|
337
351
|
end
|
338
352
|
end
|
339
353
|
|
@@ -347,17 +361,17 @@ module Effective
|
|
347
361
|
end
|
348
362
|
|
349
363
|
def merge_defaults!(obj, defaults)
|
350
|
-
defaults =
|
364
|
+
defaults = EMPTY_HASH if defaults.nil?
|
351
365
|
|
352
366
|
case obj
|
353
367
|
when false
|
354
368
|
false
|
355
369
|
when nil, true
|
356
|
-
defaults
|
370
|
+
defaults.dup
|
357
371
|
when String
|
358
372
|
defaults.merge(text: obj)
|
359
373
|
when Hash
|
360
|
-
html_classes = (obj[:class].
|
374
|
+
html_classes = ((obj[:class] || '').split(' ') + (defaults[:class] || '').split(' ')).uniq
|
361
375
|
|
362
376
|
# Try to smart merge bootstrap classes
|
363
377
|
if (exclusive = html_classes.select { |c| c.include?('-') }).length > 1
|
@@ -421,11 +435,11 @@ module Effective
|
|
421
435
|
end
|
422
436
|
|
423
437
|
def sanitized_object_name
|
424
|
-
@builder.object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
|
438
|
+
@sanitized_object_name ||= @builder.object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
|
425
439
|
end
|
426
440
|
|
427
441
|
def sanitized_method_name
|
428
|
-
name.to_s.sub(/\?$/, "")
|
442
|
+
@sanitized_method_name ||= name.to_s.sub(/\?$/, "")
|
429
443
|
end
|
430
444
|
|
431
445
|
def input_js_options_method_name
|
@@ -34,7 +34,7 @@ module Effective
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def input_js_options
|
37
|
-
{ 'data-input-js-options' => JSON.generate({method_name: input_js_options_method_name}.merge(logic_options)) }
|
37
|
+
{ 'data-input-js-options' => JSON.generate({method_name: input_js_options_method_name}.merge!(logic_options)) }
|
38
38
|
end
|
39
39
|
|
40
40
|
def input_js_options_method_name
|