From 0b9abf84ccf951ef9bf3e0443f9f6fd0dbf27c9f Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 11 Sep 2019 19:53:51 +1000 Subject: [PATCH] Add support for date variable in field interpolation --- lib/builder.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/builder.rb b/lib/builder.rb index 018fd7ff..f6d426b4 100644 --- a/lib/builder.rb +++ b/lib/builder.rb @@ -53,7 +53,21 @@ class CustomWizard::Builder result end - result.gsub(/w\{(.*?)\}/) { |match| recurse(data, [*$1.split('.')]) } + result = result.gsub(/w\{(.*?)\}/) { |match| recurse(data, [*$1.split('.')]) } + + result.gsub(/v\{(.*?)\}/) do |match| + attrs = $1.split(':') + key = attrs.first + format = attrs.length > 1 ? attrs.last : nil + v = nil + + if key == 'time' + time_format = format.present? ? format : "%B %-d, %Y" + v = Time.now.strftime(time_format) + end + + v + end end def self.recurse(data, keys)