effective_bootstrap 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/effective_bootstrap.js +1 -0
- data/app/assets/javascripts/effective_bootstrap/logic.js.coffee +20 -0
- data/app/models/effective/form_builder.rb +9 -0
- data/app/models/effective/form_inputs/collection_input.rb +4 -0
- data/app/models/effective/form_logic.rb +45 -0
- data/app/models/effective/form_logics/hide_if.rb +28 -0
- data/app/models/effective/form_logics/show_if.rb +28 -0
- data/lib/effective_bootstrap/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ef5c490c21c811d0bab4b33f68d2b45a49e71e5
|
4
|
+
data.tar.gz: fd13c727e25be05f6dd021fa0fa3165562dcf7f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 365573317df114f67454c6331f58fdc869b89c7b5f13ced477098a2b87582395dbfca0d34683805162dfb49b4499cb9a8769fa9afd100ba905d69f2878942efd
|
7
|
+
data.tar.gz: c857d13f1b2e978f363eab1514c2a2936560b802d87418143da60a4d41e1f0f0446061c4dd151cd2fe50fdc92c1986d49834fbaf20a04ef3b9ec67b9cea3bbe4
|
@@ -0,0 +1,20 @@
|
|
1
|
+
(this.EffectiveBootstrap || {}).effective_hide_if = ($element, options) ->
|
2
|
+
|
3
|
+
$affects = $element.closest('form').find("input[name='#{options.name}']")
|
4
|
+
|
5
|
+
$affects.on 'change', (event) ->
|
6
|
+
if $(event.target).val() == options.value
|
7
|
+
$element.hide()
|
8
|
+
else
|
9
|
+
$element.fadeIn()
|
10
|
+
|
11
|
+
(this.EffectiveBootstrap || {}).effective_show_if = ($element, options) ->
|
12
|
+
|
13
|
+
$affects = $element.closest('form').find("input[name='#{options.name}']")
|
14
|
+
|
15
|
+
$affects.on 'change', (event) ->
|
16
|
+
if $(event.target).val() == options.value
|
17
|
+
$element.fadeIn()
|
18
|
+
else
|
19
|
+
$element.hide()
|
20
|
+
|
@@ -132,6 +132,15 @@ module Effective
|
|
132
132
|
Effective::FormInputs::UrlField.new(name, options, builder: self).to_html { super(name, options) }
|
133
133
|
end
|
134
134
|
|
135
|
+
# Logics
|
136
|
+
def hide_if(*args, &block)
|
137
|
+
Effective::FormLogics::HideIf.new(*args, builder: self).to_html(&block)
|
138
|
+
end
|
139
|
+
|
140
|
+
def show_if(*args, &block)
|
141
|
+
Effective::FormLogics::ShowIf.new(*args, builder: self).to_html(&block)
|
142
|
+
end
|
143
|
+
|
135
144
|
end
|
136
145
|
end
|
137
146
|
|
@@ -82,6 +82,10 @@ module Effective
|
|
82
82
|
|
83
83
|
grouped = collection.kind_of?(Hash) && collection.values.first.respond_to?(:to_a)
|
84
84
|
|
85
|
+
if collection.nil?
|
86
|
+
raise "Please include a collection"
|
87
|
+
end
|
88
|
+
|
85
89
|
if grouped? && !grouped && collection.present?
|
86
90
|
raise "Grouped collection expecting a Hash {'Posts' => Post.all, 'Events' => Event.all} or a Hash {'Posts' => [['Post A', 1], ['Post B', 2]], 'Events' => [['Event A', 1], ['Event B', 2]]}"
|
87
91
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Effective
|
2
|
+
class FormLogic
|
3
|
+
attr_accessor :args, :options
|
4
|
+
|
5
|
+
delegate :object, to: :@builder
|
6
|
+
delegate :capture, :content_tag, :link_to, :icon, to: :@template
|
7
|
+
|
8
|
+
# So this takes in the options for an entire form group.
|
9
|
+
def initialize(*args, builder:)
|
10
|
+
@builder = builder
|
11
|
+
@template = builder.template
|
12
|
+
@options ||= {}
|
13
|
+
|
14
|
+
validate!(args)
|
15
|
+
@args = args
|
16
|
+
end
|
17
|
+
|
18
|
+
def validate!(args)
|
19
|
+
raise 'expected one or more argument' if args.blank?
|
20
|
+
end
|
21
|
+
|
22
|
+
# https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/tags/base.rb#L108
|
23
|
+
def tag_name(name, multiple = false, index = nil)
|
24
|
+
sanitized_method_name = name.to_s.sub(/\?$/, "")
|
25
|
+
|
26
|
+
case
|
27
|
+
when @builder.object_name.empty?
|
28
|
+
"#{sanitized_method_name}#{multiple ? "[]" : ""}"
|
29
|
+
when index
|
30
|
+
"#{@builder.object_name}[#{index}][#{sanitized_method_name}]#{multiple ? "[]" : ""}"
|
31
|
+
else
|
32
|
+
"#{@builder.object_name}[#{sanitized_method_name}]#{multiple ? "[]" : ""}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def input_js_options
|
37
|
+
{ 'data-input-js-options' => JSON.generate({method_name: input_js_options_method_name}.merge(logic_options)) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def input_js_options_method_name
|
41
|
+
"effective_#{self.class.name.split('::').last.underscore}"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Effective
|
2
|
+
module FormLogics
|
3
|
+
class HideIf < Effective::FormLogic
|
4
|
+
|
5
|
+
def to_html(&block)
|
6
|
+
content_tag(:div, options.merge(input_js_options), &block)
|
7
|
+
end
|
8
|
+
|
9
|
+
def options
|
10
|
+
{ style: ('display: none;' if hide?) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def logic_options
|
14
|
+
{ name: tag_name(args.first), value: args.second }
|
15
|
+
end
|
16
|
+
|
17
|
+
def validate!(args)
|
18
|
+
raise 'expected two arguments' unless args.length == 2
|
19
|
+
raise "expected object to respond to #{args.first}" unless object.respond_to?(args.first)
|
20
|
+
end
|
21
|
+
|
22
|
+
def hide?
|
23
|
+
object.send(args.first) == args.second
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Effective
|
2
|
+
module FormLogics
|
3
|
+
class ShowIf < Effective::FormLogic
|
4
|
+
|
5
|
+
def to_html(&block)
|
6
|
+
content_tag(:div, options.merge(input_js_options), &block)
|
7
|
+
end
|
8
|
+
|
9
|
+
def options
|
10
|
+
{ style: ('display: none;' unless show?) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def logic_options
|
14
|
+
{ name: tag_name(args.first), value: args.second }
|
15
|
+
end
|
16
|
+
|
17
|
+
def validate!(args)
|
18
|
+
raise 'expected two arguments' unless args.length == 2
|
19
|
+
raise "expected object to respond to #{args.first}" unless object.respond_to?(args.first)
|
20
|
+
end
|
21
|
+
|
22
|
+
def show?
|
23
|
+
object.send(args.first) == args.second
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
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.
|
4
|
+
version: 0.3.0
|
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-
|
11
|
+
date: 2018-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -372,6 +372,7 @@ files:
|
|
372
372
|
- app/assets/javascripts/effective_bootstrap.js
|
373
373
|
- app/assets/javascripts/effective_bootstrap/base.js.coffee
|
374
374
|
- app/assets/javascripts/effective_bootstrap/form.js.coffee
|
375
|
+
- app/assets/javascripts/effective_bootstrap/logic.js.coffee
|
375
376
|
- app/assets/javascripts/effective_checks/initialize.js.coffee
|
376
377
|
- app/assets/javascripts/effective_checks/input.js
|
377
378
|
- app/assets/javascripts/effective_date/initialize.js.coffee
|
@@ -455,6 +456,9 @@ files:
|
|
455
456
|
- app/models/effective/form_inputs/text_field.rb
|
456
457
|
- app/models/effective/form_inputs/time_field.rb
|
457
458
|
- app/models/effective/form_inputs/url_field.rb
|
459
|
+
- app/models/effective/form_logic.rb
|
460
|
+
- app/models/effective/form_logics/hide_if.rb
|
461
|
+
- app/models/effective/form_logics/show_if.rb
|
458
462
|
- app/views/effective/style_guide/__fields.html.haml
|
459
463
|
- app/views/effective/style_guide/__inline_fields.html.haml
|
460
464
|
- app/views/effective/style_guide/_effective_form_with.html.haml
|