Skip to content

Instantly share code, notes, and snippets.

@EmmanuelOga
Created June 8, 2010 06:22
Show Gist options
  • Save EmmanuelOga/429680 to your computer and use it in GitHub Desktop.
Save EmmanuelOga/429680 to your computer and use it in GitHub Desktop.
# [sudo] gem install rack
# ruby -rubygems server.rb
# open http://localhost:9292 in browser.
require 'rack'
require 'erb'
TEMPLATE = File.read("template.erb")
server = lambda do |env|
response_text = ERB.new(TEMPLATE).result
response_code = "200"
response_headers = {"Content-Type" => "text/html", "Content-Length" => response_text.length.to_s}
[response_code, response_headers, response_text]
end
Rack::Handler::WEBrick.run server, :Port => 9292
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>
Vare minimal erb page.
</title>
</head>
<body>
Ruby says that 2 + 2 is:
<br/>
<%= 2 + 2%>
<% [1,2,3,4].each do |n| %>
<h<%= n %>>And these are headers.</h<%= n %>>
<% end %>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment