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:
parent
33087977ef
commit
972aa1747a
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue