Permalink
Browse files

use instance_exec to overcome locals problem (>= 1.8.7 only)

Falls back to evaluating template source each time when
instance_exec is not available.
  • Loading branch information...
1 parent 6e1ce25 commit 79de592e55d2a40057e7fc9143bbe4870c6ed8c5 @rtomayko committed Mar 3, 2010
Showing with 8 additions and 2 deletions.
  1. +8 −2 lib/tilt.rb
View
@@ -141,7 +141,13 @@ def compile!
# this method unless they implement either the #template_source or
# template_proc method.
def evaluate(scope, locals, &block)
- scope.instance_eval(&template_proc(locals))
+ if scope.respond_to?(:instance_exec)
+ scope.instance_exec(locals, &template_proc(locals))
+ else
+ source, offset = local_assignment_code(locals)
+ source = [source, template_source].join("\n")
+ scope.instance_eval(source, eval_file, line - offset)
+ end
end
# Return a string containing the (Ruby) source code for the template. The
@@ -157,7 +163,7 @@ def template_proc(locals)
@procs[locals.keys] ||= begin
source, offset = local_assignment_code(locals)
source = [source, template_source].join("\n")
- instance_eval("proc { #{source} }", eval_file, line - offset)
+ instance_eval("proc { |locals| #{source} }", eval_file, line - offset)
end
end

0 comments on commit 79de592

Please sign in to comment.