Fixed an uncought exception when run on the Google App Engine infrastructure.
Signed-off-by: Simon Rozet <simon@rozet.name>
This commit is contained in:
parent
9d67449452
commit
b88c0f579a
|
@ -635,7 +635,14 @@ module Sinatra
|
||||||
# when no file is specified.
|
# when no file is specified.
|
||||||
def use_in_file_templates!(file=nil)
|
def use_in_file_templates!(file=nil)
|
||||||
file ||= caller_files.first
|
file ||= caller_files.first
|
||||||
if data = ::IO.read(file).split('__END__')[1]
|
|
||||||
|
begin
|
||||||
|
data = ::IO.read(file).split('__END__')[1]
|
||||||
|
rescue
|
||||||
|
data = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if data
|
||||||
data.gsub!(/\r\n/, "\n")
|
data.gsub!(/\r\n/, "\n")
|
||||||
template = nil
|
template = nil
|
||||||
data.each_line do |line|
|
data.each_line do |line|
|
||||||
|
|
|
@ -75,6 +75,16 @@ class TemplatesTest < Test::Unit::TestCase
|
||||||
assert_equal "this is foo\n\n", @app.templates[:foo]
|
assert_equal "this is foo\n\n", @app.templates[:foo]
|
||||||
assert_equal "X\n= yield\nX\n", @app.templates[:layout]
|
assert_equal "X\n= yield\nX\n", @app.templates[:layout]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'use_in_file_templates simply ignores IO errors' do
|
||||||
|
assert_nothing_raised {
|
||||||
|
mock_app {
|
||||||
|
use_in_file_templates!('/foo/bar')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert @app.templates.empty?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
|
Loading…
Reference in New Issue