Class: Charming::Components::Breadcrumbs

Inherits:
Charming::Component show all
Defined in:
lib/charming/presentation/components/breadcrumbs.rb

Overview

Breadcrumbs renders a navigation trail like ‘Home › Projects › My App`, with the final (current) item highlighted and ancestors muted.

Constant Summary collapse

DEFAULT_SEPARATOR =
""

Instance Method Summary collapse

Methods inherited from Charming::Component

#captures_text?

Methods inherited from View

#focused?, #layout_assigns

Constructor Details

#initialize(items:, separator: DEFAULT_SEPARATOR, theme: nil) ⇒ Breadcrumbs

items is the trail (strings or anything responding to to_s), first-to-last. separator joins the items.



12
13
14
15
16
# File 'lib/charming/presentation/components/breadcrumbs.rb', line 12

def initialize(items:, separator: DEFAULT_SEPARATOR, theme: nil)
  super(theme: theme)
  @items = Array(items).map(&:to_s)
  @separator = separator
end

Instance Method Details

#renderObject

Renders the trail; ancestors muted, current item in the title style.



19
20
21
22
23
24
25
26
# File 'lib/charming/presentation/components/breadcrumbs.rb', line 19

def render
  return "" if @items.empty?

  *ancestors, current = @items
  parts = ancestors.map { |item| theme.muted.render(item) }
  parts << theme.title.render(current)
  parts.join(theme.muted.render(@separator))
end