<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -576,9 +576,19 @@ module Sinatra
     private 
     
       def render_erb(content, options = {})
-        ::ERB.new(content).result(binding)
+        locals_opt = options.delete(:locals) || {}
+
+        locals_code = &quot;&quot;
+        locals_hash = {} 
+        locals_opt.each do |key, value|
+          locals_code &lt;&lt; &quot;#{key} = locals_hash[:#{key}]\n&quot;
+          locals_hash[:&quot;#{key}&quot;] = value
+        end
+ 
+        body = ::ERB.new(content).src
+        eval(&quot;#{locals_code}#{body}&quot;, binding)
       end
-      
+
   end
 
   module Haml</diff>
      <filename>lib/sinatra.rb</filename>
    </modified>
    <modified>
      <diff>@@ -23,6 +23,26 @@ context &quot;Erb&quot; do
       body.should == '2'
 
     end
+
+    specify &quot;should take an options hash with :locals set with a string&quot; do
+      get '/locals' do
+        erb '&lt;%= foo %&gt;', :locals =&gt; {:foo =&gt; &quot;Bar&quot;}
+      end
+
+      get_it '/locals'
+      should.be.ok
+      body.should == 'Bar'
+    end
+
+    specify &quot;should take an options hash with :locals set with a complex object&quot; do
+      get '/locals-complex' do
+        erb '&lt;%= foo[0] %&gt;', :locals =&gt; {:foo =&gt; [&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;]}
+      end
+
+      get_it '/locals-complex'
+      should.be.ok
+      body.should == 'foo'
+    end
   end
   
   context &quot;with layouts&quot; do</diff>
      <filename>test/erb_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>07f254733192d114d59143b997ee51a4ca003a48</id>
    </parent>
  </parents>
  <author>
    <name>Chris Schneider</name>
    <email>chris@christopher-schneider.com</email>
  </author>
  <url>http://github.com/cschneid/sinatra/commit/f2733e8785b8b943f4114d4a8ff25b5ef632a1ff</url>
  <id>f2733e8785b8b943f4114d4a8ff25b5ef632a1ff</id>
  <committed-date>2008-05-27T19:16:23-07:00</committed-date>
  <authored-date>2008-05-27T19:09:45-07:00</authored-date>
  <message>Add :locals option for erb.  General approach and some of the code was borrowed from rails (compilable.rb)</message>
  <tree>1c063b35a5cdc7c30bf0d373d59fa2a05ac078d9</tree>
  <committer>
    <name>bmizerany</name>
    <email>blake.mizerany@gmail.com</email>
  </committer>
</commit>
