Skip to content

Instantly share code, notes, and snippets.

@febuiles
Created August 4, 2010 00:06
Show Gist options
  • Save febuiles/507419 to your computer and use it in GitHub Desktop.
Save febuiles/507419 to your computer and use it in GitHub Desktop.
$: << File.join(File.dirname(__FILE__), 'lib')
require "sinatra"
require "models"
require "helpers"
enable :static
# Content
get "/" do
erb :index, {:layout => false }
end
get "/about" do
erb :about
end
# Diary
get "/diary" do
@articles = Article.all(:order => [:created_at.desc])
erb :diary
end
get "/diary/:id" do
@article = Article.get(params[:id])
"#{@article.title}<br/>#{@article.body}"
end
post "/diary" do
title, body = params[:title], params[:body]
halt 500 if invalid_entry?
Article.create(:title => title, :body => body)
end
delete "/diary" do
article = Article.get(params[:id])
article.destroy unless article.nil?
end
# Statements
get "/statements" do
@statements = Statement.all(:order => [:created_at.asc])
erb :statements
end
post "/statements" do
title, body = params[:title], params[:body]
halt 500 if invalid_entry?
Statement.create(:title => title, :body => body)
end
delete "/statements" do
statement = Statement.get(params[:id])
statement.destroy unless statement.nil?
end
# RSS
get "/diary.xml" do
content_type 'text/xml', :charset => 'utf-8'
Article.to_rss
end
get "/statements.xml" do
content_type 'text/xml', :charset => 'utf-8'
Statement.to_rss
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment