# File lib/erubis/tiny.rb, line 88
88: def convert(input)
89: src = "_buf = '';" # preamble
90: pos = 0
91: input.scan(EMBEDDED_PATTERN) do |lspace, stmt, rspace, indicator, expr|
92: match = Regexp.last_match
93: len = match.begin(0) - pos
94: text = input[pos, len]
95: pos = match.end(0)
96: #src << " _buf << '" << escape_text(text) << "';"
97: text.gsub!(/['\\]/, '\\\&')
98: src << " _buf << '" << text << "';" unless text.empty?
99: if stmt # <?rb ... ?>
100: if lspace && rspace
101: src << "#{lspace}#{stmt}#{rspace}"
102: else
103: src << " _buf << '" << lspace << "';" if lspace
104: src << stmt << ";"
105: src << " _buf << '" << rspace << "';" if rspace
106: end
107: else # ${...}, $!{...}
108: if !indicator
109: src << " _buf << " << @escape << "(" << expr << ");"
110: elsif indicator == '!'
111: src << " _buf << (" << expr << ").to_s;"
112: end
113: end
114: end
115: #rest = $' || input # ruby1.8
116: rest = pos == 0 ? input : input[pos..1] # ruby1.9
117: #src << " _buf << '" << escape_text(rest) << "';"
118: rest.gsub!(/['\\]/, '\\\&')
119: src << " _buf << '" << rest << "';" unless rest.empty?
120: src << "\n_buf.to_s\n" # postamble
121: return src
122: end
# File lib/erubis/tiny.rb, line 132
132: def evaluate(_context=Object.new)
133: if _context.is_a?(Hash)
134: _obj = Object.new
135: _context.each do |k, v| _obj.instance_variable_set("@#{k}", v) end
136: _context = _obj
137: end
138: _context.instance_eval @src
139: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.