From fe8d8ccc93d5fdd28c4c6b4bae2d73e81608a45e Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Mon, 3 May 2021 18:08:26 +1200 Subject: [PATCH] WIP --- lib/custom_wizard/mapper.rb | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/custom_wizard/mapper.rb b/lib/custom_wizard/mapper.rb index c1187b0f..550ee74b 100644 --- a/lib/custom_wizard/mapper.rb +++ b/lib/custom_wizard/mapper.rb @@ -215,6 +215,7 @@ class CustomWizard::Mapper def interpolate(string, opts = { user: true, wizard: true, value: true, template: false }) return string if string.blank? + int_data = prepare_data_for_interpolation if opts[:user] string.gsub!(/u\{(.*?)\}/) do |match| @@ -227,7 +228,7 @@ class CustomWizard::Mapper if opts[:wizard] string.gsub!(/w\{(.*?)\}/) do |match| - value = recurse(data, [*$1.split('.')]) + value = recurse(int_data, [*$1.split('.')]) value.present? ? value : '' end end @@ -250,7 +251,7 @@ class CustomWizard::Mapper if opts[:template] template = Liquid::Template.parse(string) - string = template.render(data) + string = template.render(int_data) end string @@ -262,4 +263,19 @@ class CustomWizard::Mapper result = data[k] keys.empty? ? result : self.recurse(result, keys) end + + def prepare_data_for_interpolation + result = {} + + data.each do |key, value| + if value.is_a?(Hash) + result["#{key}_url"] = value[:url] if value[:url] + result["#{key}_id"] = value[:id] if value[:id] + else + result[key] = value + end + end + + result + end end