10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/exclaim/implementations/each_component.rb', line 10
def call(config, env)
items = (config['items'] || config['$each']).to_a
bind_reference = config['yield']
original_env_includes_bind_reference = env.key?(bind_reference)
original_bind_value = env[bind_reference] if original_env_includes_bind_reference
resolved_items = items.map do |item|
env[bind_reference] = item
yield config['do'], env
end
resolved_items.map { |line| line.end_with?("\n") ? line : "#{line}\n" }.join
ensure
env.delete(bind_reference)
env[bind_reference] = original_bind_value if original_env_includes_bind_reference
end
|