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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6bcd0b60a0df4d1edc4b00f89144a17eab765a8d51e3374abc4fc37c4dbc8a5
4
- data.tar.gz: d641170ee84b65b7cfc22852674fedc102d86629128a5945b90d03a851095a09
3
+ metadata.gz: a4af632b1d028e2adca5c77ef12e64bfdf3b031322dd31339d3b9999be009f0e
4
+ data.tar.gz: 8303bdedb09f4c716d9f5114e67c00b02e9f7c6ce5f2f5b635c00b858cc513b2
5
5
  SHA512:
6
- metadata.gz: 65edcb87ea84066e95edcf7a52286b54a98135b97b82aa44c8b9fcb245dae6ba36f4e9bf40bbefa6bb33f9e923fa861ca63d9e70807a7bc4978a4cd0f751380e
7
- data.tar.gz: 2a6a77e9e8582b672e6bef9386bf9ff4e0ce838365e993f91168cae34a3ad72e7c8dc13acfe4daba6dd0afc7454edec722774ee0282cec2e95d5257d7570fcea
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 = capture_block(&block)
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
- select(method, options.delete(:choices), options, &block)
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.raw tag.apply(html, capture_block(&block))
148
+ content = @template.capture(&block) if block_given?
149
+ @template.raw tag.apply(html, content)
142
150
  end
143
151
 
144
- def capture_block(&block)
145
- return unless block_given?
146
-
147
- # Use the buffer from the block's binding to avoid writing to a different
148
- # output buffer and duplicating content when the builder is reused.
149
- capture_buffer = block.binding.eval("@output_buffer") rescue nil
150
- capture_buffer ||= @template.output_buffer
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
- if capture_buffer.respond_to?(:capture)
153
- capture_buffer.capture(&block)
160
+ def choice_list_item(choice)
161
+ label, value = if choice.is_a?(Array)
162
+ [ choice[0], choice[1] ]
154
163
  else
155
- @template.capture(&block)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PolarisFormBuilder
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polaris_form_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lex Cao