require 'camping'
Camping.goes :Simple
module Simple::Controllers
class Index < R '/'
def get
render :index
end
end
class Greeter < R '/greeter/(\w+)', '/greeter'
def get message
render message
end
def post
@names = input.names
render :greetings
end
end
class Style < R '/styles.css'
def get
@headers["Content-Type"] =
"text/css; charset=utf-8"
@body = %{
body {
background-color: #BDFFB0;
}
p.hello {
color: red;
}
}
end
end
end
module Simple::Views
def layout
html do
head do
title 'my camping site'
link :rel => 'stylesheet',
:type => 'text/css',
:href => '/styles.css',
:media => 'screen'
end
body do
self << yield
end
end
end
def index
p.hello "Welcome on my greeting-engine!"
_greet
end
def greetings
@names.split(", ").each do |n|
p.hello ("Hello " + n + "!")
end
a("Back to input", :href => R(Index))
end
#Partials start here!
def _greet
form :action => R(Greeter),
:method => 'post' do
label 'Persons you wanna greet:',
:for => 'names'
br
input :name => 'names', :type => 'text'
br
input :type => 'submit',
:value => 'Greet!'
end
end
end
Tuesday, February 6, 2007
everything.inject {|sum, post| sum += post}
Now let's sum up all code-snippets, so you don't have to copy and past all the stuff if you wanna start from here.
Subscribe to:
Post Comments (Atom)

2 comments:
Great website. I think it is very useful for a camping beginner like me. Thank you.
Regarding this entry: Is there still a need for '/greeter/(\w+)' in this code?
I think it's not needed. Same for the get method of the Greeter controller.
Post a Comment