Tip: Click lines to highlight, hold ctrl/cmd to multi-select

http://codedumper.com/ekume (30-Sep @ 09:13)

rrees.wordpress.com

Syntax Highlighted Code

  1.  
  2. require 'rubygems'
  3. require 'sinatra'
  4.  
  5. get '/' do
  6.     haml <<END
  7. !!!
  8. %html
  9.   %head
  10.     %title Greetings
  11.   %body
  12.     %p Prepare to be greeted
  13.     %form{:action => 'hello', :method => 'post'}
  14.       %input{:type => 'text', :name => 'name'}
  15.       %input{:type => 'submit', :value => 'Greet'}
  16. END
  17. end
  18.  
  19. get '/hello/:name' do
  20.     greet(params[:name])
  21. end
  22.  
  23. post '/hello' do
  24.     greet(params[:name])
  25. end
  26.  
  27. private
  28.  
  29. def greet(name)
  30.         haml <<END
  31. !!!
  32. %html
  33.   %head
  34.     %title Greetz
  35.   %body
  36.     %h1 Heya!
  37.     %p= "Hello <em> #{name} </em>"
  38. END
  39. end

Plain Code


require 'rubygems'
require 'sinatra'

get '/' do
    haml <<END
!!!
%html
  %head
    %title Greetings
  %body
    %p Prepare to be greeted
    %form{:action => 'hello', :method => 'post'}
      %input{:type => 'text', :name => 'name'}
      %input{:type => 'submit', :value => 'Greet'}
END
end

get '/hello/:name' do
    greet(params[:name])
end

post '/hello' do
    greet(params[:name])
end

private

def greet(name)
        haml <<END
!!!
%html
  %head
    %title Greetz
  %body
    %h1 Heya!
    %p= "Hello <em> #{name} </em>"
END
end

Permalink: http://codedumper.com/ekume