Class: MiddlemanToc::Toc

Inherits:
Struct
  • Object
show all
Defined in:
lib/middleman_toc/toc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeToc

Returns a new instance of Toc.



7
8
9
10
# File 'lib/middleman_toc/toc.rb', line 7

def initialize(*)
  super
  @root = Builder.new(manifest, pages).build
end

Instance Attribute Details

#pagesObject

Returns the value of attribute pages

Returns:

  • (Object)

    the current value of pages



4
5
6
# File 'lib/middleman_toc/toc.rb', line 4

def pages
  @pages
end

#rootObject (readonly)

Returns the value of attribute root.



5
6
7
# File 'lib/middleman_toc/toc.rb', line 5

def root
  @root
end

Instance Method Details

#next_page(path) ⇒ Object



22
23
24
25
# File 'lib/middleman_toc/toc.rb', line 22

def next_page(path)
  node = next_node(path)
  Tag.new(:a, 'Next', class: 'next', href: "/#{node.path}.html").render if node && node.path
end

#prev_page(path) ⇒ Object



17
18
19
20
# File 'lib/middleman_toc/toc.rb', line 17

def prev_page(path)
  node = prev_node(path)
  Tag.new(:a, 'Previous', class: 'prev', href: "/#{node.path}.html").render if node && node.path
end

#toc(path) ⇒ Object



12
13
14
15
# File 'lib/middleman_toc/toc.rb', line 12

def toc(path)
  root.activate(normalize_path(path))
  root.render
end