Permalink
Browse files

special case template compilation under 1.9.1

  • Loading branch information...
1 parent daafed1 commit b05e8da957be51335373bc415f984c9d972234bb @rtomayko committed Sep 10, 2010
Showing with 22 additions and 0 deletions.
  1. +21 −0 lib/tilt.rb
  2. +1 −0 test/tilt_template_test.rb
View
@@ -311,6 +311,27 @@ def self.garbage_collect_compiled_template_method(site, method_name)
end
end
end
+
+ # Special case Ruby 1.9.1's broken yield.
+ #
+ # http://github.com/rtomayko/tilt/commit/20c01a5
+ # http://redmine.ruby-lang.org/issues/show/3601
+ #
+ # Remove when 1.9.2 dominates 1.9.1 installs in the wild.
+ if RUBY_VERSION =~ /^1.9.1/
+ undef compile_template_method
+ def compile_template_method(method_name, locals)
+ source, offset = precompiled(locals)
+ offset += 1
+ CompileSite.module_eval <<-RUBY, eval_file, line - offset
+ def #{method_name}(locals)
+ #{source}
+ end
+ RUBY
+ ObjectSpace.define_finalizer self,
+ Template.compiled_template_method_remover(CompileSite, method_name)
+ end
+ end
end
# Extremely simple template cache implementation. Calling applications
@@ -151,6 +151,7 @@ class FastPerson < Person
end
test "template which accesses a constant with Tilt::CompileSite" do
+ flunk "known broken under 1.9.1" if RUBY_VERSION =~ /^1.9.1/
inst = SourceGeneratingMockTemplate.new { |t| 'Hey #{CONSTANT}!' }
assert_equal "Hey Bob!", inst.render(FastPerson.new("Joe"))
end

0 comments on commit b05e8da

Please sign in to comment.