Sha256: 727c39d641635abe365c22e2db10f89078eb6bfeed329f01bb3a7fdee3bb7f64

Contents?: true

Size: 1.05 KB

Versions: 9

Compression:

Stored size: 1.05 KB

Contents

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

    def self.controller_path
      "lookbook/pages"
    end

    def index
      landing = Engine.pages.find(&:landing?) || Engine.pages.first
      raise_not_found("Page not found") unless landing.present?

      redirect_to lookbook_page_path(landing.path)
    end

    def show
      @page = @pages.find_by_path(params[:path])
      raise_not_found("Page not found") unless @page

      @page_content = page_controller.render_page(@page)
      @title = @page.title
      @next_page = @pages.next(@page)
      @previous_page = @pages.previous(@page)
    rescue ActionView::Template::Error => err
      raise Lookbook::TemplateError.new(
        original: err,
        file_path: @page.file_path,
        source: @page.content
      )
    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

9 entries across 9 versions & 1 rubygems

Version Path
lookbook-2.3.4 app/controllers/lookbook/pages_controller.rb
lookbook-2.3.3 app/controllers/lookbook/pages_controller.rb
lookbook-2.3.2 app/controllers/lookbook/pages_controller.rb
lookbook-2.3.0 app/controllers/lookbook/pages_controller.rb
lookbook-2.2.2 app/controllers/lookbook/pages_controller.rb
lookbook-2.2.1 app/controllers/lookbook/pages_controller.rb
lookbook-2.2.0 app/controllers/lookbook/pages_controller.rb
lookbook-2.1.1 app/controllers/lookbook/pages_controller.rb
lookbook-2.1.0 app/controllers/lookbook/pages_controller.rb