summaryrefslogtreecommitdiff
path: root/app/controllers/pages_controller.rb
blob: 3e7609262c4a4147dc49bd8e85cf85b5293441f6 (plain)
1
2
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class PagesController < ApplicationController

  class PageNotFound < Exception; end

  layout :choose_layout
  rescue_from ActionView::MissingTemplate, :with => :render_404
  rescue_from PageNotFound, :with => :render_404

  def show
    @page = site.find_pages(params[:page])
    if @page
      respond_to do |format|
        format.html { render_page(@page) }
        format.atom { render_atom_feed(@page) }
      end
    else
      logger.error("ERROR: could not find page %s" % params[:page])
      raise PageNotFound.new
    end
  end

  protected

  def choose_layout
    if @page && @page.props && @page.props.layout
      @page.props.layout
    else
      'application'
    end
  end

  def render_atom_feed(root)
    if root
      @pages = root.all_children.order_by(:posted_at, :direction => :desc).limit(site.pagination_size)
      if @pages.any?
        render :file => 'layouts/blog/feed', :layout => false, :content_type => 'application/atom+xml'
      else
        render_404
      end
    end
  end

end