Skip to content

Commit e4c9463

Browse files
committed
wip
1 parent 2e69cee commit e4c9463

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

lib/props_template/base_with_extensions.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,18 @@ def handle_collection_item(collection, item, index, options)
8282
if !options[:key]
8383
@traveled_path.push(index)
8484
else
85-
id, val = options[:key]
85+
if (key = options[:key])
86+
val = if item.respond_to? key
87+
item.send(key)
88+
elsif item.is_a? Hash
89+
item[key] || item[key.to_sym]
90+
end
91+
end
8692

87-
if id.nil?
93+
if key.nil?
8894
@traveled_path.push(index)
8995
else
90-
@traveled_path.push("#{id}=#{val}")
96+
@traveled_path.push("#{key}=#{val}")
9197
end
9298
end
9399

lib/props_template/extension_manager.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,16 @@ def has_extensions(options)
4747
def handle(options, item_context = nil)
4848
return yield if !has_extensions(options)
4949

50+
if (key = options[:key]) && item_context
51+
val = if item_context.respond_to? key
52+
item_context.send(key)
53+
elsif item_context.is_a? Hash
54+
item_context[key] || item_context[key.to_sym]
55+
end
56+
end
57+
5058
if options[:defer] && !@deferment.disabled
51-
placeholder = @deferment.handle(options)
59+
placeholder = @deferment.handle(options, key, val)
5260
base.stream.push_value(placeholder)
5361
@fragment.handle(options)
5462
else
@@ -61,14 +69,6 @@ def handle(options, item_context = nil)
6169
yield
6270
end
6371

64-
if (key = options[:key]) && item_context
65-
val = if item_context.respond_to? key
66-
item_context.send(key)
67-
elsif item_context.is_a? Hash
68-
item_context[key] || item_context[key.to_sym]
69-
end
70-
end
71-
7272
if key && val
7373
base.set!(key, val)
7474
end

lib/props_template/extensions/deferment.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,15 @@ def refine_options(options, item = nil)
3434
pass_opts
3535
end
3636

37-
def handle(options)
37+
def handle(options, key, val)
3838
return if !options[:defer]
3939

4040
type, rest = options[:defer]
4141
placeholder = rest[:placeholder]
4242
success_action = rest[:success_action]
4343
fail_action = rest[:fail_action]
4444

45-
if type.to_sym == :auto && options[:key]
46-
key, val = options[:key]
45+
if type.to_sym == :auto && key && val
4746
placeholder = {}
4847
placeholder[key] = val
4948
end

0 commit comments

Comments
 (0)