Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
igorgue committed Nov 3, 2009
0 parents commit fd9f994
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .gitignore
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
28 changes: 28 additions & 0 deletions app.rb
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'
29 changes: 29 additions & 0 deletions controllers/entries.rb
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
9 changes: 9 additions & 0 deletions models/blog.rb
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
7 changes: 7 additions & 0 deletions views/add.erb
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>
20 changes: 20 additions & 0 deletions views/index.erb
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>

0 comments on commit fd9f994

Please sign in to comment.