# File lib/review/tocprinter.rb, line 83 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
# File lib/review/tocprinter.rb, line 156 def a_name(name, label) %Q(<a name="#{name}">#{label}</a>) end
# File lib/review/tocprinter.rb, line 115 def chap_sections_to_s(chap) res = [] res << "<ol>" chap.each_section do |sec| res << li(escape_html(sec.label)) end res << "</ol>" return res.join("\n") end
# File lib/review/tocprinter.rb, line 140 def h1(label) "<h1>#{label}</h1>" end
# File lib/review/tocprinter.rb, line 144 def h2(label) "<h2>#{label}</h2>" end
# File lib/review/tocprinter.rb, line 148 def h3(label) "<h3>#{label}</h3>" end
# File lib/review/tocprinter.rb, line 152 def li(content) "<li>#{content}</li>" end
# File lib/review/tocprinter.rb, line 125 def print_chapter_to_s(chap) res = [] chap.each_section do |sec| res << h3(escape_html(sec.label)) next unless print?(4) next if sec.n_sections == 0 res << "<ul>" sec.each_section do |node| res << li(escape_html(node.label)) end res << "</ul>" end return res.join("\n") end