From 142c0b8a78d490882981c58988c6825d3f842036 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Sat, 20 Jun 2026 09:32:43 +0300 Subject: Add module/function docs to renderer --- src/renderer.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/renderer.rs b/src/renderer.rs index 90162e6..1db1215 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -1,3 +1,8 @@ +//! Markdown rendering primitives. +//! +//! This module renders project headers and normalized file paths into Markdown. +//! Rendering behavior is controlled by [`RenderOptions`]. + use std::{ fs::File, io::{Read, Write}, @@ -12,8 +17,10 @@ use crate::{ }, }; +/// Default maximum file size, in bytes. Larger files are not included in Markdown output. pub const DEFAULT_MAX_FILE_SIZE: u64 = 1_000_000; +/// Renders files and project metadata as Markdown. #[derive(Debug)] pub struct Renderer { output: W, @@ -24,10 +31,12 @@ pub struct Renderer { } impl Renderer { + /// Creates a renderer with default [`RenderOptions`]. pub fn new_with_defaults(output: W) -> Self { Self::new(output, RenderOptions::default()) } + /// Creates a renderer with explicit rendering options. pub fn new(output: W, config: RenderOptions) -> Self { Self { output, @@ -38,30 +47,39 @@ impl Renderer { } } + /// Sets the maximum file size, in bytes, that will be rendered. pub fn with_max_file_size(mut self, max_file_size: u64) -> Self { self.max_file_size = max_file_size; self } + /// Sets the logger used for warnings and informational messages. pub fn with_logger(mut self, logger: Logger) -> Self { self.logger = logger; self } + /// Controls whether skipped binary files are represented by placeholders. pub fn with_binary_file_placeholder(mut self, placeholder_for_binary_files: bool) -> Self { self.placeholder_for_binary_files = placeholder_for_binary_files; self } + /// Controls whether skipped large files are represented by placeholders. pub fn with_large_file_placeholder(mut self, placeholder_for_large_files: bool) -> Self { self.placeholder_for_large_files = placeholder_for_large_files; self } + /// Renders the top-level project heading. pub fn render_header(&mut self, project_title: &str) -> std::io::Result<()> { writeln!(self.output, "# {}", project_title) } + /// Renders a normalized path. + /// + /// Text files are rendered as fenced Markdown code blocks. Large files and binary files are + /// skipped unless their corresponding placeholder options are enabled. pub fn render_path(&mut self, normalized_path: &NormalizedPath) -> std::io::Result<()> { let metadata = std::fs::metadata(&normalized_path.absolute)?; if metadata.len() > self.max_file_size { @@ -137,10 +155,14 @@ impl Renderer { } } +/// Options controlling how files are rendered. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct RenderOptions { + /// Maximum file size, in bytes, to include in Markdown output. pub max_file_size: u64, + /// Whether skipped binary files should be shown as `[BINARY FILE]`. pub placeholder_for_binary_files: bool, + /// Whether skipped large files should be shown as `[FILE TOO LARGE]`. pub placeholder_for_large_files: bool, } -- cgit v1.3.1