fixes for Tilt 1.3

This commit is contained in:
Konstantin Haase 2011-04-26 22:19:03 +02:00
parent 6207962fc1
commit 5e1375a5cc
6 changed files with 32 additions and 25 deletions

View File

@ -7,19 +7,20 @@ module Sinatra
include Sinatra::EngineTracking
DUMMIES = {
Tilt::HamlTemplate => "!= capture_haml(*args, &block)",
Tilt::ERBTemplate => "<% @capture = yield(*args) %>",
Tilt::ErubisTemplate => "<%= yield(*args) %>",
:slim => "== yield(*args)"
:haml => "!= capture_haml(*args, &block)",
:erb => "<% @capture = yield(*args) %>",
:slim => "== yield(*args)"
}
DUMMIES[:erubis] = DUMMIES[:erb]
def capture(*args, &block)
@capture = nil
if current_engine == :ruby
result = block[*args]
else
clean_up = eval '_buf, @_buf_was = "", _buf if defined?(_buf)', block.binding
dummy = DUMMIES[Tilt[current_engine]] || DUMMIES.fetch(current_engine)
dummy = DUMMIES.fetch(current_engine)
options = { :layout => false, :locals => {:args => args, :block => block }}
result = render(current_engine, dummy, options, &block)
end

View File

@ -8,6 +8,7 @@ module Sinatra
# Sinatra::Application by default.
module Common
register :ConfigFile
register :CSRF
register :Namespace
register :RespondWith

View File

@ -167,7 +167,9 @@ module Sinatra
settings.template_engines[ext].each { |e| possible << [e, name] }
end
possible.each do |engine, template|
find_template(settings.views, template, Tilt[engine]) do |file|
# not exactly like Tilt[engine], but does not trigger a require
klass = Tilt.mappings[Tilt.normalize(engine)].first
find_template(settings.views, template, klass) do |file|
next unless File.exist? file
return settings.rendering_method(engine) << template.to_sym
end

View File

@ -94,8 +94,9 @@ Gem::Specification.new do |s|
"spec/spec_helper.rb"
]
s.add_dependency "sinatra", "~> 1.2.2"
s.add_dependency "sinatra", "~> 1.2.3"
s.add_dependency "backports", ">= 2.0"
s.add_dependency "tilt", "~> 1.3"
s.add_dependency "rack-test"
s.add_development_dependency "rspec", "~> 2.3"

View File

@ -9,6 +9,8 @@ describe Sinatra::ContentFor do
end.new!
end
Tilt.prefer Tilt::ERBTemplate
extend Forwardable
def_delegators :subject, :content_for, :yield_content
def render(engine, template)

View File

@ -87,20 +87,20 @@ describe Sinatra::Reloader do
end
it "doesn't mess up the application" do
get('/foo').body.should == 'foo'
get('/foo').body.strip.should == 'foo'
end
it "knows when a route has been modified" do
update_app_file(:routes => ['get("/foo") { "bar" }'])
get('/foo').body.should == 'bar'
get('/foo').body.strip.should == 'bar'
end
it "knows when a route has been added" do
update_app_file(
:routes => ['get("/foo") { "foo" }', 'get("/bar") { "bar" }']
)
get('/foo').body.should == 'foo'
get('/bar').body.should == 'bar'
get('/foo').body.strip.should == 'foo'
get('/bar').body.strip.should == 'bar'
end
it "knows when a route has been removed" do
@ -113,7 +113,7 @@ describe Sinatra::Reloader do
:routes => ['get("/foo") { erb :foo }'],
:inline_templates => { :foo => 'bar' }
)
get('/foo').body.should == 'bar'
get('/foo').body.strip.should == 'bar'
end
it "reloads inline templates in other file" do
@ -124,17 +124,17 @@ describe Sinatra::Reloader do
end
require template_file_path
app_const.inline_templates= template_file_path
get('/foo').body.should == 'foo'
get('/foo').body.strip.should == 'foo'
update_file(template_file_path) do |f|
f.write "__END__\n\n@@foo\nbar"
end
get('/foo').body.should == 'bar'
get('/foo').body.strip.should == 'bar'
end
it "doesn't try to reload a removed file" do
update_app_file(:routes => ['get("/foo") { "i shall not be reloaded" }'])
FileUtils.rm app_file_path
get('/foo').body.should == 'foo'
get('/foo').body.strip.should == 'foo'
end
end
@ -149,20 +149,20 @@ describe Sinatra::Reloader do
it "allows to specify a file to stop from being reloaded" do
app_const.dont_reload app_file_path
update_app_file(:routes => ['get("/foo") { "bar" }'])
get('/foo').body.should == 'foo'
get('/foo').body.strip.should == 'foo'
end
it "allows to specify a glob to stop matching files from being reloaded" do
app_const.dont_reload '**/*.rb'
update_app_file(:routes => ['get("/foo") { "bar" }'])
get('/foo').body.should == 'foo'
get('/foo').body.strip.should == 'foo'
end
it "doesn't interfere with other application's reloading policy" do
app_const.dont_reload '**/*.rb'
setup_example_app(:routes => ['get("/foo") { "foo" }'])
update_app_file(:routes => ['get("/foo") { "bar" }'])
get('/foo').body.should == 'bar'
get('/foo').body.strip.should == 'bar'
end
end
@ -179,19 +179,19 @@ describe Sinatra::Reloader do
end
it "allows to specify a file to be reloaded" do
get('/foo').body.should == 'foo'
get('/foo').body.strip.should == 'foo'
update_file(@foo_path) do |f|
f.write 'class Foo; def self.foo() "bar" end end'
end
get('/foo').body.should == 'bar'
get('/foo').body.strip.should == 'bar'
end
it "allows to specify glob to reaload matching files" do
get('/foo').body.should == 'foo'
get('/foo').body.strip.should == 'foo'
update_file(@foo_path) do |f|
f.write 'class Foo; def self.foo() "bar" end end'
end
get('/foo').body.should == 'bar'
get('/foo').body.strip.should == 'bar'
end
it "doesn't try to reload a removed file" do
@ -199,17 +199,17 @@ describe Sinatra::Reloader do
f.write 'class Foo; def self.foo() "bar" end end'
end
FileUtils.rm @foo_path
get('/foo').body.should == 'foo'
get('/foo').body.strip.should == 'foo'
end
it "doesn't interfere with other application's reloading policy" do
app_const.also_reload '**/*.rb'
setup_example_app(:routes => ['get("/foo") { Foo.foo }'])
get('/foo').body.should == 'foo'
get('/foo').body.strip.should == 'foo'
update_file(@foo_path) do |f|
f.write 'class Foo; def self.foo() "bar" end end'
end
get('/foo').body.should == 'foo'
get('/foo').body.strip.should == 'foo'
end
end
end