Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-10 04:12:53 +01:00
Clarify mapper interpolation
Dieser Commit ist enthalten in:
Ursprung
ca7af31562
Commit
ba7c50b40f
1 geänderte Dateien mit 12 neuen und 9 gelöschten Zeilen
|
@ -179,27 +179,30 @@ class CustomWizard::Mapper
|
||||||
end
|
end
|
||||||
|
|
||||||
def interpolate(string)
|
def interpolate(string)
|
||||||
result = string.gsub(/u\{(.*?)\}/) do |match|
|
string.gsub!(/u\{(.*?)\}/) do |match|
|
||||||
result = ''
|
result = ''
|
||||||
result = user.send($1) if USER_FIELDS.include?($1)
|
result = user.send($1) if USER_FIELDS.include?($1)
|
||||||
result = user.user_profile.send($1) if PROFILE_FIELDS.include?($1)
|
result = user.user_profile.send($1) if PROFILE_FIELDS.include?($1)
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
result = result.gsub(/w\{(.*?)\}/) { |match| recurse(data, [*$1.split('.')]) }
|
string.gsub(/v\{(.*?)\}/) do |match|
|
||||||
|
|
||||||
result.gsub(/v\{(.*?)\}/) do |match|
|
|
||||||
attrs = $1.split(':')
|
attrs = $1.split(':')
|
||||||
key = attrs.first
|
key = attrs.first
|
||||||
format = attrs.length > 1 ? attrs.last : nil
|
value = data[key]
|
||||||
val = nil
|
format = attrs.last if attrs.length > 1
|
||||||
|
result = nil
|
||||||
|
|
||||||
if key == 'time'
|
if key == 'time'
|
||||||
time_format = format.present? ? format : "%B %-d, %Y"
|
time_format = value.present? ? value : "%B %-d, %Y"
|
||||||
val = Time.now.strftime(time_format)
|
return Time.now.strftime(time_format)
|
||||||
end
|
end
|
||||||
|
|
||||||
val
|
if value.present?
|
||||||
|
return recurse(value, [*$1.split('.')])
|
||||||
|
end
|
||||||
|
|
||||||
|
result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Laden …
In neuem Issue referenzieren