diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb
index 5536245a39..dc538a634a 100644
--- a/lib/sinatra/base.rb
+++ b/lib/sinatra/base.rb
@@ -1833,6 +1833,58 @@ class << self
content_type 'text/html'
'
Internal Server Error
'
end
+
+ configure :development do
+ get '/__sinatra__/:image.png' do
+ filename = File.dirname(__FILE__) + "/images/#{params[:image].to_i}.png"
+ content_type :png
+ send_file filename
+ end
+
+ error NotFound do
+ content_type 'text/html'
+
+ if self.class == Sinatra::Application
+ code = <<-RUBY.gsub(/^ {12}/, '')
+ #{request.request_method.downcase} '#{request.path_info}' do
+ "Hello World"
+ end
+ RUBY
+ else
+ code = <<-RUBY.gsub(/^ {12}/, '')
+ class #{self.class}
+ #{request.request_method.downcase} '#{request.path_info}' do
+ "Hello World"
+ end
+ end
+ RUBY
+
+ file = settings.app_file.to_s.sub(settings.root.to_s, '').sub(/^\//, '')
+ code = "# in #{file}\n#{code}" unless file.empty?
+ end
+
+ (<<-HTML).gsub(/^ {10}/, '')
+
+
+
+
+
+
+ Sinatra doesn’t know this ditty.
+
+
+ Try this:
+
#{Rack::Utils.escape_html(code)}
+
+
+
+ HTML
+ end
+ end
end
# Execution context for classic style (top-level) applications. All
diff --git a/lib/sinatra/main.rb b/lib/sinatra/main.rb
index d9ca55c017..5b14442dd9 100644
--- a/lib/sinatra/main.rb
+++ b/lib/sinatra/main.rb
@@ -1,8 +1,16 @@
require 'sinatra/base'
module Sinatra
- class Base
- if ARGV.any?
+ class Application < Base
+
+ # we assume that the first file that requires 'sinatra' is the
+ # app_file. all other path related options are calculated based
+ # on this path by default.
+ set :app_file, caller_files.first || $0
+
+ set :run, Proc.new { File.expand_path($0) == File.expand_path(app_file) }
+
+ if run? && ARGV.any?
require 'optparse'
OptionParser.new { |op|
op.on('-p port', 'set the port (default is 4567)') { |val| set :port, Integer(val) }
@@ -13,67 +21,6 @@ class Base
op.on('-x', 'turn on the mutex lock (default is off)') { set :lock, true }
}.parse!(ARGV.dup)
end
-
- configure :development do
- get '/__sinatra__/:image.png' do
- filename = File.dirname(__FILE__) + "/images/#{params[:image].to_i}.png"
- content_type :png
- send_file filename
- end
-
- error NotFound do
- content_type 'text/html'
-
- if self.class == Sinatra::Application
- code = <<-RUBY.gsub(/^ {12}/, '')
- #{request.request_method.downcase} '#{request.path_info}' do
- "Hello World"
- end
- RUBY
- else
- code = <<-RUBY.gsub(/^ {12}/, '')
- class #{self.class}
- #{request.request_method.downcase} '#{request.path_info}' do
- "Hello World"
- end
- end
- RUBY
-
- file = settings.app_file.to_s.sub(settings.root.to_s, '').sub(/^\//, '')
- code = "# in #{file}\n#{code}" unless file.empty?
- end
-
- (<<-HTML).gsub(/^ {10}/, '')
-
-
-
-
-
-
- Sinatra doesn’t know this ditty.
-
-
- Try this:
-
#{Rack::Utils.escape_html(code)}
-
-
-
- HTML
- end
- end
- end
-
- class Application < Base
- # we assume that the first file that requires 'sinatra' is the
- # app_file. all other path related options are calculated based
- # on this path by default.
- set :app_file, caller_files.first || $0
-
- set :run, Proc.new { File.expand_path($0) == File.expand_path(app_file) }
end
at_exit { Application.run! if $!.nil? && Application.run? }