Class: Koi::SummaryList::Base

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
Katalyst::HtmlAttributes
Defined in:
app/components/koi/summary_list/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(model, attribute, label: nil, skip_blank: true) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
16
17
18
# File 'app/components/koi/summary_list/base.rb', line 11

def initialize(model, attribute, label: nil, skip_blank: true)
  super()

  @model      = model
  @attribute  = attribute
  @label      = label
  @skip_blank = skip_blank
end

Instance Method Details

#attribute_nameObject



29
30
31
# File 'app/components/koi/summary_list/base.rb', line 29

def attribute_name
  @label&.dig(:text) || @model.class.human_attribute_name(@attribute)
end

#attribute_valueObject



33
34
35
# File 'app/components/koi/summary_list/base.rb', line 33

def attribute_value
  raw_value.to_s
end

#callObject



20
21
22
23
# File 'app/components/koi/summary_list/base.rb', line 20

def call
  tag.dt(attribute_name, **term_attributes) +
    tag.dd(content_or_value, **description_attributes)
end

#inspectObject



41
42
43
# File 'app/components/koi/summary_list/base.rb', line 41

def inspect
  "#<#{self.class.name} #{@attribute.inspect}>"
end

#raw_valueObject



37
38
39
# File 'app/components/koi/summary_list/base.rb', line 37

def raw_value
  @model.public_send(@attribute)
end

#render?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/components/koi/summary_list/base.rb', line 25

def render?
  raw_value.present? || !@skip_blank
end

#to_sObject

Convenience method for rendering the content of the cell <% dl.text(:name) { |cell| tag.em(cell) } %>

> <dt>Name</dt><dd>Jamie Banks</dd>



48
49
50
# File 'app/components/koi/summary_list/base.rb', line 48

def to_s
  attribute_value
end