def convert(input)
src = "_buf = '';"
pos = 0
input.scan(EMBEDDED_PATTERN) do |indicator, code|
m = Regexp.last_match
text = input[pos...m.begin(0)]
pos = m.end(0)
text.gsub!(/['\\]/, '\\\\\&')
src << " _buf << '" << text << "';" unless text.empty?
if !indicator
src << code << ";"
elsif indicator == '#'
src << ("\n" * code.count("\n"))
else
src << " _buf << (" << code << ").to_s;"
end
end
rest = pos == 0 ? input : input[pos..-1]
rest.gsub!(/['\\]/, '\\\\\&')
src << " _buf << '" << rest << "';" unless rest.empty?
src << "\n_buf.to_s\n"
return src
end