Skip to content

Instantly share code, notes, and snippets.

@chischaschos
Created April 21, 2011 17:09
Show Gist options
  • Save chischaschos/935008 to your computer and use it in GitHub Desktop.
Save chischaschos/935008 to your computer and use it in GitHub Desktop.
One File Web Page with Rack
rvm 1.9.2@rack-examples --create
source :gemcutter
gem 'haml'
gem 'rack'
GEM
remote: http://rubygems.org/
specs:
haml (3.0.25)
rack (1.2.2)
PLATFORMS
ruby
DEPENDENCIES
haml
rack
message = "Hello world"
headers = {"Content-Length" => "#{message.length}",
"Content-Type" => 'text/html'}
status = 200
run lambda {[status, headers, [message]]}
message = "Hello world"
status = 200
use Rack::ContentLength
use Rack::ContentType
run lambda {[status, {}, [message]]}
require 'erb'
status = 200
home_view = <<VIEW
Hello world
VIEW
rendered_view = ERB.new(home_view).result
use Rack::ContentLength
use Rack::ContentType
run lambda {[status, {}, [rendered_view]]}
require 'haml'
status = 200
home_view = <<VIEW
!!!
%html
%head
%title= title
%body
= message
VIEW
rendered_view = Haml::Engine.new(home_view).render Object.new,
{:message => 'Hello world', :title => 'A hello world page'}
use Rack::ContentLength
use Rack::ContentType
run lambda {[status, {}, [rendered_view]]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment