Class: ReVIEW::HTMLTOCPrinter

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

Constant Summary

Constants included from HTMLUtils

ReVIEW::HTMLUtils::ESC

Instance Method Summary collapse

Methods included from HTMLUtils

#escape_comment, #escape_html, #highlight, #highlight?, #normalize_id, #strip_html, #unescape_html

Methods inherited from TOCPrinter

default_upper_level, #initialize, #print?

Constructor Details

This class inherits a constructor from ReVIEW::TOCPrinter

Instance Method Details



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/review/tocprinter.rb', line 84

def print_book(book)
  return unless print?(1)
  html = ""
  book.each_part do |part|
    html << h1(part.name) if part.name
    part.each_section do |chap|
      if chap.number
        name = "chap#{chap.number}"
        label = "第#{chap.number}章 #{chap.label}"
        html << h2(a_name(escape_html(name), escape_html(label)))
      else
        label = "#{chap.label}"
        html << h2(escape_html(label))
      end
      return unless print?(2)
      if print?(3)
        html << chap_sections_to_s(chap)
      else
        html << chapter_to_s(chap)
      end
    end
  end
  layout_file = File.join(book.basedir, "layouts", "layout.html.erb")
  unless File.exist?(layout_file) # backward compatibility
    layout_file = File.join(book.basedir, "layouts", "layout.erb")
  end
  puts HTMLLayout.new(
    {'body' => html, 'title' => "目次"}, layout_file).result
end