very first test with ruby camping :-)

Flattr this!

I tried The Camping Short, Short Example for the ruby camping framework.

 #!/usr/local/bin/ruby -rubygems
 require 'camping'

 Camping.goes :HomePage

 module HomePage::Controllers

   # The root slash shows the `index' view.
   class Index < R '/'
     def get
       render :index

   # Any other page name gets sent to the view
   # of the same name.
   #   /index -> Views#index
   #   /sample -> Views#sample
   class Page < R '/(\w+)'
     def get(page_name)
       render page_name


 module HomePage::Views

   # If you have a `layout' method like this, it
   # will wrap the HTML in the other methods.  The
   # `self << yield' is where the HTML is inserted.
   def layout
     html do
       title { 'My HomePage' }
       body { self << yield }

   # The `index' view.  Inside your views, you express
   # the HTML in Ruby.  See
   def index
     p 'Hi my name is Charles.'
     p 'Here are some links:'
     ul do
      li { a 'Google', :href => '' }
      li { a 'A sample page', :href => '/sample' }

   # The `sample' view.
   def sample
     p 'A sample page'

It seems to be very easy to create the separat pages.

The example above generates one entry page. (the index method in Views) and one additional page (sample method).
As far as i should know it from rails, it uses the same MVC pattern and theres is a similar syntax. Just the Views are in native ruby without mixing up with html.
But maybe that will appear later on.
The next step is to see howto connect ruby with some inner sys-functions of nexenta ^^.

Blogged with the Flock Browser

Leave a Reply

%d bloggers like this: