Class: Chiridion::Engine::Renderer
- Inherits:
-
Object
- Object
- Chiridion::Engine::Renderer
- Defined in:
- lib/chiridion/engine/renderer.rb
Overview
Renders documentation to Obsidian-compatible markdown.
Uses Liquid templates for the document body content, while YAML frontmatter is rendered directly in Ruby due to its complex formatting requirements (flow vs block arrays, proper quoting, etc.).
## Template Customization
Templates are loaded from the gem’s templates/ directory by default. Override by passing a custom templates_path to the constructor.
## Enhanced Frontmatter
All generated documents include enhanced YAML frontmatter for Obsidian:
-
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
-
#initialize(namespace_strip:, include_specs:, root: Dir.pwd, github_repo: nil, github_branch: "main", project_title: "API Documentation", index_description: nil, templates_path: nil, inline_source_threshold: 10, rbs_attr_types: {}) ⇒ Renderer
constructor
A new instance of Renderer.
-
#register_classes(structure) ⇒ Object
Register known classes for cross-reference linking and inheritance.
-
#render_class(klass) ⇒ String
Render class documentation.
-
#render_index(structure) ⇒ String
Render the documentation index.
-
#render_module(mod) ⇒ String
Render module documentation.
-
#render_type_aliases(type_aliases) ⇒ String
Render type aliases reference page.
Constructor Details
#initialize(namespace_strip:, include_specs:, root: Dir.pwd, github_repo: nil, github_branch: "main", project_title: "API Documentation", index_description: nil, templates_path: nil, inline_source_threshold: 10, rbs_attr_types: {}) ⇒ Renderer
Returns a new instance of Renderer.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/chiridion/engine/renderer.rb', line 23 def initialize( namespace_strip:, include_specs:, root: Dir.pwd, github_repo: nil, github_branch: "main", project_title: "API Documentation", index_description: nil, templates_path: nil, inline_source_threshold: 10, rbs_attr_types: {} ) @namespace_strip = namespace_strip @include_specs = include_specs @root = root @index_description = index_description || "Auto-generated from source code." @inline_source_threshold = inline_source_threshold @rbs_attr_types = rbs_attr_types || {} @class_linker = ClassLinker.new(namespace_strip: namespace_strip) @github_linker = GithubLinker.new(repo: github_repo, branch: github_branch, root: root) @frontmatter_builder = FrontmatterBuilder.new( @class_linker, namespace_strip: namespace_strip, project_title: project_title ) @template_renderer = TemplateRenderer.new(templates_path: templates_path) end |
Instance Method Details
#register_classes(structure) ⇒ Object
Register known classes for cross-reference linking and inheritance.
54 55 56 57 |
# File 'lib/chiridion/engine/renderer.rb', line 54 def register_classes(structure) @class_linker.register_classes(structure) @frontmatter_builder.register_inheritance(structure) end |
#render_class(klass) ⇒ String
Render class documentation.
88 |
# File 'lib/chiridion/engine/renderer.rb', line 88 def render_class(klass) = render_document(klass, include_mixins: true) |
#render_index(structure) ⇒ String
Render the documentation index.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/chiridion/engine/renderer.rb', line 63 def render_index(structure) frontmatter = @frontmatter_builder.build_index classes = structure[:classes].map do |c| { path: c[:path], link_path: link(c[:path]) } end modules = structure[:modules].map do |m| { path: m[:path], link_path: link(m[:path]) } end body = @template_renderer.render_index( title: frontmatter[:title], description: @index_description, classes: classes, modules: modules ) "#{render_frontmatter(frontmatter)}\n\n#{body}\n" end |
#render_module(mod) ⇒ String
Render module documentation.
94 |
# File 'lib/chiridion/engine/renderer.rb', line 94 def render_module(mod) = render_document(mod, include_mixins: false) |
#render_type_aliases(type_aliases) ⇒ String
Render type aliases reference page.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/chiridion/engine/renderer.rb', line 100 def render_type_aliases(type_aliases) return nil if type_aliases.nil? || type_aliases.empty? frontmatter = { generated: Time.now.utc.iso8601, title: "Type Aliases Reference", type: "reference", description: "RBS type aliases defined across the codebase", tags: %w[types rbs reference] } # Convert to array format for template namespaces = type_aliases.map do |namespace, types| { name: namespace.empty? ? "(root)" : namespace, types: types.map do |t| { name: t[:name], definition: t[:definition], description: t[:description] } end } end.sort_by { |ns| ns[:name] } body = @template_renderer.render_type_aliases( title: "Type Aliases Reference", description: "RBS type aliases defined across the codebase. " \ "These types can be referenced in `@rbs` annotations.", namespaces: namespaces ) "#{render_frontmatter(frontmatter)}\n\n#{body}\n" end |