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