use std::path::Path;
use yog_formats::book::page_type::{PageType, compile, is_book_page};
use crate::yui::{self, Element};
pub fn is_book_ui(root: &Element) -> bool {
is_book_page(root) || yog_formats::book::layout::is_recipe_layout(root)
}
pub fn find(root: &Path, ns: &str, errors: &mut Vec<String>) -> Vec<PageType> {
let mut out = Vec::new();
for file in yui::find_yui_files(&root.join("src")) {
let Ok(text) = std::fs::read_to_string(&file) else { continue };
let Ok(el) = yui::parse_xml(&text) else { continue };
if !is_book_page(&el) {
continue;
}
let shown = file.strip_prefix(root).unwrap_or(&file).display().to_string();
match compile(&el, ns) {
Ok(t) => out.push(t),
Err(e) => errors.push(format!("{shown}: {e}")),
}
}
out
}
pub fn find_layouts(root: &Path, ns: &str, errors: &mut Vec<String>) -> Vec<(String, yog_formats::book::layout::RecipeLayout)> {
let mut out = Vec::new();
for file in yui::find_yui_files(&root.join("src")) {
let Ok(text) = std::fs::read_to_string(&file) else { continue };
let Ok(el) = yui::parse_xml(&text) else { continue };
if !yog_formats::book::layout::is_recipe_layout(&el) {
continue;
}
let shown = file.strip_prefix(root).unwrap_or(&file).display().to_string();
match yog_formats::book::layout::compile(&el, ns) {
Ok(l) => out.push((shown, l)),
Err(e) => errors.push(format!("{shown}: {e}")),
}
}
out
}