Skip to content

Instantly share code, notes, and snippets.

@nu7hatch
Created September 29, 2010 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nu7hatch/603761 to your computer and use it in GitHub Desktop.
Save nu7hatch/603761 to your computer and use it in GitHub Desktop.
require "rubygems"
require "mounter"
module FooApp
extend Mounter
controllers do
get "/foo" do
"Foo..."
end
get "/bar" do
"Bar..."
end
end
end
FooApp.mount!
Mounter::Application.run!
require "sinatra"
module Mounter
class Application < Sinatra::Application
def self.mount(mod)
mod.defined_controllers.each do |name, blocks|
blocks.each {|block| instance_eval(&block) }
end
end
end
def mount!
Application.mount(self)
end
def controllers(prefix=nil, opts={}, &block)
routes = defined_controllers[prefix||false] ||= []
routes << block
end
def defined_controllers
@_routes ||= {}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment