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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4538dcdf672ff18dadb24146b5186498ffad746ff81d736fbfd24ba8f23a7f89
4
- data.tar.gz: b0a95bd9c6d58c1a3cf86da55a871c5d5da85faa4296d9d5de3201bd6b45ba67
3
+ metadata.gz: c99ee9149a14d12b358d091ad6cebb80daf48170b609911e12d219d7ce5419af
4
+ data.tar.gz: 70107ccde4ca9fb2b7913ed8f262c8086cd15889bb27e79d4c4ba4c1f22f95d4
5
5
  SHA512:
6
- metadata.gz: 653f533b1ae794be6558a9da86c99fc4c69bab5fe19c85a16395a10b24d3c8d43c4878386586006dea73d1380177c09ffeb5fca5986dc317b452f5a003251ea9
7
- data.tar.gz: eedc133811ffea31458b65ae3d2c76a2562b410ac285d25bdf07056568cc0ac587b708b310bcedc278f180bf769970ee5996f27afde0bd4ac0d04e2999bf76d4
6
+ metadata.gz: c4b8aa210f3a582a110c1eca6959c6238c5f897381126b958f584cea4d51e60f7218435a113c0e50b4031a1f7cf6bc39b7ab1b3cfdcfe276b33c5f1a5f511485
7
+ data.tar.gz: 5ec8f4f333bb7e7ac46fdeaf1d47583b38732ddfbb157390efa9968b140a0640f35c7734b905d901d89247ad957110b557b3fed5122425666ca4242eeda08edd
@@ -2,9 +2,6 @@
2
2
 
3
3
  @import 'effective_checks/input';
4
4
  @import 'effective_datetime/input';
5
- @import 'effective_date/input';
6
- @import 'effective_time/input';
7
-
8
5
  @import 'effective_file/input';
9
6
  @import 'effective_rich_text_area/input';
10
7
  @import 'effective_select/input';
@@ -1,4 +1,4 @@
1
- .trix-content {
1
+ .effective_rich_text_area {
2
2
  height: 100%;
3
3
  border-color: #ccc;
4
4
 
@@ -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-#{''.object_id}"
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 = btn_class.presence || 'btn-outline-primary'
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
- button = content_tag(:button, class: "btn #{btn_class} dropdown-toggle" + (split ? " dropdown-toggle-split" : ''), type: 'button', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false) do
92
- btn_content || content_tag(:span, 'Toggle Dropdown', class: 'sr-only')
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, class: ['dropdown-menu', ('dropdown-menu-right' if right)].compact.join(' '))
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, class: ['dropdown-menu', ('dropdown-menu-right' if right)].compact.join(' '))
120
+ content_tag(:div, @_dropdown_link_tos.join.html_safe, menu_opts)
99
121
  end
100
122
 
101
- retval = if split
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: ['btn-group', variation.to_s.presence].compact.join(' '), role: 'group') do
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') do
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], 'dropdown-item'].compact.join(' ')
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] = [options[:class], 'btn', btn_class].compact.join(' ')
166
+ options[:class] = (options[:class] ? "btn #{btn_class} #{options[:class]}" : "btn #{btn_class}")
147
167
  else
148
- options[:class] = [options[:class], 'dropdown-item'].compact.join(' ')
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
- { input_group: { class: 'input-group' }, prepend: false, append: false }
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
- { class: 'col-sm-2 col-form-label'}
51
+ HORIZONTAL_LABEL_OPTIONS
38
52
  when :inline
39
- { class: 'sr-only' }
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
- { valid: { class: 'valid-feedback' }, invalid: { class: 'invalid-feedback' } }
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
- { class: 'form-group row' }
80
+ HORIZONTAL_WRAPPER_OPTIONS
67
81
  else
68
- { class: 'form-group' }
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], 'is-invalid'].compact.join(' ')
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], 'is-valid'].compact.join(' ')
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].to_s.sub('form-control', 'form-control-plaintext')
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 = {} if defaults.nil?
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].to_s.split(' ') + defaults[:class].to_s.split(' ')).uniq
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
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '0.9.0'.freeze
2
+ VERSION = '0.9.5'.freeze
3
3
  end
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.0
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-17 00:00:00.000000000 Z
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';