82: def result(string = nil)
83: if string
84: self.string = string
85: template_source = "inline template"
86: else
87: template_source = file
88: end
89:
90:
91:
92:
93: benchmark(:debug, "Bound template variables for #{template_source}") do
94: scope.to_hash.each { |name, value|
95: if name.kind_of?(String)
96: realname = name.gsub(/[^\w]/, "_")
97: else
98: realname = name
99: end
100: instance_variable_set("@#{realname}", value)
101: }
102: end
103:
104: result = nil
105: benchmark(:debug, "Interpolated template #{template_source}") do
106: template = ERB.new(self.string, 0, "-")
107: result = template.result(binding)
108: end
109:
110: result
111: end