Module: Blogical::Blog

Included in:
Application
Defined in:
app/blogical/blog.rb

Class Method Summary collapse

Class Method Details

.included(app) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/blogical/blog.rb', line 3

def self.included(app)

  # GET /blog
  app.get %r{^/blog/?(\?.*)?$} do
    @posts = options.repository.paginated(Integer(params['page']))
    @pages = options.repository.total_pages
    erb :blog
  end

  # GET /blog/2009/05/12/comma-intro
  app.get '/blog/:year/:month/:day/:title' do |year, month, day, title|
    @post = options.repository.find_by_permalink(title)
    raise Sinatra::NotFound, 'No such post' unless @post
    @title = @post.title
    erb :article
  end

  # GET /assets/2009/05/12/1-filename.pdf
  app.get '/assets/:year/:month/:day/:attachment' do |year, month, day, attachment|
    @attachment = options.repository.find_by_attachment(attachment)
    raise Sinatra::NotFound, 'No such attachment' unless @attachment
    send_file @attachment.content, :disposition => 'attachment'
  end

end