Sha256: ab2465b7a9ee54bbb36bd14cb646de5c98f394361d90c6e96537e5c2ea75996e

Contents?: true

Size: 1.35 KB

Versions: 5

Compression:

Stored size: 1.35 KB

Contents

module Lookbook
  class PagesController < ApplicationController
    helper_method :page_controller
    helper Lookbook::PageHelper

    def self.controller_path
      "lookbook/pages"
    end

    def index
      landing = Lookbook.pages.find(&:landing) || Lookbook.pages.first
      if landing.present?
        redirect_to lookbook_page_path landing.lookup_path
      else
        @title = "Not found"
        render "not_found"
      end
    end

    def show
      @pages = Lookbook.pages
      @page = @pages.find_by_path(params[:path])
      if @page
        if @page.errors.any?
          render "lookbook/error", locals: {error: @page.errors.first}
        else
          begin
            @page_content = page_controller.render_page(@page)
            @next_page = @pages.find_next(@page)
            @previous_page = @pages.find_previous(@page)
            @title = @page.title
          rescue => exception
            render "lookbook/error", locals: {
              error: Lookbook::Error.new(exception, file_path: @page.full_path, source_code: @page.content)
            }
          end
        end
      else
        render "not_found"
      end
    end

    protected

    def page_controller
      controller_class = Lookbook.config.page_controller.constantize
      controller = controller_class.new
      controller.request = request
      controller
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lookbook-0.9.8 app/controllers/lookbook/pages_controller.rb
lookbook-0.9.7 app/controllers/lookbook/pages_controller.rb
lookbook-0.9.6 app/controllers/lookbook/pages_controller.rb
lookbook-0.9.5 app/controllers/lookbook/pages_controller.rb
lookbook-0.9.4 app/controllers/lookbook/pages_controller.rb