Created
September 18, 2008 17:17
-
-
Save macournoyer/11448 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
# Montreal Against Rails code | |
# Written by macournoyer, Carl Mercier and Francois Beausoleil | |
## Framework code | |
class App | |
def call(env) | |
#im doing good | |
@request = Rack::Request.new(env) | |
@response = Rack::Response.new | |
# route recognition | |
_, block = @routes.detect do |url,block| | |
Regexp.new(url).match(env["PATH_INFO"]) | |
end | |
#instance_eval block | |
block.call | |
#test first huh? | |
@response.finish #phew | |
end | |
def initialize(&block) | |
@routes = {} | |
instance_eval &block | |
end | |
def get(url, &block) | |
@routes[url] = block | |
end | |
def render(text) | |
#text="you've been rickrolled!" | |
@response.write(text) | |
end | |
end | |
## Application code | |
app = App.new do | |
get "/echo/(.*)" do |text| # Regexp matches are passed as block args | |
render text | |
end | |
get "/form" do | |
render erb(:form) # Can have helper methods to render erb and the like | |
end | |
# post "/form" do | |
# render params.inspect | |
# end | |
get "/" do | |
render "hi" # Specifies the body of the response | |
end | |
end | |
run app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment