Sha256: 2cd320a82e2a4c050a8ffed4779277cd29da916595e3c39df07b2f066793399e

Contents?: true

Size: 884 Bytes

Versions: 12

Compression:

Stored size: 884 Bytes

Contents

module Nanoc::Helpers
  # @see http://nanoc.ws/doc/reference/helpers/#breadcrumbs
  module Breadcrumbs
    class CannotGetBreadcrumbsForNonLegacyItem < Nanoc::Int::Errors::Generic
      def initialize(identifier)
        super("You cannot build a breadcrumbs trail for an item that has a “full” identifier (#{identifier}). Doing so is only possible for items that have a legacy identifier.")
      end
    end

    # @return [Array]
    def breadcrumbs_trail
      unless @item.identifier.legacy?
        raise CannotGetBreadcrumbsForNonLegacyItem.new(@item.identifier)
      end

      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

12 entries across 12 versions & 1 rubygems

Version Path
nanoc-4.4.2 lib/nanoc/helpers/breadcrumbs.rb
nanoc-4.4.1 lib/nanoc/helpers/breadcrumbs.rb
nanoc-4.4.0 lib/nanoc/helpers/breadcrumbs.rb
nanoc-4.3.8 lib/nanoc/helpers/breadcrumbs.rb
nanoc-4.3.7 lib/nanoc/helpers/breadcrumbs.rb
nanoc-4.3.6 lib/nanoc/helpers/breadcrumbs.rb
nanoc-4.3.5 lib/nanoc/helpers/breadcrumbs.rb
nanoc-4.3.4 lib/nanoc/helpers/breadcrumbs.rb
nanoc-4.3.3 lib/nanoc/helpers/breadcrumbs.rb
nanoc-4.3.2 lib/nanoc/helpers/breadcrumbs.rb
nanoc-4.3.1 lib/nanoc/helpers/breadcrumbs.rb
nanoc-4.3.0 lib/nanoc/helpers/breadcrumbs.rb