Class: Coradoc::Html::TocSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/coradoc/html/toc_serializer.rb

Overview

Serializes a document’s TOC structure to JSON for inline embedding.

Used by the SPA layout to provide client-side navigation data.

Instance Method Summary collapse

Instance Method Details

#build_json(document, options) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/coradoc/html/toc_serializer.rb', line 9

def build_json(document, options)
  return { entries: [], numbered: false } unless document.is_a?(CoreModel::StructuralElement)

  numbered = options[:section_numbers] == true
  builder = TocBuilder.from_options(options)
  toc = builder.build(document)
  { entries: serialize_entries(toc.entries), numbered: numbered }
end