Permalink
Browse files

first commit

  • Loading branch information...
igorgue committed Nov 3, 2009
0 parents commit fd9f994d3e82ce583178a3ff6a9c34a5b044b252
Showing with 114 additions and 0 deletions.
  1. +21 −0 .gitignore
  2. +28 −0 app.rb
  3. +29 −0 controllers/entries.rb
  4. +9 −0 models/blog.rb
  5. +7 −0 views/add.erb
  6. +20 −0 views/index.erb
@@ -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 app.rb
@@ -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'
@@ -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
@@ -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
@@ -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>
@@ -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.