cleaned up quote escaping a little

This commit is contained in:
Javan Makhmali 2010-07-07 18:55:14 -04:00
parent dd15137e41
commit 1472fecc4b

View File

@ -13,21 +13,13 @@ module Whenever
end end
def output def output
template = @options[:template].dup @options[:template].dup.gsub(/:\w+/) do |key|
before_and_after = [$`[-1..-1], $'[0..0]]
template.gsub(/:\w+/) do |key|
single_quote = "'"
double_quote = '"'
char_before = $`[-1..-1]
char_after = $'[0..0]
option = @options[key.sub(':', '').to_sym] option = @options[key.sub(':', '').to_sym]
if char_before == single_quote && char_after == single_quote if before_and_after.all? { |c| c == "'" }
escape_single_quotes(option) escape_single_quotes(option)
elsif char_after == double_quote && char_after == double_quote elsif before_and_after.all? { |c| c == '"' }
escape_double_quotes(option) escape_double_quotes(option)
else else
option option