forked from yhara/sinatbbs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart.rb
49 lines (41 loc) · 914 Bytes
/
start.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'rubygems'
require 'sinatra'
require 'sequel'
Sequel::Model.plugin(:schema)
DB = Sequel.sqlite("comments.db")
class Comments < Sequel::Model
set_schema do
primary_key :id
string :name
string :title
text :message
timestamp :posted_date
end
def date
self.posted_date.strftime("%Y-%m-%d %H:%M:%S")
end
def formatted_message
Rack::Utils.escape_html(self.message).gsub(/\n/, "<br>")
end
end
Comments.create_table unless Comments.table_exists?
helpers do
include Rack::Utils; alias_method :h, :escape_html
end
get '/style.css' do
content_type 'text/css', :charset => 'utf-8'
sass :style
end
get '/' do
@comments = Comments.order_by(:posted_date.desc)
haml :index
end
put '/comment' do
Comments.create({
:name => request[:name],
:title => request[:title],
:message => request[:message],
:posted_date => Time.now,
})
redirect '/'
end