1use std::path::Path;
15
16use yog_formats::book::page_type::{PageType, compile, is_book_page};
17
18use crate::yui::{self, Element};
19
20pub fn is_book_ui(root: &Element) -> bool {
23 is_book_page(root) || yog_formats::book::layout::is_recipe_layout(root)
24}
25
26pub fn find(root: &Path, ns: &str, errors: &mut Vec<String>) -> Vec<PageType> {
28 let mut out = Vec::new();
29 for file in yui::find_yui_files(&root.join("src")) {
30 let Ok(text) = std::fs::read_to_string(&file) else { continue };
31 let Ok(el) = yui::parse_xml(&text) else { continue };
32 if !is_book_page(&el) {
33 continue;
34 }
35 let shown = file.strip_prefix(root).unwrap_or(&file).display().to_string();
36 match compile(&el, ns) {
37 Ok(t) => out.push(t),
38 Err(e) => errors.push(format!("{shown}: {e}")),
39 }
40 }
41 out
42}
43
44pub fn find_layouts(root: &Path, ns: &str, errors: &mut Vec<String>) -> Vec<(String, yog_formats::book::layout::RecipeLayout)> {
46 let mut out = Vec::new();
47 for file in yui::find_yui_files(&root.join("src")) {
48 let Ok(text) = std::fs::read_to_string(&file) else { continue };
49 let Ok(el) = yui::parse_xml(&text) else { continue };
50 if !yog_formats::book::layout::is_recipe_layout(&el) {
51 continue;
52 }
53 let shown = file.strip_prefix(root).unwrap_or(&file).display().to_string();
54 match yog_formats::book::layout::compile(&el, ns) {
55 Ok(l) => out.push((shown, l)),
56 Err(e) => errors.push(format!("{shown}: {e}")),
57 }
58 }
59 out
60}