Class: ReVIEW::WEBTOCPrinter

Inherits:
TOCPrinter show all
Includes:
HTMLUtils
Defined in:
lib/review/webtocprinter.rb

Instance Attribute Summary

Attributes inherited from TOCPrinter

#calc_char_width

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HTMLUtils

#escape, #escape_comment, #highlight, #highlight?, #highlight_pygments, #highlight_rouge, #normalize_id, #strip_html, #unescape

Methods inherited from TOCPrinter

#build_chap, #build_result_array, #calc_line_wrapping, #calc_linesize, #calc_pages, #calc_total_count, #execute, execute, #initialize, #parse_contents, #parse_options

Constructor Details

This class inherits a constructor from ReVIEW::TOCPrinter

Class Method Details

.book_to_string(book) ⇒ Object



9
10
11
# File 'lib/review/webtocprinter.rb', line 9

def self.book_to_string(book)
  ReVIEW::WEBTOCPrinter.new.print_book(book)
end

Instance Method Details



13
14
15
16
17
18
# File 'lib/review/webtocprinter.rb', line 13

def print_book(book)
  @book = book
  @indent = nil
  @upper = 1 # only part and chapter
  print_result(build_result_array)
end


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/review/webtocprinter.rb', line 20

def print_result(result_array)
  content = <<EOT
<ul class="book-toc">
<li><a href="index.html">TOP</a></li>
EOT

  path = ''
  result_array.each do |result|
    unless result.headline
      result.headline = '-'
    end

    if result.name
      path = "#{result.name}.#{@book.config['htmlext']}"
      next
    end

    if result.part
      if result.part == 'end'
        content << "</ul></li>\n"
      end
      next
    end

    content << if path.start_with?('.')
                 "<li>#{escape(result.headline)}"
               else
                 %Q(<li><a href="#{path}">#{escape(result.headline)}</a>)
               end
    content << if result.level == 0
                 "\n<ul>" # part
               else
                 "</li>\n"
               end
  end
  content << "</ul>\n"
end