mod cache;
pub mod cli;
mod config;
mod context;
mod domain;
mod fs;
mod init;
mod layout;
mod markdown;
mod output;
mod render;
mod workspace;
use domain::Metadata;
use std::path::Path;
use workspace::WorkspaceIndex;
#[cfg(test)]
use workspace::WorkspaceFile;
#[derive(Debug)]
pub(crate) struct RenderCtx<'a> {
pub(crate) workspace: WorkspaceIndex,
pub(crate) root: &'a Path,
pub(crate) dir: &'a Path,
pub(crate) rel_dir: &'a str,
pub(crate) metadata: &'a Metadata,
}
impl RenderCtx<'_> {
#[must_use]
pub(crate) fn is_root(&self) -> bool {
self.rel_dir.is_empty() || self.rel_dir == "."
}
}
#[cfg(test)]
pub(crate) mod test_helpers {
use std::path::Path;
use crate::fs::walk;
use crate::{WorkspaceFile, WorkspaceIndex};
#[must_use]
pub(crate) fn workspace_at(root: &Path) -> WorkspaceIndex {
let (files, _failures) = walk::workspace_source_files(root).into_parts();
let entries = files
.into_iter()
.map(|path| {
let contents = std::fs::read(&path)
.ok()
.and_then(|bytes| String::from_utf8(bytes).ok())
.map(String::into_boxed_str);
WorkspaceFile { path, contents }
})
.collect();
WorkspaceIndex::new(root.to_path_buf(), entries)
}
}