moss-core 0.2.0

Pure-Rust content engine for moss: AST, render, resolve, validate, frontmatter, schema.
Documentation
//! Directory-shaped resolution capability (injected; pure core).
//! Build impl is backed by the content graph + html_files; the editor impl
//! by read_dir. Separate from AssetIndex because the backing data and the
//! query shape (is_dir / markdown-index / static-index) differ.

pub trait FolderIndex {
    /// Does a directory exist at this root-relative path?
    fn is_dir(&self, root_rel: &str) -> bool;
    /// Does this folder resolve a markdown index (→ FolderListing)?
    /// Build: a doc whose url_path is this folder's index URL (covers
    /// content-folder promotion). Editor: FS index.md/README.md/_index.md.
    fn dir_has_markdown_index(&self, root_rel: &str) -> bool;
    /// Does this folder have a static index.html/.htm (and no markdown index)?
    /// Returns the index filename (→ FolderIndexIframe).
    fn dir_has_static_index(&self, root_rel: &str) -> Option<String>;
}

#[cfg(test)]
pub(crate) struct FakeFolderIndex {
    pub dirs: std::collections::HashSet<String>,
    pub md_index: std::collections::HashSet<String>,
    pub static_index: std::collections::HashMap<String, String>,
}

#[cfg(test)]
impl FakeFolderIndex {
    pub fn new() -> Self {
        FakeFolderIndex {
            dirs: Default::default(),
            md_index: Default::default(),
            static_index: Default::default(),
        }
    }
}

#[cfg(test)]
impl FolderIndex for FakeFolderIndex {
    fn is_dir(&self, p: &str) -> bool {
        self.dirs.contains(p)
    }
    fn dir_has_markdown_index(&self, p: &str) -> bool {
        self.md_index.contains(p)
    }
    fn dir_has_static_index(&self, p: &str) -> Option<String> {
        self.static_index.get(p).cloned()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn fake_reports_dir_kinds() {
        let mut idx = FakeFolderIndex::new();
        idx.dirs.insert("Resources/app".into());
        idx.static_index
            .insert("Resources/app".into(), "index.html".into());
        assert!(idx.is_dir("Resources/app"));
        assert!(!idx.dir_has_markdown_index("Resources/app"));
        assert_eq!(
            idx.dir_has_static_index("Resources/app"),
            Some("index.html".into())
        );
    }
}