Skip to content

Instantly share code, notes, and snippets.

@macournoyer
Created September 18, 2008 17:17
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 macournoyer/11448 to your computer and use it in GitHub Desktop.
Save macournoyer/11448 to your computer and use it in GitHub Desktop.
# 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