Permalink
Browse files

Fix to allow Tilt to render a Tempfile based template.

  • Loading branch information...
1 parent 521705e commit 2936d60c26e172dad20d4575c46031c1aa70db5f @jamesotron jamesotron committed Feb 8, 2012
Showing with 8 additions and 0 deletions.
  1. +1 −0 lib/tilt/template.rb
  2. +7 −0 test/tilt_template_test.rb
@@ -41,6 +41,7 @@ def initialize(file=nil, line=1, options={}, &block)
[options, line, file].compact.each do |arg|
case
when arg.respond_to?(:to_str) ; @file = arg.to_str
+ when arg.respond_to?(:path) ; @file = arg.path
when arg.respond_to?(:to_int) ; @line = arg.to_int
when arg.respond_to?(:to_hash) ; @options = arg.to_hash.dup
else raise TypeError
@@ -1,5 +1,6 @@
require 'contest'
require 'tilt'
+require 'tempfile'
class TiltTemplateTest < Test::Unit::TestCase
@@ -23,6 +24,12 @@ def prepare
assert_equal 55, inst.line
end
+ test "initializing with a tempfile" do
+ tempfile = Tempfile.new('tilt_template_test')
+ inst = MockTemplate.new(tempfile)
+ assert_equal File.basename(tempfile.path), inst.basename
+ end
+
test "uses correct eval_file" do
inst = MockTemplate.new('foo.erb', 55) {}
assert_equal 'foo.erb', inst.eval_file

0 comments on commit 2936d60

Please sign in to comment.