class Juli::Visitor::Html::Helper::Contents

Helper-class for 'contents' helper

Public Instance Methods

on_root(in_file, root, visitor = nil) click to toggle source

called on each parsed document

# File lib/juli/visitor/html/helper/contents.rb, line 51
def on_root(in_file, root, visitor = nil)
  @root = root
end
run(*args) click to toggle source

implementation of:

contents

which draws contents(a.k.a. outline) of this document.

This visits document tree by ContentsDrawer visitor and generate HTML contents list.

# File lib/juli/visitor/html/helper/contents.rb, line 62
def run(*args)
  contents_drawer = ContentsDrawer.new
  chapter_checker = ChapterChecker.new
  @root.accept(chapter_checker)
  if chapter_checker.chapter_exists
    contents_drawer.content_tag(:b, I18n.t('contents')) +
    contents_drawer.content_tag(:ol) do
      @root.accept(contents_drawer)
    end
  else
    ''
  end
end