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.15.1 app/components/koi/header/new_component.rb
katalyst-koi-4.15.0 app/components/koi/header/new_component.rb
katalyst-koi-4.14.3 app/components/koi/header/new_component.rb
katalyst-koi-4.14.2 app/components/koi/header/new_component.rb
katalyst-koi-4.14.1 app/components/koi/header/new_component.rb
katalyst-koi-4.14.0 app/components/koi/header/new_component.rb
katalyst-koi-4.13.2 app/components/koi/header/new_component.rb
katalyst-koi-4.13.0 app/components/koi/header/new_component.rb
katalyst-koi-4.12.6 app/components/koi/header/new_component.rb
katalyst-koi-4.12.5 app/components/koi/header/new_component.rb
katalyst-koi-4.12.4 app/components/koi/header/new_component.rb
katalyst-koi-4.12.3 app/components/koi/header/new_component.rb
katalyst-koi-4.12.2 app/components/koi/header/new_component.rb
katalyst-koi-4.12.1 app/components/koi/header/new_component.rb
katalyst-koi-4.12.0 app/components/koi/header/new_component.rb
katalyst-koi-4.11.2 app/components/koi/header/new_component.rb
katalyst-koi-4.11.1 app/components/koi/header/new_component.rb
katalyst-koi-4.11.0 app/components/koi/header/new_component.rb
katalyst-koi-4.10.3 app/components/koi/header/new_component.rb
katalyst-koi-4.10.2 app/components/koi/header/new_component.rb