view_partial_form_builder 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bad5344dd2dcb3ff6332ccce094cafee462d8dad93253e40002d90869908c7d
|
4
|
+
data.tar.gz: 75733a62d1ec0c8266e2577380a70d7459942a4b908ae17e5d98b25cdb6bfb0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f847a1f3ceb8b4c390e94575fd6aeb0b37bf93daf49804c4fbc125b476f896250b14a80cb522c76ce32e33e31457f30cb222f28b978851f58ccaa68f19aa76ed
|
7
|
+
data.tar.gz: 682356c76cf59d62ad176adc0166e6e1ec4c8102b89d3214567cd2abea2721f5d6fdb70259f53b55aed6a955adcbf7f7c48275a37159fdb545caad23275df6cb
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require "view_partial_form_builder/
|
1
|
+
require "view_partial_form_builder/lookup_override"
|
2
2
|
require "view_partial_form_builder/html_attributes"
|
3
3
|
|
4
4
|
module ViewPartialFormBuilder
|
@@ -14,9 +14,9 @@ module ViewPartialFormBuilder
|
|
14
14
|
@template,
|
15
15
|
options,
|
16
16
|
)
|
17
|
-
@
|
18
|
-
|
19
|
-
object_name: object_name,
|
17
|
+
@lookup_override = LookupOverride.new(
|
18
|
+
prefixes: @template.lookup_context.prefixes,
|
19
|
+
object_name: @object_name,
|
20
20
|
view_partial_directory: ViewPartialFormBuilder.view_partial_directory,
|
21
21
|
)
|
22
22
|
end
|
@@ -173,6 +173,17 @@ module ViewPartialFormBuilder
|
|
173
173
|
render_partial("time_zone_select", locals, fallback: -> { super })
|
174
174
|
end
|
175
175
|
|
176
|
+
def date_select(method, options = {}, **html_options)
|
177
|
+
locals = {
|
178
|
+
method: method,
|
179
|
+
options: options,
|
180
|
+
html_options: HtmlAttributes.new(html_options),
|
181
|
+
arguments: [method, options, html_options],
|
182
|
+
}
|
183
|
+
|
184
|
+
render_partial("date_select", locals, fallback: -> { super })
|
185
|
+
end
|
186
|
+
|
176
187
|
def hidden_field(method, **options)
|
177
188
|
@emitted_hidden_id = true if method == :id
|
178
189
|
|
@@ -247,55 +258,55 @@ module ViewPartialFormBuilder
|
|
247
258
|
|
248
259
|
private
|
249
260
|
|
250
|
-
attr_reader :lookup_context
|
251
|
-
|
252
261
|
def render_partial(field, locals, fallback:, &block)
|
253
262
|
options = locals.fetch(:options, {})
|
254
263
|
partial_override = options.delete(:partial)
|
264
|
+
locals = objectify_options(options).merge(locals, form: self)
|
255
265
|
|
256
|
-
if
|
266
|
+
partial = if partial_override.present?
|
267
|
+
find_partial(partial_override, locals, prefixes: [])
|
268
|
+
else
|
269
|
+
find_partial(field, locals, prefixes: prefixes_after(field))
|
270
|
+
end
|
271
|
+
|
272
|
+
if partial.nil? || about_to_recurse_infinitely?(partial)
|
257
273
|
fallback.call
|
258
274
|
else
|
259
|
-
|
260
|
-
|
261
|
-
lookup_context.override do
|
262
|
-
if partial_override.present?
|
263
|
-
render(partial_override, locals, &block)
|
264
|
-
elsif partial_exists?(field)
|
265
|
-
render(field, locals, &block)
|
266
|
-
else
|
267
|
-
fallback.call
|
268
|
-
end
|
269
|
-
end
|
275
|
+
partial.render(@template, locals, &block)
|
270
276
|
end
|
271
277
|
end
|
272
278
|
|
273
|
-
def
|
279
|
+
def find_partial(template_name, locals, prefixes:)
|
274
280
|
template_is_partial = true
|
275
281
|
|
276
|
-
lookup_context.
|
282
|
+
@template.lookup_context.find_all(
|
277
283
|
template_name,
|
278
|
-
|
284
|
+
prefixes,
|
279
285
|
template_is_partial,
|
280
|
-
|
286
|
+
locals.keys,
|
287
|
+
).first
|
281
288
|
end
|
282
289
|
|
283
|
-
def
|
284
|
-
|
285
|
-
|
290
|
+
def prefixes_after(template_name)
|
291
|
+
prefixes = @lookup_override.prefixes
|
292
|
+
current_prefix = current_virtual_path.delete_suffix("/_#{template_name}")
|
293
|
+
|
294
|
+
if prefixes.include?(current_prefix)
|
295
|
+
prefixes.from(prefixes.index(current_prefix).to_i + 1)
|
286
296
|
else
|
287
|
-
|
297
|
+
prefixes
|
288
298
|
end
|
289
299
|
end
|
290
300
|
|
291
|
-
def about_to_recurse_infinitely?(
|
292
|
-
|
293
|
-
|
294
|
-
current_partial = @virtual_path.gsub("/_", "/")
|
295
|
-
currently_rendering_field = current_partial.end_with?(partial_name)
|
301
|
+
def about_to_recurse_infinitely?(partial)
|
302
|
+
partial.virtual_path == current_virtual_path
|
303
|
+
end
|
296
304
|
|
297
|
-
|
298
|
-
|
305
|
+
def current_virtual_path
|
306
|
+
if (current_template = @template.instance_values["current_template"])
|
307
|
+
current_template.virtual_path.to_s
|
308
|
+
else
|
309
|
+
@template.instance_values["virtual_path"].to_s
|
299
310
|
end
|
300
311
|
end
|
301
312
|
end
|
@@ -1,29 +1,12 @@
|
|
1
1
|
module ViewPartialFormBuilder
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
def initialize(overridden_context:, object_name:, view_partial_directory:)
|
2
|
+
class LookupOverride
|
3
|
+
def initialize(prefixes:, object_name:, view_partial_directory:)
|
6
4
|
@object_name = object_name.to_s.pluralize
|
7
|
-
@
|
8
|
-
@prefixes = overridden_context.prefixes.dup.freeze
|
5
|
+
@prefixes = prefixes
|
9
6
|
@view_partial_directory = view_partial_directory
|
10
7
|
end
|
11
8
|
|
12
|
-
def
|
13
|
-
previous_prefixes = overridden_context.prefixes
|
14
|
-
|
15
|
-
overridden_context.prefixes = prefix_overrides
|
16
|
-
|
17
|
-
yield
|
18
|
-
ensure
|
19
|
-
overridden_context.prefixes = previous_prefixes
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
attr_reader :overridden_context, :object_name, :view_partial_directory
|
25
|
-
|
26
|
-
def prefix_overrides
|
9
|
+
def prefixes
|
27
10
|
*overridden_prefixes, root_prefix = @prefixes.dup
|
28
11
|
|
29
12
|
prefixes = [
|
@@ -49,5 +32,9 @@ module ViewPartialFormBuilder
|
|
49
32
|
|
50
33
|
prefixes.uniq
|
51
34
|
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_reader :object_name, :view_partial_directory
|
52
39
|
end
|
53
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view_partial_form_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Doyle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -94,7 +94,7 @@ files:
|
|
94
94
|
- lib/view_partial_form_builder/engine.rb
|
95
95
|
- lib/view_partial_form_builder/form_builder.rb
|
96
96
|
- lib/view_partial_form_builder/html_attributes.rb
|
97
|
-
- lib/view_partial_form_builder/
|
97
|
+
- lib/view_partial_form_builder/lookup_override.rb
|
98
98
|
- lib/view_partial_form_builder/version.rb
|
99
99
|
homepage: https://github.com/seanpdoyle/view_partial_form_builder
|
100
100
|
licenses:
|