template_form 0.4.5 → 0.4.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 +4 -4
- data/README.md +7 -0
- data/lib/template_form/base_input.rb +4 -1
- data/lib/template_form/form_builder.rb +3 -0
- data/lib/template_form/form_helper.rb +1 -0
- data/lib/template_form/grouped_select_input.rb +5 -1
- data/lib/template_form/select_input.rb +3 -0
- data/lib/template_form/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2dffdc1b897b10460d029723d7f286651388e59c7a637eded104e78898edbab
|
4
|
+
data.tar.gz: bf8b340b369c8113fae4d5d6311a83383de8cb9bd832e10fbe41c2d7917cc960
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ac600b29d24bb2d9bce1b63d7d1d75cd9b94b7c25c836ab3c23a734db71f2f22b361be6a49b7b16055585c7b3dc642e5f010d3846831ea0ed152cea5e26412f
|
7
|
+
data.tar.gz: 1b2e8c6caf8c4fa2d897ae42941c6d4d6f234c9bee95422f307614dc69836146cb1f87a3e451321e033113bcce0e003f00b2b2acbf113c5eb85b0a3ecec47371
|
data/README.md
CHANGED
@@ -159,6 +159,13 @@ def render
|
|
159
159
|
end
|
160
160
|
```
|
161
161
|
|
162
|
+
You also have access to the `view` in which the template is contained. This is handy if you need to call methods on the view inside your template. For example, translating values for data attributes.
|
163
|
+
|
164
|
+
```erb
|
165
|
+
<div data-controller="foo" data-foo-show-value=view.translate("foo.show")>
|
166
|
+
</div>
|
167
|
+
```
|
168
|
+
|
162
169
|
### Attribute types and form inputs
|
163
170
|
|
164
171
|
Template Form looks up the type for the attribute, falling back to `:string` if it can't find one. Then it uses the corresponding form input.
|
@@ -6,6 +6,7 @@ module TemplateForm
|
|
6
6
|
def initialize(builder, attribute_name, options)
|
7
7
|
@builder = builder
|
8
8
|
@attribute_name = attribute_name
|
9
|
+
@view = options.delete(:view)
|
9
10
|
|
10
11
|
@form_type = options.delete(:form_type) || builder.form_type
|
11
12
|
|
@@ -37,7 +38,8 @@ module TemplateForm
|
|
37
38
|
hint_text: hint_text,
|
38
39
|
|
39
40
|
options: options,
|
40
|
-
errors: errors
|
41
|
+
errors: errors,
|
42
|
+
view: view
|
41
43
|
).html_safe
|
42
44
|
end
|
43
45
|
|
@@ -48,6 +50,7 @@ module TemplateForm
|
|
48
50
|
form_type
|
49
51
|
builder
|
50
52
|
attribute_name
|
53
|
+
view
|
51
54
|
|
52
55
|
has_label
|
53
56
|
label_text
|
@@ -22,6 +22,7 @@ module TemplateForm
|
|
22
22
|
# associated record, the second and subsequent ones have the
|
23
23
|
# correct form type.
|
24
24
|
@form_type = options[:form_type] || TemplateForm.form_type
|
25
|
+
@view = options[:view]
|
25
26
|
end
|
26
27
|
|
27
28
|
def input(attribute_name, options = {})
|
@@ -31,6 +32,8 @@ module TemplateForm
|
|
31
32
|
|
32
33
|
options[:type] ||= 'password' if attribute_name.match(/password/)
|
33
34
|
|
35
|
+
options.merge! view: @view
|
36
|
+
|
34
37
|
input_for(attribute_type).new(self, attribute_name, options).render
|
35
38
|
end
|
36
39
|
|
@@ -5,6 +5,7 @@ module TemplateForm
|
|
5
5
|
|
6
6
|
def template_form_with(model: nil, scope: nil, url: nil, format: nil, **options, &block)
|
7
7
|
options[:builder] = TemplateForm::FormBuilder
|
8
|
+
options[:view] = self
|
8
9
|
|
9
10
|
with_template_form_field_error_proc do
|
10
11
|
form_with model: model, scope: scope, url: url, format: format, **options, &block
|
@@ -8,6 +8,7 @@ module TemplateForm
|
|
8
8
|
def initialize(builder, attribute_name, options)
|
9
9
|
@builder = builder
|
10
10
|
@attribute_name = attribute_name
|
11
|
+
@view = options.delete(:view)
|
11
12
|
|
12
13
|
@form_type = options.delete(:form_type) || builder.form_type
|
13
14
|
|
@@ -54,7 +55,9 @@ module TemplateForm
|
|
54
55
|
group_method: group_method,
|
55
56
|
group_label_method: group_label_method,
|
56
57
|
option_key_method: option_key_method,
|
57
|
-
option_value_method: option_value_method
|
58
|
+
option_value_method: option_value_method,
|
59
|
+
|
60
|
+
view: view
|
58
61
|
).html_safe
|
59
62
|
end
|
60
63
|
|
@@ -62,6 +65,7 @@ module TemplateForm
|
|
62
65
|
|
63
66
|
attr_reader *%i[
|
64
67
|
collection
|
68
|
+
view
|
65
69
|
|
66
70
|
html_options
|
67
71
|
|
@@ -8,6 +8,7 @@ module TemplateForm
|
|
8
8
|
def initialize(builder, attribute_name, options)
|
9
9
|
@builder = builder
|
10
10
|
@attribute_name = attribute_name
|
11
|
+
@view = options.delete(:view)
|
11
12
|
|
12
13
|
@form_type = options.delete(:form_type) || builder.form_type
|
13
14
|
|
@@ -37,6 +38,7 @@ module TemplateForm
|
|
37
38
|
builder,
|
38
39
|
attribute_name: attribute_name,
|
39
40
|
collection: collection,
|
41
|
+
view: view,
|
40
42
|
|
41
43
|
has_label: has_label,
|
42
44
|
label_text: label_text,
|
@@ -58,6 +60,7 @@ module TemplateForm
|
|
58
60
|
|
59
61
|
attr_reader *%i[
|
60
62
|
collection
|
63
|
+
view
|
61
64
|
|
62
65
|
html_options
|
63
66
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: template_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
requirements: []
|
140
|
-
rubygems_version: 3.
|
140
|
+
rubygems_version: 3.2.33
|
141
141
|
signing_key:
|
142
142
|
specification_version: 4
|
143
143
|
summary: A template-based form builder for Rails.
|