effective_bootstrap 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b7401c7fc3dab6443b98ff497f5e12fbf14f277
4
- data.tar.gz: a110acdf369a5b250433b95bf4210a14a7df3c88
3
+ metadata.gz: ec5621959449ff4c414d797e5b635b197ad481cb
4
+ data.tar.gz: 98044a2f5c6167489ea5a1ef2b192322faae2726
5
5
  SHA512:
6
- metadata.gz: da584d79497081312420637807902d91e9d5f88d95854798f36f385c2c2058df4862ebea347bc2f373eee487532477741ce706f6b8d7d8e7a18c1b1eabfc330d
7
- data.tar.gz: 11da3d29d21d11e678ec69d9412def8ee90e4d89d52b083d8424b401dba94b7c32b86437269bd45e3c5408d3d4f45abffc37f5e8ea32786b37fee5b487de2ba9
6
+ metadata.gz: 55cf5551994328a7458abe296c1d1e73a02520f9a415a25a2d3437c9bb8f0abbc3cfa8ae0f9716ead00f0889b3b48ffda78824f4558ad7da46b4778e339774be
7
+ data.tar.gz: 9835d86a4c956040965e0cfd54c85c15ef8a3a7d8a559f972e1de883a11a105378c1d337ded67f4a9b2fa050e4076ce67429b10b5c6bf3cd3526ba5871d61e30
data/README.md CHANGED
@@ -91,3 +91,21 @@ $('input.effective_date_time_picker').datetimepicker
91
91
 
92
92
  Any options passed in this way will be used to initialize the underlying javascript libraries.
93
93
 
94
+
95
+ ```
96
+ = f.submit
97
+ = f.submit 'Save 2'
98
+
99
+ = f.submit 'Save', left: true
100
+ = f.submit 'Save', center: true
101
+ = f.submit 'Save', right: true
102
+
103
+ = f.submit 'Save', border: false
104
+ = f.submit 'Save', center: true, border: false
105
+ = f.submit 'Save', left: true, border: false
106
+
107
+ = f.submit('Save', border: false) do
108
+ = f.save 'Okay'
109
+ = f.save 'Mom'
110
+ ```
111
+
@@ -25,12 +25,18 @@ this.EffectiveBootstrap ||= new class
25
25
 
26
26
  if valid
27
27
  $form.addClass('form-is-valid').removeClass('form-is-invalid')
28
- setTimeout((-> $('button[type=submit],input[type=submit]').prop('disabled', true)), 0)
28
+ setTimeout((-> EffectiveBootstrap.disable($form)), 0)
29
29
  else
30
30
  $form.addClass('was-validated').addClass('form-is-invalid').removeClass('form-is-valid')
31
31
 
32
32
  valid
33
33
 
34
+ disable: ($form) ->
35
+ $form.find('[type=submit]').prop('disabled', true)
36
+
37
+ enable: ($form) ->
38
+ $form.removeClass('form-is-valid').find('[type=submit]').removeAttr('disabled')
39
+
34
40
  $ -> EffectiveBootstrap.initialize()
35
41
  $(document).on 'turbolinks:load', -> EffectiveBootstrap.initialize()
36
42
  $(document).on 'cocoon:after-insert', -> EffectiveBootstrap.initialize()
@@ -1,15 +1,26 @@
1
1
  // Submit buttons
2
- .form-actions.form-group {
2
+ .form-actions {
3
+ display: flex;
4
+ align-items: center;
5
+ }
6
+
7
+ .form-actions-bordered {
3
8
  border-top: solid 1px #eee;
4
9
  margin-top: 1rem;
5
10
 
6
- display: flex;
7
- align-items: center;
8
- justify-content: flex-end;
11
+ > * { margin-top: 1rem; }
12
+ }
13
+
14
+ .form-actions.justify-content-start {
15
+ > * { margin-right: 0.5rem; }
16
+ }
17
+
18
+ .form-actions.justify-content-end {
19
+ > * { margin-left: 0.5rem; }
20
+ }
9
21
 
10
- > * {
11
- margin: 1rem 0 0 0.5rem;
12
- }
22
+ .form-actions.justify-content-center {
23
+ > * { margin-left: 0.5rem; }
13
24
  }
14
25
 
15
26
  // Spinner
@@ -66,6 +66,7 @@ module Effective
66
66
  end
67
67
 
68
68
  def save(name = 'Save', options = {})
69
+ (options = name; name = 'Save') if name.kind_of?(Hash)
69
70
  Effective::FormInputs::Save.new(name, options, builder: self).to_html { super(name, options) }
70
71
  end
71
72
 
@@ -74,8 +75,9 @@ module Effective
74
75
  Effective::FormInputs::Select.new(name, options, builder: self).to_html
75
76
  end
76
77
 
77
- def submit(name = 'Submit', options = {})
78
- Effective::FormInputs::Submit.new(name, options, builder: self).to_html { super(name, options) }
78
+ def submit(name = 'Save', options = {}, &block)
79
+ (options = name; name = 'Save') if name.kind_of?(Hash)
80
+ Effective::FormInputs::Submit.new(name, options, builder: self).to_html(&block)
79
81
  end
80
82
 
81
83
  def static_field(name, options = {}, &block)
@@ -3,6 +3,8 @@ module Effective
3
3
  attr_accessor :name, :options
4
4
 
5
5
  BLANK = ''.html_safe
6
+ EXCLUSIVE_CLASS_PREFIXES = [] # None
7
+ EXCLUSIVE_CLASS_SUFFIXES = ['-primary', '-secondary', '-success', '-danger', '-warning', '-info', '-light', '-dark']
6
8
 
7
9
  delegate :object, to: :@builder
8
10
  delegate :capture, :content_tag, :link_to, :icon, to: :@template
@@ -284,7 +286,22 @@ module Effective
284
286
  when String
285
287
  defaults.merge(text: obj)
286
288
  when Hash
289
+ html_classes = (obj[:class].to_s.split(' ') + defaults[:class].to_s.split(' ')).uniq
290
+
291
+ # Try to smart merge bootstrap classes
292
+ if (exclusive = html_classes.select { |c| c.include?('-') }).length > 1
293
+ EXCLUSIVE_CLASS_PREFIXES.each do |prefix|
294
+ prefixed = exclusive.select { |c| c.start_with?(prefix) }
295
+ prefixed[1..-1].each { |c| html_classes.delete(c) } if prefixed.length > 1
296
+ end
297
+
298
+ suffixed = exclusive.select { |c| EXCLUSIVE_CLASS_SUFFIXES.any? { |suffix| c.end_with?(suffix) } }
299
+ suffixed[1..-1].each { |c| html_classes.delete(c) } if suffixed.length > 1
300
+ end
301
+
302
+ obj[:class] = html_classes.join(' ') if html_classes.present?
287
303
  obj.reverse_merge!(defaults)
304
+ obj
288
305
  else
289
306
  raise 'unexpected object'
290
307
  end
@@ -7,7 +7,12 @@ module Effective
7
7
  end
8
8
 
9
9
  def input_html_options
10
- { class: 'form-control-file', multiple: multiple?, direct_upload: true, 'data-progress-template': progress_template }
10
+ {
11
+ class: 'form-control form-control-file btn btn-outline-secondary',
12
+ multiple: multiple?,
13
+ direct_upload: true,
14
+ 'data-progress-template': progress_template
15
+ }
11
16
  end
12
17
 
13
18
  def multiple?
@@ -3,15 +3,26 @@ module Effective
3
3
  class Submit < Effective::FormInput
4
4
 
5
5
  def build_input(&block)
6
- content_tag(:button, name, options[:input])
6
+ icon('spinner') + (block_given? ? capture(&block) : content_tag(:button, name, options[:input]))
7
7
  end
8
8
 
9
9
  def wrapper_options
10
- if layout == :horizontal
11
- { class: 'form-group row form-actions'}
12
- else
13
- { class: 'form-group form-actions'}
14
- end
10
+ border = options.key?(:border) ? options.delete(:border) : true
11
+ left = options.delete(:left) || false
12
+ center = options.delete(:center) || false
13
+ right = options.delete(:right) || false
14
+ right = true unless (left || center)
15
+
16
+ classes = [
17
+ ('row' if layout == :horizontal),
18
+ 'form-group form-actions',
19
+ ('form-actions-bordered' if border),
20
+ ('justify-content-start' if left && layout == :vertical),
21
+ ('justify-content-center' if center && layout == :vertical),
22
+ ('justify-content-end' if right && layout == :vertical)
23
+ ].compact.join(' ')
24
+
25
+ { class: classes }
15
26
  end
16
27
 
17
28
  def input_html_options
@@ -23,18 +34,19 @@ module Effective
23
34
  end
24
35
 
25
36
  def feedback_options
26
- case layout
27
- when :inline
28
- false
29
- else
30
- {
31
- valid: { class: 'valid-feedback', text: 'Looks good! Submitting...' },
32
- invalid: {
33
- class: 'invalid-feedback',
34
- text: 'one or more errors are present. please fix the errors above and try again.'
35
- }
36
- }
37
- end
37
+ # case layout
38
+ # when :inline
39
+ # false
40
+ # else
41
+ # {
42
+ # valid: { class: 'valid-feedback', text: 'Looks good! Submitting...' },
43
+ # invalid: {
44
+ # class: 'invalid-feedback',
45
+ # text: 'one or more errors are present. please fix the errors above and try again.'
46
+ # }
47
+ # }
48
+ # end
49
+ false
38
50
  end
39
51
 
40
52
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '0.0.5'.freeze
2
+ VERSION = '0.0.6'.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.0.5
4
+ version: 0.0.6
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: 2018-03-28 00:00:00.000000000 Z
11
+ date: 2018-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails