Created
November 30, 2008 22:51
-
-
Save ivey/30543 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-merb' | |
# use_orm :datamapper | |
# use_test :rspec | |
# use_template_engine :erb | |
get "/" do | |
"<h1>It works!</h1>" | |
end | |
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 'digest/md5' | |
Merb::Config.use { |c| | |
c[:framework] = { :public => [Merb.root / "public", nil] } | |
c[:session_store] = 'none' | |
c[:exception_details] = true | |
c[:log_level] = :debug # or error, warn, info or fatal | |
c[:log_stream] = STDOUT | |
c[:reload_classes] = true | |
c[:reload_templates] = true | |
} | |
Merb::Router.prepare do | |
end | |
class SinatraMerb < Merb::Controller | |
end | |
def get(path,&blk) ; add_action(path,:get,&blk) ; end | |
def post(path,&blk) ; add_action(path,:post,&blk) ; end | |
def put(path,&blk) ; add_action(path,:put,&blk) ; end | |
def delete(path,&blk) ; add_action(path,:delete,&blk) ; end | |
def add_action(path, method, &blk) | |
m = "sinatra__#{Digest::MD5.hexdigest(path)}" | |
SinatraMerb.class_eval do | |
define_method(m,blk) | |
show_action m | |
end | |
Merb::Router.prepare(Merb::Router.routes, []) do | |
match(path).to(:controller => SinatraMerb, :action => m, :method => method) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment