Class: Chiridion::Engine::SemanticRenderer
- Inherits:
-
Object
- Object
- Chiridion::Engine::SemanticRenderer
- Defined in:
- lib/chiridion/engine/semantic_renderer.rb
Overview
Simplified semantic renderer that outputs structured data.
Rather than formatting for human reading, this outputs all extracted semantic data as JSON (or simple markdown with JSON payload). This helps:
-
Verify what data is being captured vs. missed
-
Debug the extraction pipeline
-
Provide machine-readable documentation for LLMs/agents
-
Separate concerns: extraction vs. presentation
Output format: YAML frontmatter + JSON code fence with all data.
Instance Method Summary collapse
-
#initialize(namespace_strip: nil, project_title: "API Documentation") ⇒ SemanticRenderer
constructor
A new instance of SemanticRenderer.
-
#render(project) ⇒ Hash{String => String}
Render complete project documentation.
-
#render_index(project) ⇒ Object
Render index page.
-
#render_namespace(ns) ⇒ Object
Render a namespace (class or module).
-
#render_type_aliases(project) ⇒ Object
Render type aliases reference.
Constructor Details
#initialize(namespace_strip: nil, project_title: "API Documentation") ⇒ SemanticRenderer
Returns a new instance of SemanticRenderer.
20 21 22 23 |
# File 'lib/chiridion/engine/semantic_renderer.rb', line 20 def initialize(namespace_strip: nil, project_title: "API Documentation") @namespace_strip = namespace_strip @project_title = project_title end |
Instance Method Details
#render(project) ⇒ Hash{String => String}
Render complete project documentation.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/chiridion/engine/semantic_renderer.rb', line 29 def render(project) files = {} # Index files["index.md"] = render_index(project) # Type aliases are embedded where used (in each namespace's referenced_types) # No separate types.md needed. # Each namespace project.namespaces.each do |ns| filename = namespace_to_filename(ns.path) files[filename] = render_namespace(ns) end files end |
#render_index(project) ⇒ Object
Render index page.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/chiridion/engine/semantic_renderer.rb', line 48 def render_index(project) frontmatter = { "generated" => project.generated_at.iso8601, "title" => @project_title, "type" => "index", "description" => project.description || "Auto-generated API documentation", "class_count" => project.classes.size, "module_count" => project.modules.size } classes = project.classes.map { |c| { path: c.path, file: c.file } } modules = project.modules.map { |m| { path: m.path, file: m.file } } body_data = { classes: classes, modules: modules } render_document(frontmatter, body_data) end |
#render_namespace(ns) ⇒ Object
Render a namespace (class or module).
89 90 91 92 93 94 |
# File 'lib/chiridion/engine/semantic_renderer.rb', line 89 def render_namespace(ns) frontmatter = build_frontmatter(ns) body_data = build_body_data(ns) render_document(frontmatter, body_data) end |
#render_type_aliases(project) ⇒ Object
Render type aliases reference.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/chiridion/engine/semantic_renderer.rb', line 70 def render_type_aliases(project) frontmatter = { "generated" => project.generated_at.iso8601, "title" => "Type Aliases Reference", "type" => "reference", "description" => "RBS type aliases defined across the codebase" } # Convert DocumentModel structs to hashes for JSON aliases_by_namespace = project.type_aliases.transform_values do |types| types.map { |t| type_alias_to_hash(t) } end body_data = { type_aliases: aliases_by_namespace } render_document(frontmatter, body_data) end |