lib/brief/model/serializers.rb in brief-1.10.0 vs lib/brief/model/serializers.rb in brief-1.10.1

- old
+ new

@@ -22,11 +22,13 @@ id: Digest::MD5.hexdigest(path.to_s), hash: file_hash, sections: {}, section_headings: [], }.tap do |h| + h[:content] = document.combined_data_and_content if options[:content] || options[:include_content] + h[:rendered] = document.to_html if options[:rendered] || options[:include_rendered] if options[:attachments] || options[:include_attachments] h[:attachments] = document.render_attachments h[:attachment_paths] = document.attachment_paths @@ -39,13 +41,25 @@ update_url: "/update/#{ doc_path }", remove_url: "/remove/#{ doc_path }", schema_url: "/schema/#{ type }", actions_url: "/actions/:action/#{ doc_path }" } if options[:urls] || options[:include_urls] - end.tap do |h| + if document.has_sections? h[:section_headings] = document.section_headings h[:sections] = document.sections_data + + structure = document.structure + + h[:structure] = { + highest_level: structure.highest_level, + lowest_level: structure.lowest_level, + headings_by_level: (structure.levels.reduce({}) do |m, l| + headings = structure.headings_at_level(l.to_i) + m[l.to_s] = headings.map(&:heading) + m + end) + } end end end end