Skip to content

Instantly share code, notes, and snippets.

@snusnu
Created June 21, 2010 14:10
Show Gist options
  • Save snusnu/446896 to your computer and use it in GitHub Desktop.
Save snusnu/446896 to your computer and use it in GitHub Desktop.
Allows properly namespaced apps with "controllers" and models where they "should" be
require 'sinatra/base'
module M1
def self.apps
@apps ||= {}
end
class A < Sinatra::Base
def self.namespace(namespace)
M1.apps[namespace] = self
end
not_found do
"Sorry, not found"
end
end
module M2
class B < M1::A
namespace '/B'
class C < M2::B
namespace '/B/C'
class D < M2::B::C
namespace '/B/C/D'
get '/d' do
'rendered M2::B::C::D at /B/C/D/d'
end
end
get '/c' do
'rendered M2::B::C at /B/C/c'
end
end
get '/b' do
'rendered M2::B at /B/b'
end
end
end
end
run M1.apps # if you run a hash, it sets up a map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment