Skip to content
Browse files

prepare for Tilt 1.3 (while remaining compatible with 1.2)

  • Loading branch information...
1 parent 1c1fa17 commit 94bdb1cb0beada9ee77197f4b42217f99e3e1063 @rkh rkh committed Apr 13, 2011
Showing with 15 additions and 12 deletions.
  1. +4 −2 lib/sinatra/base.rb
  2. +7 −10 test/coffee_test.rb
  3. +4 −0 test/helper.rb
View
6 lib/sinatra/base.rb
@@ -528,8 +528,9 @@ def slim(template, options={}, locals={})
# 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
@@ -590,6 +591,7 @@ def compile_template(engine, data, options, views)
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
17 test/coffee_test.rb
@@ -23,7 +23,7 @@ def coffee_app(options = {}, &block)
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 @@ def coffee_app(options = {}, &block)
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
4 test/helper.rb
@@ -65,6 +65,10 @@ def assert_body(value)
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)

0 comments on commit 94bdb1c

Please sign in to comment.
Something went wrong with that request. Please try again.