Sha256: 4622fd99b927198c6e605f19129251395e2d908a6a49acba5bc98c3f9a2cfbba

Contents?: true

Size: 933 Bytes

Versions: 4

Compression:

Stored size: 933 Bytes

Contents

# encoding: utf-8

module Nanoc::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      = []
      idx_start  = 0

      loop do
        idx = @item.identifier.to_s.index('/', idx_start)
        break if idx.nil?

        idx_start = idx + 1
        identifier = @item.identifier.to_s[0..idx]
        trail << @items[identifier]
      end

      trail
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nanoc-4.0.0b2 lib/nanoc/helpers/breadcrumbs.rb
nanoc-4.0.0b1 lib/nanoc/helpers/breadcrumbs.rb
nanoc-4.0.0a2 lib/nanoc/helpers/breadcrumbs.rb
nanoc-4.0.0a1 lib/nanoc/helpers/breadcrumbs.rb