Sha256: 77672f7cdfec6bac1ec5e1217bfb733457d39e02c8745738a316b04004c4192e

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module Doculab
  class DocsController < ApplicationController
    rescue_from Doc::FileNotFound, :with => :handle_file_not_found
    layout :select_layout
    helper TableOfContentsHelper
  
    def index
      find('index')
      response.headers['Cache-Control'] = 'public'
      render :text => @doc.render, :layout => true
    end
  
    def show
      find(params[:permalink])
      response.headers['Cache-Control'] = 'public'
      render :text => @doc.render, :layout => true
    end
  
    protected
      def find(permalink)
        @doc = Doc.find(permalink)
        @page = lookup_page(permalink)
      end
      
      def handle_file_not_found(e)
        @doc = Doc.new(:title => "File Not Found", :content => e.message)
        @page = TableOfContents::Page.new("File Not Found")
        render :text => e.message, :layout => true
      end
      
      def lookup_page(permalink)
        if permalink == 'index'
          TableOfContents::Page.new(Doculab.title)
        elsif page = TableOfContents.lookup(permalink)
          page
        else
          TableOfContents::Page.new(permalink.titleize)
        end
      end
      
      def select_layout
        case params[:permalink]
        when 'index', NilClass
          Doculab.index_layout
        else
          Doculab.main_layout
        end
      end
    # end protected
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
doculab-0.2.0 app/controllers/doculab/docs_controller.rb