Sugar to include a classic style app in a rackup.

This will eval the source into a Sinatra::Default class giving you
the ablility to seperate the apps into files and run them with ruby
when needed.

Example:

@@ foo.rb

get '/' do
  'sugar!'
end

@@ config.ru

require 'sinatra/base'

map '/foo' do
   run Sinatra("foo.rb")
end
This commit is contained in:
Blake Mizerany 2009-02-06 16:32:49 -08:00
parent 33087977ef
commit 972aa1747a
1 changed files with 21 additions and 0 deletions

View File

@ -980,3 +980,24 @@ class String #:nodoc:
# earlier. # earlier.
alias_method :bytesize, :length unless ''.respond_to? :bytesize alias_method :bytesize, :length unless ''.respond_to? :bytesize
end end
class Rack::Builder
## Sugar to include a classic style app in a rackup.
##
## This will eval the source into a Sinatra::Default class
## Example:
##
## require 'sinatra/base'
##
## map '/foo' do
## run Sinatra("foo.rb")
## end
##
## run Sinatra("bar.rb")
##
def Sinatra(file, base=Sinatra::Default)
Sinatra.new(base) {
expanded = File.expand_path(file)
self.class_eval(File.read(expanded), expanded) }
end
end