Created
May 13, 2011 07:02
-
-
Save rkh/970108 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra/base' | |
class MyApp < Sinatra::Base | |
@@my_app = {} | |
def self.new(*) self < MyApp ? super : Rack::URLMap.new(@@my_app) end | |
def self.map(url) @@my_app[url] = self end | |
class FooController < MyApp | |
map '/foo' | |
get '/' do | |
"foo" | |
end | |
end | |
class BarController < MyApp | |
map '/bar' | |
get '/' do | |
"bar" | |
end | |
end | |
run! if __FILE__ == $0 | |
end |
I built a more fleshed out application and used this code for controllers. I'm sharing a skeleton of it here: https://github.com/jfeaver/modular-sinatra
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Totally awesome! Thank you for this.