Sha256: f806b46c7306ca6d986946fe82e546d49021c88c58f4dc915ef01d004d69c71d

Contents?: true

Size: 1.56 KB

Versions: 7

Compression:

Stored size: 1.56 KB

Contents

module Lookbook
  class ApplicationController < ActionController::Base
    content_security_policy(false) if respond_to?(:content_security_policy)

    protect_from_forgery with: :exception

    helper Lookbook::ApplicationHelper
    helper Lookbook::OutputHelper
    helper Lookbook::ComponentHelper

    before_action :generate_theme_overrides
    before_action :assign_instance_vars

    def self.controller_path
      "lookbook"
    end

    def index
      landing = Lookbook.pages.find(&:landing?) || Lookbook.pages.first
      if landing.present?
        redirect_to lookbook_page_path(landing.path)
      else
        render "lookbook/index"
      end
    end

    protected

    def generate_theme_overrides
      @theme_overrides ||= Lookbook.theme.to_css
    end

    def assign_instance_vars
      @previews = Lookbook.previews
      @pages = Lookbook.pages
      @config = Lookbook.config
      @engine = Lookbook.engine
    end

    def feature_enabled?(feature)
      Lookbook::Features.enabled?(feature)
    end

    def render_in_layout(path, layout: nil, **locals)
      @error = locals[:error]
      render path, layout: layout.presence || (params[:lookbook_embed] ? "lookbook/basic" : "lookbook/application"), locals: locals
    end

    def prettify_error(exception)
      error_params = {}
      if exception.is_a?(ViewComponent::PreviewTemplateError)
        error_params = {
          file_path: @preview&.file_path,
          line_number: 0,
          source_code: @target&.source
        }
      end
      Lookbook::Error.new(exception, **error_params)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lookbook-1.5.0 app/controllers/lookbook/application_controller.rb
lookbook-1.4.5 app/controllers/lookbook/application_controller.rb
lookbook-1.4.4 app/controllers/lookbook/application_controller.rb
lookbook-1.4.3 app/controllers/lookbook/application_controller.rb
lookbook-1.4.2 app/controllers/lookbook/application_controller.rb
lookbook-1.4.1 app/controllers/lookbook/application_controller.rb
lookbook-1.4.0 app/controllers/lookbook/application_controller.rb