Skip to content

Commit

Permalink
feat(template-compiler): add more group API
Browse files Browse the repository at this point in the history
  • Loading branch information
LastLeaf committed Nov 20, 2024
1 parent aa37d0b commit 621211d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions glass-easel-template-compiler/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, TmplError> {
let mut w = JsTopScopeWriter::new(String::new());
w.expr_scope(|w| {
Expand Down Expand Up @@ -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<String, TmplError> {
let mut w = JsTopScopeWriter::new(String::new());
w.expr_scope(|w| {
Expand Down Expand Up @@ -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<Item = (&str, &Template)> {
self.trees.iter().map(|(name, tmpl)| (name.as_str(), tmpl))
}
}

0 comments on commit 621211d

Please sign in to comment.