prepare for Tilt 1.3 (while remaining compatible with 1.2)

This commit is contained in:
Konstantin Haase 2011-04-13 14:53:40 +02:00
parent 33cde76d37
commit a735e34c19
3 changed files with 15 additions and 12 deletions

View File

@ -523,8 +523,9 @@ module Sinatra
# Calls the given block for every possible template file in views,
# named name.ext, where ext is registered on engine.
def find_template(views, name, engine)
Tilt.mappings.each do |ext, klass|
next unless klass == engine
yield ::File.join(views, "#{name}.#{@preferred_extension}")
Tilt.mappings.each do |ext, engines|
next unless ext != @preferred_extension and Array(engines).include? engine
yield ::File.join(views, "#{name}.#{ext}")
end
end
@ -585,6 +586,7 @@ module Sinatra
template.new(path, line.to_i, options) { body }
else
found = false
@preferred_extension = engine.to_s
find_template(views, data, template) do |file|
path ||= file # keep the initial path rather than the last one
if found = File.exists?(file)

View File

@ -23,7 +23,7 @@ class CoffeeTest < Test::Unit::TestCase
it 'renders inline Coffee strings' do
coffee_app { coffee "alert 'Aye!'\n" }
assert ok?
assert_equal "(function() {\n alert('Aye!');\n}).call(this);\n", body
assert body.include?("alert('Aye!');")
end
it 'defaults content type to javascript' do
@ -52,38 +52,35 @@ class CoffeeTest < Test::Unit::TestCase
it 'renders .coffee files in views path' do
coffee_app { coffee :hello }
assert ok?
assert_equal "(function() {\n alert(\"Aye!\");\n}).call(this);\n", body
assert_include body, "alert(\"Aye!\");"
end
it 'ignores the layout option' do
coffee_app { coffee :hello, :layout => :layout2 }
assert ok?
assert_equal "(function() {\n alert(\"Aye!\");\n}).call(this);\n", body
assert_include body, "alert(\"Aye!\");"
end
it "raises error if template not found" do
mock_app {
get('/') { coffee :no_such_template }
}
assert_raise(Errno::ENOENT) { get('/') }
assert_raise(Errno::ENOENT, ArgumentError) { get('/') }
end
it "passes coffee options to the coffee engine" do
coffee_app {
coffee "alert 'Aye!'\n",
:no_wrap => true
}
coffee_app { coffee "alert 'Aye!'\n", :no_wrap => true }
assert ok?
assert_equal "alert('Aye!');", body
end
it "passes default coffee options to the coffee engine" do
mock_app {
mock_app do
set :coffee, :no_wrap => true # default coffee style is :nested
get '/' do
coffee "alert 'Aye!'\n"
end
}
end
get '/'
assert ok?
assert_equal "alert('Aye!');", body

View File

@ -65,6 +65,10 @@ class Test::Unit::TestCase
assert_equal value.lstrip.gsub(/\s*\n\s*/, ""), body.lstrip.gsub(/\s*\n\s*/, "")
end
def assert_include(str, substr)
assert str.include?(substr), "expected #{str.inspect} to include #{substr.inspect}"
end
# Delegate other missing methods to response.
def method_missing(name, *args, &block)
if response && response.respond_to?(name)