Class: Koi::Header::NewComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/koi/header/new_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:, title: nil) ⇒ NewComponent

Returns a new instance of NewComponent.



10
11
12
13
14
15
16
17
# File 'app/components/koi/header/new_component.rb', line 10

def initialize(model:, title: nil)
  super

  @model  = model
  @title  = title

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

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



6
7
8
# File 'app/components/koi/header/new_component.rb', line 6

def model
  @model
end

Instance Method Details

#add_index(header) ⇒ Object



33
34
35
36
37
# File 'app/components/koi/header/new_component.rb', line 33

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

#callObject



19
20
21
22
23
24
25
26
27
# File 'app/components/koi/header/new_component.rb', line 19

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

#titleObject



29
30
31
# File 'app/components/koi/header/new_component.rb', line 29

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