2010-10-26 14:50:07 -04:00
|
|
|
require File.dirname(__FILE__) + '/helper'
|
|
|
|
|
|
|
|
begin
|
|
|
|
require 'slim'
|
|
|
|
|
|
|
|
class SlimTest < Test::Unit::TestCase
|
|
|
|
def slim_app(&block)
|
|
|
|
mock_app {
|
|
|
|
set :views, File.dirname(__FILE__) + '/views'
|
|
|
|
get '/', &block
|
|
|
|
}
|
|
|
|
get '/'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders inline slim strings' do
|
|
|
|
slim_app { slim "h1 Hiya\n" }
|
|
|
|
assert ok?
|
|
|
|
assert_equal "<h1>Hiya</h1>", body
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders .slim files in views path' do
|
|
|
|
slim_app { slim :hello }
|
|
|
|
assert ok?
|
|
|
|
assert_equal "<h1>Hello From Slim</h1>", body
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders with inline layouts" do
|
|
|
|
mock_app {
|
|
|
|
layout { %(h1\n | THIS. IS. \n == yield.upcase ) }
|
2010-11-05 06:41:54 -04:00
|
|
|
get('/') { slim 'em Sparta' }
|
2010-10-26 14:50:07 -04:00
|
|
|
}
|
|
|
|
get '/'
|
|
|
|
assert ok?
|
|
|
|
assert_equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>", body
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders with file layouts" do
|
|
|
|
slim_app {
|
2010-11-05 06:41:54 -04:00
|
|
|
slim '| Hello World', :layout => :layout2
|
2010-10-26 14:50:07 -04:00
|
|
|
}
|
|
|
|
assert ok?
|
|
|
|
assert_equal "<h1>Slim Layout!</h1><p>Hello World</p>", body
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises error if template not found" do
|
|
|
|
mock_app {
|
|
|
|
get('/') { slim :no_such_template }
|
|
|
|
}
|
|
|
|
assert_raise(Errno::ENOENT) { get('/') }
|
|
|
|
end
|
|
|
|
|
|
|
|
HTML4_DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
|
|
|
|
|
|
|
|
it "passes slim options to the slim engine" do
|
|
|
|
mock_app {
|
|
|
|
get '/' do
|
2010-11-05 06:41:54 -04:00
|
|
|
slim "! doctype html\nh1 Hello World", :format => :html4
|
2010-10-26 14:50:07 -04:00
|
|
|
end
|
|
|
|
}
|
|
|
|
get '/'
|
|
|
|
assert ok?
|
|
|
|
assert_equal "#{HTML4_DOCTYPE}<h1>Hello World</h1>", body
|
|
|
|
end
|
|
|
|
|
|
|
|
it "passes default slim options to the slim engine" do
|
|
|
|
mock_app {
|
|
|
|
set :slim, {:format => :html4}
|
|
|
|
get '/' do
|
2010-11-05 06:41:54 -04:00
|
|
|
slim "! doctype html\nh1 Hello World"
|
2010-10-26 14:50:07 -04:00
|
|
|
end
|
|
|
|
}
|
|
|
|
get '/'
|
|
|
|
assert ok?
|
|
|
|
assert_equal "#{HTML4_DOCTYPE}<h1>Hello World</h1>", body
|
|
|
|
end
|
|
|
|
|
|
|
|
it "merges the default slim options with the overrides and passes them to the slim engine" do
|
|
|
|
mock_app {
|
2010-11-05 12:00:08 -04:00
|
|
|
set :slim, {:format => :html4}
|
2010-10-26 14:50:07 -04:00
|
|
|
get '/' do
|
2010-11-05 06:41:54 -04:00
|
|
|
slim "! doctype html\nh1.header Hello World"
|
2010-10-26 14:50:07 -04:00
|
|
|
end
|
2010-11-05 12:00:08 -04:00
|
|
|
get '/html5' do
|
|
|
|
slim "! doctype html\nh1.header Hello World", :format => :html5
|
2010-10-26 14:50:07 -04:00
|
|
|
end
|
|
|
|
}
|
|
|
|
get '/'
|
|
|
|
assert ok?
|
|
|
|
assert_match(/^#{HTML4_DOCTYPE}/, body)
|
2010-11-05 12:00:08 -04:00
|
|
|
get '/html5'
|
|
|
|
assert ok?
|
|
|
|
assert_equal "<!DOCTYPE html><h1 class=\"header\">Hello World</h1>", body
|
2010-10-26 14:50:07 -04:00
|
|
|
end
|
|
|
|
end
|
2011-01-25 03:27:15 -05:00
|
|
|
|
|
|
|
rescue LoadError
|
2010-10-26 14:50:07 -04:00
|
|
|
warn "#{$!.to_s}: skipping slim tests"
|
|
|
|
end
|