Sha256: 60ad769adaf88d261530a3ae57f0a5deaf9f14bf6e72031caa87baaf67bf0204

Contents?: true

Size: 883 Bytes

Versions: 65

Compression:

Stored size: 883 Bytes

Contents

# frozen_string_literal: true

module Koi
  module Header
    class NewComponent < ViewComponent::Base
      attr_reader :model

      delegate :with_breadcrumb, :with_action, to: :@header

      def initialize(model:, title: nil)
        super

        @model  = model
        @title  = title

        @header = HeaderComponent.new(title: self.title)
      end

      def call
        render @header do |header|
          # render block, if any (delegating slots to header)
          content

          # add our breadcrumbs and actions
          add_index(header)
        end
      end

      def title
        @title || "New #{model.model_name.human.downcase}"
      end

      def add_index(header)
        header.with_breadcrumb(model.model_name.human.pluralize, url_for(action: :index))
      rescue ActionController::UrlGenerationError
        nil
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
katalyst-koi-4.5.1 app/components/koi/header/new_component.rb
katalyst-koi-4.5.0 app/components/koi/header/new_component.rb
katalyst-koi-4.5.0.beta.2 app/components/koi/header/new_component.rb
katalyst-koi-4.5.0.beta.1 app/components/koi/header/new_component.rb
katalyst-koi-4.4.1 app/components/koi/header/new_component.rb
katalyst-koi-4.4.0 app/components/koi/header/new_component.rb
katalyst-koi-4.3.5 app/components/koi/header/new_component.rb
katalyst-koi-4.3.4 app/components/koi/header/new_component.rb
katalyst-koi-4.3.3 app/components/koi/header/new_component.rb
katalyst-koi-4.3.2 app/components/koi/header/new_component.rb
katalyst-koi-4.3.1 app/components/koi/header/new_component.rb
katalyst-koi-4.3.0 app/components/koi/header/new_component.rb
katalyst-koi-4.3.0.beta.3 app/components/koi/header/new_component.rb
katalyst-koi-4.3.0.beta.2 app/components/koi/header/new_component.rb
katalyst-koi-4.2.1 app/components/koi/header/new_component.rb
katalyst-koi-4.2.0 app/components/koi/header/new_component.rb
katalyst-koi-4.2.0.beta.2 app/components/koi/header/new_component.rb
katalyst-koi-4.2.0.beta.1 app/components/koi/header/new_component.rb
katalyst-koi-4.1.2 app/components/koi/header/new_component.rb
katalyst-koi-4.1.1 app/components/koi/header/new_component.rb