effective_bootstrap 0.9.0 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/effective_bootstrap.scss +0 -3
- data/app/assets/stylesheets/effective_rich_text_area/input.scss +1 -1
- data/app/helpers/effective_bootstrap_helper.rb +43 -23
- 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 +2 -4
- data/app/assets/stylesheets/effective_date/input.scss +0 -1
- data/app/assets/stylesheets/effective_time/input.scss +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c99ee9149a14d12b358d091ad6cebb80daf48170b609911e12d219d7ce5419af
|
4
|
+
data.tar.gz: 70107ccde4ca9fb2b7913ed8f262c8086cd15889bb27e79d4c4ba4c1f22f95d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4b8aa210f3a582a110c1eca6959c6238c5f897381126b958f584cea4d51e60f7218435a113c0e50b4031a1f7cf6bc39b7ab1b3cfdcfe276b33c5f1a5f511485
|
7
|
+
data.tar.gz: 5ec8f4f333bb7e7ac46fdeaf1d47583b38732ddfbb157390efa9968b140a0640f35c7734b905d901d89247ad957110b557b3fed5122425666ca4242eeda08edd
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Boostrap4 Helpers
|
2
4
|
|
3
5
|
module EffectiveBootstrapHelper
|
@@ -30,7 +32,7 @@ module EffectiveBootstrapHelper
|
|
30
32
|
def collapse(label, opts = {}, &block)
|
31
33
|
raise 'expected a block' unless block_given?
|
32
34
|
|
33
|
-
id = "collapse-#{
|
35
|
+
id = "collapse-#{String.new.object_id}"
|
34
36
|
show = (opts.delete(:show) == true)
|
35
37
|
|
36
38
|
link_opts = { 'data-toggle': 'collapse', role: 'button', href: "##{id}", 'aria-controls': "##{id}", 'aria-expanded': show }
|
@@ -72,15 +74,27 @@ module EffectiveBootstrapHelper
|
|
72
74
|
# variations can be :dropup, :dropleft, :dropright
|
73
75
|
# split can be true, false
|
74
76
|
# right is to right align things
|
77
|
+
DROPDOWN_SPLIT_OPTS = {class: "btn dropdown-toggle dropdown-toggle-split btn-sm btn-outline-primary", type: 'button', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false}
|
78
|
+
DROPDOWN_UNSPLIT_OPTS= {class: "btn dropdown-toggle btn-sm btn-outline-primary", type: 'button', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false}
|
79
|
+
|
80
|
+
DROPDOWN_DROPLEFT_GROUP_OPTS = {class: 'btn-group'}
|
81
|
+
DROPDOWN_DROPLEFT_OPTS = {class: 'btn-group dropleft', role: 'group'}
|
82
|
+
|
83
|
+
DROPDOWN_MENU_OPTS = {class: 'dropdown-menu'}
|
84
|
+
DROPDOWN_MENU_RIGHT_OPTS = {class: 'dropdown-menu dropdown-menu-right'}
|
85
|
+
|
86
|
+
DROPDOWN_BTN_CLASS = 'btn-sm btn-outline-primary'
|
87
|
+
DROPDOWN_TOGGLE_DROPDOWN = "<span class='sr-only'>Toggle Dropdown</span>".html_safe
|
88
|
+
|
75
89
|
def dropdown(variation: nil, split: true, btn_class: nil, btn_content: nil, right: false, &block)
|
76
90
|
raise 'expected a block' unless block_given?
|
77
91
|
|
78
|
-
btn_class
|
92
|
+
btn_class ||= DROPDOWN_BTN_CLASS
|
79
93
|
|
94
|
+
# Process all dropdown_link_tos
|
80
95
|
@_dropdown_link_tos = []
|
81
96
|
@_dropdown_split = split
|
82
|
-
|
83
|
-
# process dropdown_link_tos
|
97
|
+
@_dropdown_button_class = btn_class
|
84
98
|
yield
|
85
99
|
|
86
100
|
return @_dropdown_link_tos.first if @_dropdown_link_tos.length <= 1
|
@@ -88,31 +102,37 @@ module EffectiveBootstrapHelper
|
|
88
102
|
# Build tags
|
89
103
|
first = @_dropdown_link_tos.first
|
90
104
|
|
91
|
-
|
92
|
-
|
105
|
+
button_opts = (split ? DROPDOWN_SPLIT_OPTS : DROPDOWN_UNSPLIT_OPTS)
|
106
|
+
|
107
|
+
if btn_class != DROPDOWN_BTN_CLASS
|
108
|
+
button_opts[:class] = button_opts[:class].sub(DROPDOWN_BTN_CLASS, btn_class)
|
109
|
+
end
|
110
|
+
|
111
|
+
button = content_tag(:button, button_opts) do
|
112
|
+
btn_content || DROPDOWN_TOGGLE_DROPDOWN
|
93
113
|
end
|
94
114
|
|
115
|
+
menu_opts = (right ? DROPDOWN_MENU_RIGHT_OPTS : DROPDOWN_MENU_OPTS)
|
116
|
+
|
95
117
|
menu = if split
|
96
|
-
content_tag(:div, @_dropdown_link_tos[1..-1].join.html_safe,
|
118
|
+
content_tag(:div, @_dropdown_link_tos[1..-1].join.html_safe, menu_opts)
|
97
119
|
else
|
98
|
-
content_tag(:div, @_dropdown_link_tos.join.html_safe,
|
120
|
+
content_tag(:div, @_dropdown_link_tos.join.html_safe, menu_opts)
|
99
121
|
end
|
100
122
|
|
101
|
-
|
123
|
+
@_dropdown_link_tos = nil
|
124
|
+
|
125
|
+
if split && variation == :dropleft
|
126
|
+
content_tag(:div, DROPDOWN_DROPLEFT_GROUP_OPTS) do
|
127
|
+
content_tag(:div, (button + menu), DROPDOWN_DROPLEFT_OPTS) + first.html_safe
|
128
|
+
end
|
129
|
+
elsif split
|
102
130
|
content_tag(:div, class: 'btn-group') do
|
103
|
-
content_tag(:div, class:
|
104
|
-
[:dropleft].include?(variation) ? (button + menu) : (first + button + menu)
|
105
|
-
end + ([:dropleft].include?(variation) ? first : '').html_safe
|
131
|
+
content_tag(:div, (first + button + menu), class: "btn-group #{variation}", role: 'group')
|
106
132
|
end
|
107
133
|
else
|
108
|
-
content_tag(:div, class: 'dropdown')
|
109
|
-
button + menu
|
110
|
-
end
|
134
|
+
content_tag(:div, (button + menu), class: 'dropdown')
|
111
135
|
end
|
112
|
-
|
113
|
-
@_dropdown_link_tos = nil
|
114
|
-
|
115
|
-
retval
|
116
136
|
end
|
117
137
|
|
118
138
|
# This is a special variant of dropdown
|
@@ -135,17 +155,17 @@ module EffectiveBootstrapHelper
|
|
135
155
|
|
136
156
|
# Works with dots do and dropdown do
|
137
157
|
def dropdown_link_to(label, path, options = {})
|
138
|
-
btn_class = options.delete(:btn_class).presence || 'btn-outline-primary'
|
158
|
+
btn_class = options.delete(:btn_class).presence || @_dropdown_button_class || 'btn-outline-primary'
|
139
159
|
|
140
160
|
unless @_dropdown_link_tos
|
141
|
-
options[:class] = [options[:class]
|
161
|
+
options[:class] = (options[:class] ? "dropdown-item #{options[:class]}" : 'dropdown-item')
|
142
162
|
return link_to(label, path, options)
|
143
163
|
end
|
144
164
|
|
145
165
|
if @_dropdown_link_tos.length == 0 && @_dropdown_split
|
146
|
-
options[:class] =
|
166
|
+
options[:class] = (options[:class] ? "btn #{btn_class} #{options[:class]}" : "btn #{btn_class}")
|
147
167
|
else
|
148
|
-
options[:class] = [options[:class]
|
168
|
+
options[:class] = (options[:class] ? "dropdown-item #{options[:class]}" : 'dropdown-item')
|
149
169
|
end
|
150
170
|
|
151
171
|
@_dropdown_link_tos << link_to(label, path, options)
|
@@ -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
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_bootstrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -575,7 +575,6 @@ files:
|
|
575
575
|
- app/assets/stylesheets/effective_bootstrap/overrides.scss
|
576
576
|
- app/assets/stylesheets/effective_bootstrap_editor.scss
|
577
577
|
- app/assets/stylesheets/effective_checks/input.scss
|
578
|
-
- app/assets/stylesheets/effective_date/input.scss
|
579
578
|
- app/assets/stylesheets/effective_datetime/bootstrap-datetimepicker.scss
|
580
579
|
- app/assets/stylesheets/effective_datetime/input.scss
|
581
580
|
- app/assets/stylesheets/effective_datetime/overrides.scss
|
@@ -590,7 +589,6 @@ files:
|
|
590
589
|
- app/assets/stylesheets/effective_select/overrides.scss
|
591
590
|
- app/assets/stylesheets/effective_select/select2.css
|
592
591
|
- app/assets/stylesheets/effective_select_or_text/input.scss
|
593
|
-
- app/assets/stylesheets/effective_time/input.scss
|
594
592
|
- app/helpers/effective_bootstrap_helper.rb
|
595
593
|
- app/helpers/effective_editor_helper.rb
|
596
594
|
- app/helpers/effective_form_builder_helper.rb
|
@@ -1 +0,0 @@
|
|
1
|
-
@import '../effective_datetime/input';
|
@@ -1 +0,0 @@
|
|
1
|
-
@import '../effective_datetime/input';
|