Class: Chiridion::Engine::FrontmatterBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/chiridion/engine/frontmatter_builder.rb

Overview

Builds enhanced YAML frontmatter for documentation files.

Generates Obsidian-compatible frontmatter with navigation aids, discovery metadata, and search-friendly fields. Each documentation file gets frontmatter that enables:

  • Navigation: parent links for breadcrumb traversal

  • Discovery: tags for filtering, related links for exploration

  • Search: aliases for finding by short name, description for preview

Instance Method Summary collapse

Constructor Details

#initialize(class_linker, namespace_strip: nil, project_title: "API Documentation") ⇒ FrontmatterBuilder

Returns a new instance of FrontmatterBuilder.



17
18
19
20
21
22
# File 'lib/chiridion/engine/frontmatter_builder.rb', line 17

def initialize(class_linker, namespace_strip: nil, project_title: "API Documentation")
  @class_linker         = class_linker
  @namespace_strip      = namespace_strip
  @project_title        = project_title
  @inheritance_children = {} # Maps parent class path -> array of child class paths
end

Instance Method Details

#build(obj) ⇒ Hash

Build frontmatter hash for a class or module.

Parameters:

  • obj (Hash)

    Extracted object data from Extractor

Returns:

  • (Hash)

    Frontmatter fields in render order



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/chiridion/engine/frontmatter_builder.rb', line 45

def build(obj)
  {
    generated:    Time.now.utc.iso8601,
    title:        obj[:path],
    type:         obj[:type].to_s, # :class or :module
    source:       relative_path(obj[:file]),
    description:  extract_description(obj[:docstring]),
    inherits:     build_inherits_link(obj[:superclass]),
    parent:       build_parent_link(obj[:path]),
    inherited_by: build_inherited_by_links(obj[:path]),
    includes:     build_mixin_list(obj[:includes]),
    extends:      build_mixin_list(obj[:extends]),
    rbs:          obj[:rbs_file] ? relative_path(obj[:rbs_file]) : nil,
    tags:         build_tags(obj[:path]),
    aliases:      build_aliases(obj[:path]),
    constants:    build_constant_list(obj[:constants]),
    methods:      build_method_list(obj[:methods], obj[:path]),
    related:      build_related(obj)
  }.compact
end

#build_indexHash

Build frontmatter for index page.

Returns:

  • (Hash)

    Minimal frontmatter for index



69
70
71
72
73
74
75
# File 'lib/chiridion/engine/frontmatter_builder.rb', line 69

def build_index
  {
    generated: Time.now.utc.iso8601,
    title:     @project_title,
    tags:      %w[index api-reference]
  }
end

#register_inheritance(structure) ⇒ Object

Pre-compute inheritance relationships from full structure.

Must be called before build() to populate inherited-by fields. Scans all classes to build parent->children mapping.

Parameters:

  • structure (Hash)

    Full documentation structure from Extractor



30
31
32
33
34
35
36
37
38
39
# File 'lib/chiridion/engine/frontmatter_builder.rb', line 30

def register_inheritance(structure)
  @inheritance_children = {}
  structure[:classes].each do |klass|
    parent = klass[:superclass]
    next unless parent && documentable_class?(parent)

    @inheritance_children[parent] ||= []
    @inheritance_children[parent] << klass[:path]
  end
end