Class: Chiridion::Engine::FileWriter

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

Overview

Writes per-file documentation to disk.

Output structure mirrors source structure:

lib/archema/query.rb -> docs/sys/query.md
lib/archema/result.rb -> docs/sys/result.md

Handles smart write detection to avoid unnecessary file updates.

Instance Method Summary collapse

Constructor Details

#initialize(output:, logger:, namespace_strip: nil, include_specs: false, verbose: false, root: Dir.pwd, github_repo: nil, github_branch: "main", project_title: "API Documentation", index_description: nil, inline_source_threshold: 10, templates_path: nil) ⇒ FileWriter

Returns a new instance of FileWriter.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/chiridion/engine/file_writer.rb', line 15

def initialize(
  output:,
  logger:, namespace_strip: nil,
  include_specs: false,
  verbose: false,
  root: Dir.pwd,
  github_repo: nil,
  github_branch: "main",
  project_title: "API Documentation",
  index_description: nil,
  inline_source_threshold: 10,
  templates_path: nil
)
  @output            = output
  @namespace_strip   = namespace_strip
  @verbose           = verbose
  @logger            = logger
  @root              = root
  @index_description = index_description

  @renderer = FileRenderer.new(
    namespace_strip:         namespace_strip,
    include_specs:           include_specs,
    root:                    root,
    github_repo:             github_repo,
    github_branch:           github_branch,
    project_title:           project_title,
    inline_source_threshold: inline_source_threshold,
    templates_path:          templates_path
  )
end

Instance Method Details

#write(project) ⇒ Object

Write all per-file documentation.

Parameters:

  • project (ProjectDoc)

    Documentation structure from SemanticExtractor



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/chiridion/engine/file_writer.rb', line 50

def write(project)
  FileUtils.mkdir_p(@output)

  @renderer.register_classes(project)

  counts = { written: 0, skipped: 0 }

  # Find root file (e.g., lib/archema.rb for Archema::)
  root_file = find_root_file(project.files)

  # Write per-file docs
  project.files.each do |file_doc|
    is_root = root_file && file_doc.path == root_file.path
    write_file_doc(file_doc, counts, is_root: is_root)
  end

  # Always write index.md (root file embeds it via ![[index]])
  write_index(project, counts)

  @logger.info "  #{counts[:written]} files written, #{counts[:skipped]} unchanged"
end