Class: Charming::Components::Breadcrumbs
- Inherits:
-
Charming::Component
- Object
- View
- Charming::Component
- Charming::Components::Breadcrumbs
- 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
-
#initialize(items:, separator: DEFAULT_SEPARATOR, theme: nil) ⇒ Breadcrumbs
constructor
items is the trail (strings or anything responding to to_s), first-to-last.
-
#render ⇒ Object
Renders the trail; ancestors muted, current item in the title style.
Methods inherited from Charming::Component
Methods inherited from View
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
#render ⇒ Object
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 |