Enter Sinatra
Published:
February 21, 2009
Sinatra, I absolutely love it. After watching toolmantim present on the topic at the last RORO I borrowed some inspiration (and some code) and came up with the new hughevans.net.
require 'rubygems'
require 'sinatra'
require 'haml'
require 'time'
require 'lib/article'
Article.path = File.join(Sinatra::Application.root, 'articles')
helpers do
def article_body(article)
haml(article.template, :layout => false)
end
def article_path(article)
"/#{article.published.strftime("%Y/%m/%d")}/#{article.id}"
end
end
get '/' do
@articles = Article.all.sort[0..4]
haml :home
end
get '/:year/:month/:day/:id' do
@article = Article[params[:id]] || raise(Sinatra::NotFound)
@single_view = true
haml :article
end
get '/articles.atom' do
@articles = Article.all.sort
content_type 'application/atom+xml'
haml :feed, :layout => false
end
get '/:style.css' do
content_type 'text/css', :charset => 'utf-8'
sass :"stylesheets/#{params[:style]}"
end
Nothing too clever, just simple clean ruby code. The full source is available on GitHub.