require 'rubygems'
require 'capcode'
$:.unshift( "../lib" )
require 'capcode/base/dm'
class Story < Capcode::Base
include Capcode::Resource
property :id, Serial
property :title, String
property :body, String
property :date, String
end
module Capcode
class HTTPError
def r404(f)
"Pas glop !!! #{f} est inconnu !!!"
end
end
class Index < Route '/'
def get
r = "
"
story = Story.all
story.each do |s|
r += "#{s.title}
#{s.date} - Delete this entry#{s.body}
"
end
r+"
Add a new entry"
end
end
class Remove < Route '/remove/([^\/]*)'
def get( id )
Story.get!(id).destroy
redirect( Index )
end
end
class Add < Route '/add'
def get
'
Add a new entry
'
end
def post
Story.new( :title => params['title'], :body => params['body'], :date => Time.now.to_s ).save
redirect( Index )
end
end
end
Capcode.run( :port => 3001, :host => "localhost", :db_config => "blog-dm.yml" )