From 621211d474f9635c7b87c5baa199be43f1b1dedc Mon Sep 17 00:00:00 2001 From: LastLeaf Date: Wed, 20 Nov 2024 20:35:55 +0800 Subject: [PATCH] feat(template-compiler): add more group API --- glass-easel-template-compiler/src/group.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/glass-easel-template-compiler/src/group.rs b/glass-easel-template-compiler/src/group.rs index 0c3f732..c66bd0a 100644 --- a/glass-easel-template-compiler/src/group.rs +++ b/glass-easel-template-compiler/src/group.rs @@ -418,7 +418,7 @@ impl TmplGroup { Ok(()) } - /// Convert all to WXML GenObject js string + /// Convert all to WXML GenObject js string. pub fn get_tmpl_gen_object_groups(&self) -> Result { let mut w = JsTopScopeWriter::new(String::new()); w.expr_scope(|w| { @@ -453,7 +453,7 @@ impl TmplGroup { Ok(w.finish()) } - /// Convert all to WXML GenObject js string, with wx environment support + /// Convert all to WXML GenObject js string, with wx environment support. pub fn get_wx_gen_object_groups(&self) -> Result { let mut w = JsTopScopeWriter::new(String::new()); w.expr_scope(|w| { @@ -506,13 +506,18 @@ impl TmplGroup { Ok(w.finish()) } - /// Returns the number of templates in the group + /// Returns the number of templates in the group. pub fn len(&self) -> usize { self.trees.len() } - /// Check if the group contains certain template + /// Check if the group contains certain template. pub fn contains_template(&self, path: &str) -> bool { self.trees.contains_key(path) } + + /// List all available templates. + pub fn list_template_trees(&self) -> impl Iterator { + self.trees.iter().map(|(name, tmpl)| (name.as_str(), tmpl)) + } }