turbo_form 0.8.0 → 0.8.1
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/lib/turbo_form/engine.rb +2 -0
- data/lib/turbo_form/form_builder.rb +5 -3
- data/lib/turbo_form/select_renderer.rb +11 -0
- data/lib/turbo_form/system_test_helper.rb +4 -3
- data/lib/turbo_form/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fc9794957819ec051bc06e1b0169a5584a2f183d46532a062ad1ddd056b43a3d
|
|
4
|
+
data.tar.gz: 3cd694c43cb2cdd452b7a0e1a134699b162c7efc2853af9c17c053a40e658c74
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 25d42edc3636bf6be5cd766461242a9723b1f1bbf591aaa9e347ca415598846ccabee52dd8ebcfe13ae6d72fb7ee5b7a0d08a185d0a47347cf334e5e93417d19
|
|
7
|
+
data.tar.gz: f6ddefa9a45e55fe4e1cab8f13768773d649d1174d802aaa12ac8a8dd9b1673730f23d88c2dbc48bfcc1838e4e76dcd98bd0fdbc63165bdf0b25a5a4b6278501
|
data/lib/turbo_form/engine.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'turbo-rails'
|
|
2
2
|
require 'turbo_form/form_helper'
|
|
3
3
|
require 'turbo_form/form_builder'
|
|
4
|
+
require 'turbo_form/select_renderer'
|
|
4
5
|
require 'turbo_form/routes'
|
|
5
6
|
require 'turbo_form/controller'
|
|
6
7
|
|
|
@@ -59,6 +60,7 @@ module TurboForm
|
|
|
59
60
|
|
|
60
61
|
ActionView::Helpers::FormHelper.prepend(TurboForm::FormHelper)
|
|
61
62
|
ActionView::Helpers::FormBuilder.prepend(TurboForm::FormBuilder)
|
|
63
|
+
ActionView::Helpers::Tags::SelectRenderer.prepend(TurboForm::SelectRenderer)
|
|
62
64
|
end
|
|
63
65
|
end
|
|
64
66
|
end
|
|
@@ -78,9 +78,11 @@ module TurboForm
|
|
|
78
78
|
[ options.except(*DYNAMIC_OPTIONS), absorb_trigger(html_options.merge(options.slice(*DYNAMIC_OPTIONS))) ]
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
+
def absorb_trigger(attributes) = FormBuilder.absorb_trigger(attributes, @template)
|
|
82
|
+
|
|
81
83
|
# `dynamic_action:` makes a trigger of its own, on the default event unless
|
|
82
84
|
# `dynamic_trigger:` names one. It takes whatever `url_for` does.
|
|
83
|
-
def absorb_trigger(attributes)
|
|
85
|
+
def self.absorb_trigger(attributes, template)
|
|
84
86
|
return attributes unless attributes.keys.intersect?(DYNAMIC_OPTIONS)
|
|
85
87
|
|
|
86
88
|
trigger, action = attributes.values_at(*DYNAMIC_OPTIONS)
|
|
@@ -88,12 +90,12 @@ module TurboForm
|
|
|
88
90
|
trigger ||= action.present?
|
|
89
91
|
return attributes unless trigger
|
|
90
92
|
|
|
91
|
-
attributes.merge(data: { **attributes[:data].to_h, turbo_form_trigger: trigger_event(trigger), turbo_form_action: (
|
|
93
|
+
attributes.merge(data: { **attributes[:data].to_h, turbo_form_trigger: trigger_event(trigger), turbo_form_action: (template.url_for(action) if action) })
|
|
92
94
|
end
|
|
93
95
|
|
|
94
96
|
# Left blank for `true`, which the script reads as the element's own
|
|
95
97
|
# default: `change` for a select, `input` for a text field, `click` for a
|
|
96
98
|
# button.
|
|
97
|
-
def trigger_event(trigger) = trigger == true ? '' : trigger.to_s
|
|
99
|
+
def self.trigger_event(trigger) = trigger == true ? '' : trigger.to_s
|
|
98
100
|
end
|
|
99
101
|
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module TurboForm
|
|
2
|
+
# Prepended onto ActionView::Helpers::Tags::SelectRenderer, which every select
|
|
3
|
+
# tag renders through -- including those of builder methods other gems add,
|
|
4
|
+
# like country_select's, which hand their html_options straight to the tag.
|
|
5
|
+
module SelectRenderer
|
|
6
|
+
private
|
|
7
|
+
def select_content_tag(option_tags, options, html_options)
|
|
8
|
+
super(option_tags, options, FormBuilder.absorb_trigger(html_options.symbolize_keys, @template_object))
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
module TurboForm::SystemTestHelper
|
|
2
|
-
# Waits for a dynamic form to finish reloading the page.
|
|
2
|
+
# Waits for a dynamic form to finish reloading the page. Reads <html> from the
|
|
3
|
+
# document, so it works inside `within` too.
|
|
3
4
|
#
|
|
4
5
|
# expect_dynamic_form_request { select "Bourbon", from: "Category" }
|
|
5
6
|
# select "Barrel Aged", from: "Flavor"
|
|
6
7
|
def expect_dynamic_form_request
|
|
7
|
-
completed = page.find('html')['data-turbo-form-visits'].to_i + 1
|
|
8
|
+
completed = page.document.find('html')['data-turbo-form-visits'].to_i + 1
|
|
8
9
|
|
|
9
10
|
yield
|
|
10
11
|
|
|
11
|
-
page.assert_selector "html[data-turbo-form-visits='#{completed}']"
|
|
12
|
+
page.document.assert_selector "html[data-turbo-form-visits='#{completed}']"
|
|
12
13
|
end
|
|
13
14
|
end
|
data/lib/turbo_form/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: turbo_form
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andy Cohen
|
|
@@ -85,6 +85,7 @@ files:
|
|
|
85
85
|
- lib/turbo_form/form_builder.rb
|
|
86
86
|
- lib/turbo_form/form_helper.rb
|
|
87
87
|
- lib/turbo_form/routes.rb
|
|
88
|
+
- lib/turbo_form/select_renderer.rb
|
|
88
89
|
- lib/turbo_form/system_test_helper.rb
|
|
89
90
|
- lib/turbo_form/version.rb
|
|
90
91
|
homepage: https://github.com/outlawandy/turbo_form
|