The site can be stored in a single file called home_page.rb:
1 2 #!/usr/local/bin/ruby -rubygems 3 require 'camping' 4 5 module Camping::Controllers 6 7 # The root slash shows the `index' view. 8 class Index < R '/' 9 def get 10 render :index 11 end 12 end 13 14 # Any other page name gets sent to the view 15 # of the same name. 16 # 17 # /index -> Views#index 18 # /sample -> Views#sample 19 # 20 class Page < R '/(\w+)' 21 def get(page_name) 22 render page_name 23 end 24 end 25 26 end 27 28 module Camping::Views 29 30 # If you have a `layout' method like this, it 31 # will wrap the HTML in the other methods. The 32 # `self << yield' is where the HTML is inserted. 33 def layout 34 html do 35 title { 'My HomePage' } 36 body { self << yield } 37 end 38 end 39 40 # The `index' view. Inside your views, you express 41 # the HTML in Ruby. See http://code.whytheluckystiff.net/markaby/. 42 def index 43 p 'Hi my name is Charles.' 44 p 'Here are some links:' 45 ul do 46 li { a 'Google', :href => 'http://google.com' } 47 li { a 'A sample page', :href => '/sample' } 48 end 49 end 50 51 # The `sample' view. 52 def sample 53 p 'A sample page' 54 end 55 end 56 57 if __FILE__ == $0 58 puts Camping.run 59 end
Source: The Camping Short, Short Example