Merge branch 'obsolete-default'
This commit is contained in:
commit
186a5bc9b6
|
@ -1023,15 +1023,14 @@ module Sinatra
|
||||||
|
|
||||||
reset!
|
reset!
|
||||||
|
|
||||||
set :raise_errors, true
|
set :environment, (ENV['RACK_ENV'] || :development).to_sym
|
||||||
set :dump_errors, false
|
set :raise_errors, Proc.new { !development? }
|
||||||
|
set :dump_errors, Proc.new { development? }
|
||||||
|
set :show_exceptions, Proc.new { development? }
|
||||||
set :clean_trace, true
|
set :clean_trace, true
|
||||||
set :show_exceptions, false
|
|
||||||
set :sessions, false
|
set :sessions, false
|
||||||
set :logging, false
|
set :logging, false
|
||||||
set :methodoverride, false
|
set :methodoverride, false
|
||||||
set :static, false
|
|
||||||
set :environment, (ENV['RACK_ENV'] || :development).to_sym
|
|
||||||
|
|
||||||
set :run, false # start server via at-exit hook?
|
set :run, false # start server via at-exit hook?
|
||||||
set :running, false # is the built-in server running now?
|
set :running, false # is the built-in server running now?
|
||||||
|
@ -1041,11 +1040,13 @@ module Sinatra
|
||||||
|
|
||||||
set :app_file, nil
|
set :app_file, nil
|
||||||
set :root, Proc.new { app_file && File.expand_path(File.dirname(app_file)) }
|
set :root, Proc.new { app_file && File.expand_path(File.dirname(app_file)) }
|
||||||
set :public, Proc.new { root && File.join(root, 'public') }
|
|
||||||
set :views, Proc.new { root && File.join(root, 'views') }
|
set :views, Proc.new { root && File.join(root, 'views') }
|
||||||
set :reload_templates, Proc.new { !development? }
|
set :reload_templates, Proc.new { !development? }
|
||||||
set :lock, false
|
set :lock, false
|
||||||
|
|
||||||
|
set :public, Proc.new { root && File.join(root, 'public') }
|
||||||
|
set :static, Proc.new { self.public && File.exist?(self.public) }
|
||||||
|
|
||||||
error ::Exception do
|
error ::Exception do
|
||||||
response.status = 500
|
response.status = 500
|
||||||
content_type 'text/html'
|
content_type 'text/html'
|
||||||
|
@ -1086,16 +1087,21 @@ module Sinatra
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Base class for classic style (top-level) applications.
|
# Execution context for classic style (top-level) applications. All
|
||||||
class Default < Base
|
# DSL methods executed on main are delegated to this class.
|
||||||
|
#
|
||||||
|
# The Application class should not be subclassed, unless you want to
|
||||||
|
# inherit all settings, routes, handlers, and error pages from the
|
||||||
|
# top-level. Subclassing Sinatra::Base is heavily recommended for
|
||||||
|
# modular applications.
|
||||||
|
class Application < Base
|
||||||
set :raise_errors, Proc.new { test? }
|
set :raise_errors, Proc.new { test? }
|
||||||
set :show_exceptions, Proc.new { development? }
|
|
||||||
set :dump_errors, true
|
set :dump_errors, true
|
||||||
set :sessions, false
|
set :sessions, false
|
||||||
set :logging, Proc.new { ! test? }
|
set :logging, Proc.new { ! test? }
|
||||||
set :methodoverride, true
|
set :methodoverride, true
|
||||||
set :static, true
|
|
||||||
set :run, Proc.new { ! test? }
|
set :run, Proc.new { ! test? }
|
||||||
|
set :static, true
|
||||||
|
|
||||||
def self.register(*extensions, &block) #:nodoc:
|
def self.register(*extensions, &block) #:nodoc:
|
||||||
added_methods = extensions.map {|m| m.public_instance_methods }.flatten
|
added_methods = extensions.map {|m| m.public_instance_methods }.flatten
|
||||||
|
@ -1104,11 +1110,6 @@ module Sinatra
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# The top-level Application. All DSL methods executed on main are delegated
|
|
||||||
# to this class.
|
|
||||||
class Application < Default
|
|
||||||
end
|
|
||||||
|
|
||||||
# Sinatra delegation mixin. Mixing this module into an object causes all
|
# Sinatra delegation mixin. Mixing this module into an object causes all
|
||||||
# methods to be delegated to the Sinatra::Application class. Used primarily
|
# methods to be delegated to the Sinatra::Application class. Used primarily
|
||||||
# at the top-level.
|
# at the top-level.
|
||||||
|
@ -1140,11 +1141,11 @@ module Sinatra
|
||||||
|
|
||||||
# Extend the top-level DSL with the modules provided.
|
# Extend the top-level DSL with the modules provided.
|
||||||
def self.register(*extensions, &block)
|
def self.register(*extensions, &block)
|
||||||
Default.register(*extensions, &block)
|
Application.register(*extensions, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Include the helper modules provided in Sinatra's request context.
|
# Include the helper modules provided in Sinatra's request context.
|
||||||
def self.helpers(*extensions, &block)
|
def self.helpers(*extensions, &block)
|
||||||
Default.helpers(*extensions, &block)
|
Application.helpers(*extensions, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require 'sinatra/base'
|
require 'sinatra/base'
|
||||||
|
|
||||||
module Sinatra
|
module Sinatra
|
||||||
class Default < Base
|
class Application < Base
|
||||||
|
|
||||||
# we assume that the first file that requires 'sinatra' is the
|
# we assume that the first file that requires 'sinatra' is the
|
||||||
# app_file. all other path related options are calculated based
|
# app_file. all other path related options are calculated based
|
||||||
|
|
|
@ -177,8 +177,10 @@ class SettingsTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'raise_errors' do
|
describe 'raise_errors' do
|
||||||
it 'is enabled on Base' do
|
it 'is enabled on Base except under development' do
|
||||||
assert @base.raise_errors?
|
assert @base.raise_errors?
|
||||||
|
@base.environment = :development
|
||||||
|
assert !@base.raise_errors?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is enabled on Application only in test' do
|
it 'is enabled on Application only in test' do
|
||||||
|
@ -190,8 +192,10 @@ class SettingsTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'show_exceptions' do
|
describe 'show_exceptions' do
|
||||||
it 'is disabled on Base' do
|
it 'is disabled on Base except under development' do
|
||||||
assert ! @base.show_exceptions?
|
assert ! @base.show_exceptions?
|
||||||
|
@base.environment = :development
|
||||||
|
assert @base.show_exceptions?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is disabled on Application except in development' do
|
it 'is disabled on Application except in development' do
|
||||||
|
@ -219,8 +223,10 @@ class SettingsTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'dump_errors' do
|
describe 'dump_errors' do
|
||||||
it 'is disabled on Base' do
|
it 'is disabled on Base except in development' do
|
||||||
assert ! @base.dump_errors?
|
assert ! @base.dump_errors?
|
||||||
|
@base.environment = :development
|
||||||
|
assert @base.dump_errors?
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is enabled on Application' do
|
it 'is enabled on Application' do
|
||||||
|
@ -274,10 +280,22 @@ class SettingsTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'static' do
|
describe 'static' do
|
||||||
it 'is disabled on Base' do
|
it 'is disabled on Base by default' do
|
||||||
assert ! @base.static?
|
assert ! @base.static?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'is enabled on Base when public is set and exists' do
|
||||||
|
@base.set :environment, :development
|
||||||
|
@base.set :public, File.dirname(__FILE__)
|
||||||
|
assert @base.static?
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'is enabled on Base when root is set and root/public exists' do
|
||||||
|
@base.set :environment, :development
|
||||||
|
@base.set :root, File.dirname(__FILE__)
|
||||||
|
assert @base.static?
|
||||||
|
end
|
||||||
|
|
||||||
it 'is enabled on Application' do
|
it 'is enabled on Application' do
|
||||||
assert @application.static?
|
assert @application.static?
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue