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)
layout_file = File.join(book.basedir, "layouts", "layout.erb")
end
puts HTMLLayout.new(
{'body' => html, 'title' => "目次"}, layout_file).result
end