lib/asciibook/book.rb in asciibook-0.0.2 vs lib/asciibook/book.rb in asciibook-0.0.3
- old
+ new
@@ -44,25 +44,28 @@
def cover_image_path
doc.attributes['cover-image']
end
- def toc
- @toc ||= outline(doc)
+ def outline
+ outline_node(doc)
end
- def outline(node)
+ # book outline only list sections that split as page
+ def outline_node(node)
data = []
node.sections.each do |section|
- section_data = {
- 'title' => section.xreftext,
- 'path' => section.page ? section.page.path : "#{find_page_node(section).page.path}##{section.id}"
- }
- if section.sections.count > 0 and section.level < (doc.attributes['toclevels'] || 2).to_i
- section_data['items'] = outline(section)
+ if section.page
+ section_data = {
+ 'title' => section.xreftext,
+ 'path' => section.page.path
+ }
+ if section.sections.count > 0 and section.level < @page_level
+ section_data['items'] = outline_node(section)
+ end
+ data << section_data
end
- data << section_data
end
data
end
def find_page_node(node)
@@ -77,10 +80,10 @@
def to_hash
{
'title' => doc.attributes['doctitle'],
'attributes' => doc.attributes,
- 'toc' => toc
+ 'outline' => outline
}
end
def build
if @formats.include?('html')