1
0
Fork 0

Commits vergleichen

...

1 Commit

Autor SHA1 Nachricht Datum
angusmcleod
fe8d8ccc93 WIP 2021-05-03 18:08:26 +12:00

Datei anzeigen

@ -215,6 +215,7 @@ class CustomWizard::Mapper
def interpolate(string, opts = { user: true, wizard: true, value: true, template: false }) def interpolate(string, opts = { user: true, wizard: true, value: true, template: false })
return string if string.blank? return string if string.blank?
int_data = prepare_data_for_interpolation
if opts[:user] if opts[:user]
string.gsub!(/u\{(.*?)\}/) do |match| string.gsub!(/u\{(.*?)\}/) do |match|
@ -227,7 +228,7 @@ class CustomWizard::Mapper
if opts[:wizard] if opts[:wizard]
string.gsub!(/w\{(.*?)\}/) do |match| string.gsub!(/w\{(.*?)\}/) do |match|
value = recurse(data, [*$1.split('.')]) value = recurse(int_data, [*$1.split('.')])
value.present? ? value : '' value.present? ? value : ''
end end
end end
@ -250,7 +251,7 @@ class CustomWizard::Mapper
if opts[:template] if opts[:template]
template = Liquid::Template.parse(string) template = Liquid::Template.parse(string)
string = template.render(data) string = template.render(int_data)
end end
string string
@ -262,4 +263,19 @@ class CustomWizard::Mapper
result = data[k] result = data[k]
keys.empty? ? result : self.recurse(result, keys) keys.empty? ? result : self.recurse(result, keys)
end 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 end