0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-15 14:22:53 +01:00
Dieser Commit ist enthalten in:
angusmcleod 2021-05-03 18:08:26 +12:00
Ursprung aca0fab74e
Commit fe8d8ccc93

Datei anzeigen

@ -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