Sha256: ecfb84a81e8fd476f35ea4d6a17c9b0ff3be45abaa223568017a3196526c3179

Contents?: true

Size: 1.3 KB

Versions: 6

Compression:

Stored size: 1.3 KB

Contents

require 'rubygems'
require 'trellis'

include Trellis

module GuestBookApp

  class Comment
    attr_accessor :text
    attr_accessor :time_stamp

    def initialize(text, time_stamp=Time.now)
      @text, @time_stamp = text, time_stamp
    end
  end
  
  class GuestBookApp < Application
    home :guest_book
  end
  
  class GuestBook < Page 
    persistent :comments 
    
    def initialize
      @comments = Array.new
      super
    end
    
    def on_submit_from_comment  
      text = params[:comment_text]
      @comments << Comment.new(text)
      logger.info "there are #{@comments.size.to_s} comments"
      self
    end

    template(%[
!!! XML
!!! Strict
%html{ :xmlns => "http://www.w3.org/1999/xhtml" }
  %head
    %title
      Trellis Guest Book
  %body
    %trellis:form{ :tid => "comment", :method => "post" }
      Add your comment here:
      %p
      %trellis:text_area{ :keep_contents => "no", :tid => "text", :rows => "15", :cols => "60" }
      %p
      %trellis:submit{ :tid => "add", :value => "Submit" }
    %p
    %trellis:each{ :value => "comment", :source => "comments" }
      %p
      %trellis:value{ :name => "comment.time_stamp" }
      %br
      %trellis:value{ :name => "comment.text" }
      %br
    ], :format => :haml)
  end
  
  GuestBookApp.new.start 3001 if __FILE__ == $PROGRAM_NAME
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
trellis-0.0.6 examples/guest_book/source/guest_book.rb
trellis-0.0.5 examples/guest_book/source/guest_book.rb
trellis-0.0.4 examples/guest_book/source/guest_book.rb
trellis-0.0.3 examples/guest_book/source/guest_book.rb
trellis-0.0.2 examples/guest_book/source/guest_book.rb
trellis-0.0.1 examples/guest_book/source/guest_book.rb