Skip to content

Instantly share code, notes, and snippets.

@emk
Created April 19, 2009 20:18
Show Gist options
  • Select an option

  • Save emk/98200 to your computer and use it in GitHub Desktop.

Select an option

Save emk/98200 to your computer and use it in GitHub Desktop.
# Demonstration script for http://github.com/emk/blogitr
require 'rubygems'
require 'sinatra'
require 'blogitr'
$blog = Blogitr::Blog.new(File.dirname(__FILE__))
helpers do
def article_url article
dir = article.date_time.strftime("/%Y/%m/%d")
"#{dir}/#{article.permalink}"
end
end
get "/" do
@articles = $blog.articles
haml :index
end
# SECURITY: This regex will be passed almost straight through to File.read,
# so make sure it's clean. We'll eventually do more checking in
# Blog#article.
get %r{/(\d{4})/(\d{2})/(\d{2})/([^/]*)} do |year, month, day, permalink|
@article = $blog.article(year.to_i, month.to_i, day.to_i, permalink)
haml :article
end
use_in_file_templates!
__END__
@@layout
%html
%head
%title&= $blog.title
%body
#container
%h1&= $blog.title
= yield
@@index
- for article in @articles
.article
%h2
%a{:href => article_url(article)}&= article.title
= article.body
- if article.extended
%p
%a{:href => article_url(article)} Read more >>
@@article
%h2&= @article.title
= @article.body
- if @article.extended
= @article.extended
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment