Sha256: 2d261501b77a3fa0226a993f70f968f376523780ad2696f3f90b7dea5198065b

Contents?: true

Size: 762 Bytes

Versions: 6

Compression:

Stored size: 762 Bytes

Contents

module Spontaneous::Output::Context
  module Navigation
    def navigation(opts = {}, &block)
      depth = opts.delete(:depth) || 1
      case depth
      when 0, :root
        root
      when 1, :section
        navigation_at_depth(1, opts, &block)
      else
        navigation_at_depth(depth, opts, &block)
      end
    end

    def navigation_at_depth(depth, opts = {})
      current_page = __target.page
      pages = __pages_at_depth(current_page, depth, opts).map { |p| [p, current_page.active?(p)] }
      if block_given?
        pages.each do |p, active|
          yield(p, active)
        end
      else
        pages
      end
    end

    def __pages_at_depth(origin_page, depth, opts = {})
      origin_page.at_depth(depth, opts)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/output/context/navigation.rb
spontaneous-0.2.0.beta9 lib/spontaneous/output/context/navigation.rb
spontaneous-0.2.0.beta8 lib/spontaneous/output/context/navigation.rb
spontaneous-0.2.0.beta7 lib/spontaneous/output/context/navigation.rb
spontaneous-0.2.0.beta6 lib/spontaneous/output/context/navigation.rb
spontaneous-0.2.0.beta5 lib/spontaneous/output/context/navigation.rb