Sha256: d6c6274a802c4ac381675d1c137185281399b29f4311b412f467e6bff74e788c

Contents?: true

Size: 966 Bytes

Versions: 2

Compression:

Stored size: 966 Bytes

Contents

# encoding: utf-8

module Nanoc3::Helpers

  # Provides support for breadcrumbs, which allow the user to go up in the
  # page hierarchy.
  module Breadcrumbs

    # 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.
    #
    # @return [Array] The breadcrumbs, starting with the root item and ending
    #   with the item itself
    def breadcrumbs_trail
      trail = []
      current_identifier = @item.identifier

      loop do
        item = @items.find { |i| i.identifier == current_identifier }
        trail.unshift(item)
        break if current_identifier == '/'
        current_identifier = current_identifier.sub(/[^\/]+\/$/, '')
      end

      trail
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nanoc3-3.1.0a2 lib/nanoc3/helpers/breadcrumbs.rb
nanoc3-3.1.0a1 lib/nanoc3/helpers/breadcrumbs.rb