Module: Nanoc3::Helpers::Breadcrumbs
- Defined in:
- lib/nanoc3/helpers/breadcrumbs.rb
Overview
Provides support for breadcrumbs, which allow the user to go up in the page hierarchy.
Instance Method Summary collapse
- #breadcrumbs_for_identifier(identifier) ⇒ Object
-
#breadcrumbs_trail ⇒ Array
Creates a breadcrumb trail leading from the current item to its parent, to its parent’s parent, etc, until the root item is reached.
- #item_with_identifier(identifier) ⇒ Object
Instance Method Details
#breadcrumbs_for_identifier(identifier) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/nanoc3/helpers/breadcrumbs.rb', line 28 def (identifier) @breadcrumbs_cache ||= {} @breadcrumbs_cache[identifier] ||= begin head = (identifier == '/' ? [] : (identifier.sub(/[^\/]+\/$/, '')) ) tail = [ item_with_identifier(identifier) ] head + tail end end |
#breadcrumbs_trail ⇒ Array
Creates a breadcrumb trail leading from the current item to its parent, to its parent’s parent, etc, until the root item is reached. This function does not require that each intermediate item exist; for example, if there is no ‘/foo/` item, breadcrumbs for a `/foo/bar/` item will contain a `nil` element.
17 18 19 |
# File 'lib/nanoc3/helpers/breadcrumbs.rb', line 17 def (@item.identifier) end |
#item_with_identifier(identifier) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/nanoc3/helpers/breadcrumbs.rb', line 21 def item_with_identifier(identifier) @identifier_cache ||= {} @identifier_cache[identifier] ||= begin @items.find { |i| i.identifier == identifier } end end |