2011-06-24 13:28:19 +02:00
|
|
|
class Blog < Sinatra::Base
|
2011-06-24 14:29:59 +02:00
|
|
|
set $settings
|
2011-07-27 18:03:17 +02:00
|
|
|
# never ever again load the Rack::Session::Pool here
|
|
|
|
# or the admin pool get's broken and you get thrown out after every request!
|
|
|
|
# do that in the config.ru, if you have to!
|
2011-06-26 08:45:33 +02:00
|
|
|
register Sinatra::CompassSupport
|
2011-06-24 14:29:59 +02:00
|
|
|
|
2011-06-24 13:28:19 +02:00
|
|
|
get '/' do
|
2011-07-11 20:01:23 +02:00
|
|
|
if params.has_key? 'page'
|
2011-07-15 21:21:52 +02:00
|
|
|
@current_page = params['page'].to_i
|
2011-07-11 20:01:23 +02:00
|
|
|
else
|
2011-07-15 21:21:52 +02:00
|
|
|
@current_page = 1
|
2011-07-11 20:01:23 +02:00
|
|
|
end
|
2011-07-15 21:21:52 +02:00
|
|
|
@page_count = Post.page_count
|
|
|
|
@posts = Post.get_page(@current_page - 1)
|
2011-06-24 15:40:37 +02:00
|
|
|
haml :index
|
|
|
|
end
|
|
|
|
|
2011-07-05 21:37:18 +02:00
|
|
|
get '/:year/:month/:day/:title.html' do
|
|
|
|
@post = Post.find_of_day(
|
|
|
|
Time.mktime(params[:year], params[:month], params[:day])
|
|
|
|
).select do |post|
|
|
|
|
params[:title] == post.title.gsub(/ /, '_').downcase
|
|
|
|
end
|
|
|
|
if @post.count > 0
|
|
|
|
@post = @post[0]
|
|
|
|
haml :post_single
|
|
|
|
else
|
|
|
|
404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-05 19:02:26 +02:00
|
|
|
get '/post/:id' do
|
|
|
|
@post = Post.get_released(params[:id])
|
|
|
|
if @post.nil?
|
2011-07-05 19:33:00 +02:00
|
|
|
404
|
2011-07-05 19:02:26 +02:00
|
|
|
else
|
|
|
|
haml :post_single
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-05 19:18:11 +02:00
|
|
|
get '/post/:id/comment.json' do
|
|
|
|
Post.get_released(params[:id]).acknowledged_comments.to_json
|
|
|
|
end
|
|
|
|
|
2011-08-09 22:18:34 +02:00
|
|
|
get '/atom.xml' do
|
|
|
|
@posts = Post.get_page(0)
|
|
|
|
haml :atom, :layout => false
|
|
|
|
end
|
|
|
|
|
2011-06-24 15:40:37 +02:00
|
|
|
get '/stylesheet.css' do
|
|
|
|
scss :stylesheet
|
2011-06-24 13:28:19 +02:00
|
|
|
end
|
2011-06-24 14:21:02 +02:00
|
|
|
|
|
|
|
get '/404' do
|
|
|
|
404
|
|
|
|
end
|
|
|
|
|
|
|
|
error 404 do
|
|
|
|
'where am i? is somebody here? hello?'
|
|
|
|
end
|
|
|
|
|
|
|
|
get '/502' do
|
|
|
|
502
|
|
|
|
end
|
|
|
|
|
|
|
|
error 502 do
|
|
|
|
'oh no, i think i wet myself'
|
|
|
|
end
|
2011-06-24 15:40:37 +02:00
|
|
|
|
|
|
|
def link_to display, link
|
|
|
|
"<a href=\"${link}\">#{display}</a>"
|
|
|
|
end
|
2011-06-30 21:16:10 +02:00
|
|
|
|
|
|
|
def markup content, markup
|
2011-07-27 18:03:17 +02:00
|
|
|
markup = markup.to_sym
|
2011-06-30 21:16:10 +02:00
|
|
|
if respond_to? markup
|
|
|
|
send markup, content
|
|
|
|
else
|
|
|
|
content
|
|
|
|
end
|
|
|
|
end
|
2011-09-29 19:48:59 +02:00
|
|
|
|
|
|
|
def domain path = ''
|
|
|
|
$settings[:domain] + path
|
|
|
|
end
|
|
|
|
|
|
|
|
def title
|
|
|
|
$settings[:title]
|
|
|
|
end
|
|
|
|
|
|
|
|
def subtitle
|
|
|
|
$settings[:subtitle]
|
|
|
|
end
|
2011-06-24 13:28:19 +02:00
|
|
|
end
|