polaris_form_builder 0.1.0 → 0.1.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/polaris_form_builder/form_builder.rb +24 -13
- data/lib/polaris_form_builder/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a4af632b1d028e2adca5c77ef12e64bfdf3b031322dd31339d3b9999be009f0e
|
|
4
|
+
data.tar.gz: 8303bdedb09f4c716d9f5114e67c00b02e9f7c6ce5f2f5b635c00b858cc513b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c1f62dc62a10bca07e74f5c61fc4393534f5b627501dbed88a5d98f857da19a62560fb00b9c1effb1e86f7e0e4ce92f78c76ff751c121916ba3d6c4b91edc5eb
|
|
7
|
+
data.tar.gz: acc679cfdf24f1fad0d2691c2f79f38957807564aa00a9485fd06a94d9766d86f93f59bc6442150041a02c7eb933c0308da938845b0385605e354644824a3990
|
|
@@ -66,7 +66,7 @@ module PolarisFormBuilder
|
|
|
66
66
|
super(method, choices, options.merge(attrs), html_options)
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
content =
|
|
69
|
+
content = @template.capture(&block) if block_given?
|
|
70
70
|
|
|
71
71
|
select_tag = Tag.new("s-select", "select")
|
|
72
72
|
select_tag.attr("value", object.send(method)) if object.respond_to?(method)
|
|
@@ -117,7 +117,14 @@ module PolarisFormBuilder
|
|
|
117
117
|
end
|
|
118
118
|
|
|
119
119
|
def choice_list(method, options = {}, &block)
|
|
120
|
-
|
|
120
|
+
options = options.dup
|
|
121
|
+
choices = options.delete(:choices)
|
|
122
|
+
error = method_error(method)
|
|
123
|
+
attrs = options.merge(name: @template.field_name(object_name, method))
|
|
124
|
+
attrs[:error] = error if error
|
|
125
|
+
content = choice_list_content(choices, &block)
|
|
126
|
+
|
|
127
|
+
@template.content_tag("s-choice-list", content, attrs)
|
|
121
128
|
end
|
|
122
129
|
|
|
123
130
|
private
|
|
@@ -138,22 +145,26 @@ module PolarisFormBuilder
|
|
|
138
145
|
|
|
139
146
|
def polaris_input(tag_name, html, &block)
|
|
140
147
|
tag = Tag.new(tag_name, "input", remove_attributes: %w[type size])
|
|
141
|
-
@template.
|
|
148
|
+
content = @template.capture(&block) if block_given?
|
|
149
|
+
@template.raw tag.apply(html, content)
|
|
142
150
|
end
|
|
143
151
|
|
|
144
|
-
def
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
def choice_list_content(choices, &block)
|
|
153
|
+
if block_given?
|
|
154
|
+
@template.capture(&block)
|
|
155
|
+
elsif choices.present?
|
|
156
|
+
@template.safe_join(choices.map { |choice| choice_list_item(choice) })
|
|
157
|
+
end
|
|
158
|
+
end
|
|
151
159
|
|
|
152
|
-
|
|
153
|
-
|
|
160
|
+
def choice_list_item(choice)
|
|
161
|
+
label, value = if choice.is_a?(Array)
|
|
162
|
+
[ choice[0], choice[1] ]
|
|
154
163
|
else
|
|
155
|
-
|
|
164
|
+
[ choice, choice ]
|
|
156
165
|
end
|
|
166
|
+
|
|
167
|
+
@template.content_tag("s-choice", label, value: value)
|
|
157
168
|
end
|
|
158
169
|
end
|
|
159
170
|
end
|