Class: Chiridion::Engine::FileRenderer
- Inherits:
-
Object
- Object
- Chiridion::Engine::FileRenderer
- Defined in:
- lib/chiridion/engine/file_renderer.rb
Overview
Renders per-file documentation using Liquid templates.
Takes FileDoc structures from SemanticExtractor and produces markdown files grouped by source file rather than by class/module.
Design: One markdown file per source file. Each file contains documentation for all namespaces (classes/modules) defined in that source file.
Instance Method Summary collapse
-
#initialize(namespace_strip: nil, include_specs: false, root: Dir.pwd, github_repo: nil, github_branch: "main", project_title: "API Documentation", inline_source_threshold: 10, templates_path: nil) ⇒ FileRenderer
constructor
A new instance of FileRenderer.
-
#register_classes(project) ⇒ Object
Register known classes for cross-reference linking.
-
#render_file(file_doc, is_root: false) ⇒ String
Render documentation for a single source file.
-
#render_index(project, index_description: nil) ⇒ String
Render the documentation index.
Constructor Details
#initialize(namespace_strip: nil, include_specs: false, root: Dir.pwd, github_repo: nil, github_branch: "main", project_title: "API Documentation", inline_source_threshold: 10, templates_path: nil) ⇒ FileRenderer
Returns a new instance of FileRenderer.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/chiridion/engine/file_renderer.rb', line 13 def initialize( namespace_strip: nil, include_specs: false, root: Dir.pwd, github_repo: nil, github_branch: "main", project_title: "API Documentation", inline_source_threshold: 10, templates_path: nil ) @namespace_strip = namespace_strip @include_specs = include_specs @root = root @project_title = project_title @inline_source_threshold = inline_source_threshold @class_linker = ClassLinker.new(namespace_strip: namespace_strip) @github_linker = GithubLinker.new(repo: github_repo, branch: github_branch, root: root) @template_renderer = TemplateRenderer.new(templates_path: templates_path) end |
Instance Method Details
#register_classes(project) ⇒ Object
Register known classes for cross-reference linking.
36 37 38 39 40 41 42 |
# File 'lib/chiridion/engine/file_renderer.rb', line 36 def register_classes(project) structure = { classes: project.classes.map { |c| { path: c.path } }, modules: project.modules.map { |m| { path: m.path } } } @class_linker.register_classes(structure) end |
#render_file(file_doc, is_root: false) ⇒ String
Render documentation for a single source file.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/chiridion/engine/file_renderer.rb', line 49 def render_file(file_doc, is_root: false) frontmatter = build_file_frontmatter(file_doc, is_root: is_root) namespaces_data = file_doc.namespaces.map { |ns| build_namespace_data(ns) } body = @template_renderer.render_file( path: file_doc.path, filename: file_doc.filename, line_count: file_doc.line_count, namespaces: namespaces_data, type_aliases: [] # Type aliases are now per-namespace ) # If this is the root file, embed the index using Obsidian transclusion body = "#{body}\n\n---\n\n![[index]]" if is_root "#{render_frontmatter(frontmatter)}\n\n#{body}\n" end |
#render_index(project, index_description: nil) ⇒ String
Render the documentation index.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/chiridion/engine/file_renderer.rb', line 73 def render_index(project, index_description: nil) frontmatter = { generated: project.generated_at.iso8601, title: @project_title, type: "index", description: index_description || "Auto-generated from source code." } # Group by file for per-file index files = project.files.map do |f| link_path = source_to_link(f.path) primary = f.primary_namespace { path: f.path, link_path: link_path, filename: f.filename, namespaces: f.namespaces.map(&:path).join(", "), primary: primary&.path || f.filename } end body = render_file_index(files) "#{render_frontmatter(frontmatter)}\n\n#{body}\n" end |