Class: Koi::Header::EditComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Koi::Header::EditComponent
- Defined in:
- app/components/koi/header/edit_component.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #add_index(header) ⇒ Object
- #add_show(header) ⇒ Object
- #call ⇒ Object
-
#initialize(resource:, title: nil) ⇒ EditComponent
constructor
A new instance of EditComponent.
- #resource_title ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(resource:, title: nil) ⇒ EditComponent
Returns a new instance of EditComponent.
10 11 12 13 14 15 16 17 |
# File 'app/components/koi/header/edit_component.rb', line 10 def initialize(resource:, title: nil) super @resource = resource @title = title @header = HeaderComponent.new(title: self.title) end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'app/components/koi/header/edit_component.rb', line 6 def model @model end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
6 7 8 |
# File 'app/components/koi/header/edit_component.rb', line 6 def resource @resource end |
Instance Method Details
#add_index(header) ⇒ Object
45 46 47 48 49 |
# File 'app/components/koi/header/edit_component.rb', line 45 def add_index(header) header.(resource.model_name.human.pluralize, url_for(action: :index)) rescue ActionController::UrlGenerationError nil end |
#add_show(header) ⇒ Object
51 52 53 54 55 |
# File 'app/components/koi/header/edit_component.rb', line 51 def add_show(header) header.(resource_title, url_for(action: :show)) rescue ActionController::UrlGenerationError nil end |
#call ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/components/koi/header/edit_component.rb', line 19 def call render @header do |header| # capture nested component @header = header # render block, if any (delegating slots to header) content # add our breadcrumbs and actions add_index(header) add_show(header) end end |
#resource_title ⇒ Object
37 38 39 40 41 42 43 |
# File 'app/components/koi/header/edit_component.rb', line 37 def resource_title title = Koi.config.resource_name_candidates.reduce(nil) do |name, key| name || resource.respond_to?(key) && resource.public_send(key) end title.presence || resource.model_name.human end |
#title ⇒ Object
33 34 35 |
# File 'app/components/koi/header/edit_component.rb', line 33 def title @title || "Edit #{resource.model_name.human.downcase}" end |