secret
Last active

  • Download Gist
config.ru
Ruby
1 2
require 'wiki'
run Sinatra::Application
wiki.rb
Ruby
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 50 51 52 53 54 55 56 57 58 59 60 61 62
require 'rubygems'
require 'sinatra'
require 'sequel'
 
Sequel.connect(ENV['DATABASE_URL'] || 'sqlite://wiki.db')
 
class Post < Sequel::Model
unless table_exists?
set_schema do
primary_key :id
text :name
text :content
end
create_table
end
end
 
get '/' do
redirect '/Home'
end
 
get '/:page' do
@page = Post.find_or_create(:name => params[:page])
erb :show
end
 
get '/:page/edit' do
@page = Post.find_or_create(:name => params[:page])
erb :edit
end
 
post '/:page' do
@page = Post.find_or_create(:name => params[:page])
@page.content = params[:content]
@page.save
redirect "/#{@page.name}"
end
 
__END__
@@ layout
<!DOCTYPE html>
<html>
<head>
<title><%= @page.name %></title>
</head>
<body>
<h1><%= @page.name %></h1>
<%= yield %>
</body>
</html>
 
@@ show
<p><%= @page.content %></p>
<p><a href='/<%= @page.name %>/edit'>Edit</a></p>
 
@@ edit
<form action='/<%= @page.name %>' method='POST'>
<textarea name='content' rows='20' cols='65'><%= @page.content %></textarea>
<br>
<input type='submit' value='Save'>
<a href='/<%= @page.name %>'>Cancel</a>
</form>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.