-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fd9f994
Showing
6 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
.DS_Store | |||
erl_crash.dump | |||
unicorn.rb | |||
*.db | |||
*.pyc | |||
*.swp | |||
*.swo | |||
*.pid | |||
*.log | |||
*.svn | |||
*.hg | |||
*.tmproj | |||
*~ | |||
*.egg-info | |||
_trial_temp | |||
tags | |||
build | |||
dist | |||
cscope.out | |||
cscope.files | |||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
# app.rb | |||
require 'rubygems' | |||
require 'sinatra' | |||
require 'sequel' | |||
|
|||
configure do | |||
DB = Sequel.sqlite('blog.db') | |||
|
|||
DB.create_table? :posts do | |||
primary_key :id | |||
varchar :title | |||
varchar :body | |||
end | |||
|
|||
DB.create_table? :tags do | |||
primary_key :id | |||
varchar :title | |||
end | |||
|
|||
load "models/blog.rb" | |||
end | |||
|
|||
helpers do | |||
include Rack::Utils | |||
alias_method :h, :escape_html | |||
end | |||
|
|||
load 'controllers/entries.rb' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
# controllers/entries.rb | |||
|
|||
get '/' do | |||
@entries = Post.all | |||
|
|||
erb :index | |||
end | |||
|
|||
get '/add' do | |||
erb :add | |||
end | |||
|
|||
post '/add' do | |||
Post.find_or_create :title => params[:title], :body => params[:body] | |||
|
|||
redirect "/" | |||
end | |||
|
|||
get '/delete/?' do | |||
if params[:id] | |||
post = Post.find :id => params[:id] | |||
|
|||
if post | |||
post.destroy | |||
end | |||
end | |||
|
|||
redirect "/" | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,9 @@ | |||
# models/blog.rb | |||
|
|||
class Tag < Sequel::Model | |||
many_to_many :posts | |||
end | |||
|
|||
class Post < Sequel::Model | |||
many_to_many :tags | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
<h1>Add new entry</h1> | |||
|
|||
<form action="/add" method="post" accept-charset="utf-8"> | |||
<p>Title: <input type="text" name="title" value=""> | |||
<p>Body: <textarea name="body" value=""></textarea> | |||
<p><input type="submit" value="Add"></p> | |||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" | |||
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> | |||
<html> | |||
<head> | |||
<meta http-equiv="content-type" content="text/html; charset=utf-8"/> | |||
</head> | |||
<body> | |||
<h1>Superblog!</h1> | |||
|
|||
<% @entries.each do |entry| %> | |||
<hr> | |||
<h2><%= entry.title %></h2> | |||
<p><%= entry.body %></p> | |||
<p><a href="/delete/?id=<%= entry.id %>">✖ delete</a>?</p> | |||
<% end %> | |||
<hr> | |||
|
|||
<p>Add new entries <a href="/add">here</a>.</p> | |||
</body> | |||
</html> |