diff --git a/glass-easel-template-compiler/glass_easel_template_compiler.h b/glass-easel-template-compiler/glass_easel_template_compiler.h index 575c257..5f612ac 100644 --- a/glass-easel-template-compiler/glass_easel_template_compiler.h +++ b/glass-easel-template-compiler/glass_easel_template_compiler.h @@ -114,6 +114,10 @@ TmplGroup tmpl_group_new(); TmplGroup tmpl_group_new_dev(); +bool tmpl_group_remove_script(TmplGroup *self, const uint8_t *path_buf, size_t path_len); + +bool tmpl_group_remove_tmpl(TmplGroup *self, const uint8_t *path_buf, size_t path_len); + void tmpl_group_set_extra_runtime_script(TmplGroup *self, const uint8_t *content_buf, size_t content_len); diff --git a/glass-easel-template-compiler/src/cbinding.rs b/glass-easel-template-compiler/src/cbinding.rs index 48a40fa..0af47f3 100644 --- a/glass-easel-template-compiler/src/cbinding.rs +++ b/glass-easel-template-compiler/src/cbinding.rs @@ -172,6 +172,16 @@ impl TmplGroup { ) } + #[no_mangle] + pub unsafe extern "C" fn tmpl_group_remove_tmpl( + &mut self, + path_buf: &u8, + path_len: usize, + ) -> bool { + let path = String::from_utf8_lossy(slice::from_raw_parts(path_buf, path_len)); + self.inner_mut().remove_tmpl(&path) + } + #[no_mangle] pub unsafe extern "C" fn tmpl_group_add_script( &mut self, @@ -185,6 +195,16 @@ impl TmplGroup { self.inner_mut().add_script(&path, &content); } + #[no_mangle] + pub unsafe extern "C" fn tmpl_group_remove_script( + &mut self, + path_buf: &u8, + path_len: usize, + ) -> bool { + let path = String::from_utf8_lossy(slice::from_raw_parts(path_buf, path_len)); + self.inner_mut().remove_script(&path) + } + #[no_mangle] pub unsafe extern "C" fn tmpl_group_get_direct_dependencies( &self, diff --git a/glass-easel-template-compiler/src/group.rs b/glass-easel-template-compiler/src/group.rs index 792fd34..8208c19 100644 --- a/glass-easel-template-compiler/src/group.rs +++ b/glass-easel-template-compiler/src/group.rs @@ -219,6 +219,16 @@ impl TmplGroup { ret } + /// Remove a template from the group. + /// + /// This simply removes a template path. + /// It is useful when doing hot-update debugging, + /// but not suitable for final builds since it does not do cleanups. + /// Returns true when a template is actually removed. + pub fn remove_tmpl(&mut self, path: &str) -> bool { + self.trees.remove(path).is_some() + } + /// Regenerate a template content string of the specified template. pub fn stringify_tmpl(&mut self, path: &str) -> Option { let template = self.trees.get(path)?; @@ -247,6 +257,16 @@ impl TmplGroup { self.has_scripts = true; } + /// Remove a script segment from the group. + /// + /// This simply removes a script path. + /// It is useful when doing hot-update debugging, + /// but not suitable for final builds since it does not do cleanups. + /// Returns true when a script is actually removed. + pub fn remove_script(&mut self, path: &str) -> bool { + self.scripts.remove(path).is_some() + } + /// Set extra runtime JavaScript code as a string. /// /// The `content` must be valid JavaScript statements, ended by semicolon. diff --git a/glass-easel-template-compiler/src/js_bindings.rs b/glass-easel-template-compiler/src/js_bindings.rs index ee6df7d..22b362b 100644 --- a/glass-easel-template-compiler/src/js_bindings.rs +++ b/glass-easel-template-compiler/src/js_bindings.rs @@ -84,6 +84,12 @@ impl TmplGroup { serde_wasm_bindgen::to_value(&ret).unwrap() } + #[wasm_bindgen(js_name = removeTmpl)] + pub fn remove_tmpl(&mut self, path: &str) -> bool { + let path = crate::path::normalize(path); + self.group.remove_tmpl(&path) + } + /// Regenerate a template content string for the specified template. #[wasm_bindgen(js_name = stringifyTmpl)] pub fn stringify_tmpl(&mut self, path: &str) -> Option { @@ -97,6 +103,12 @@ impl TmplGroup { self.group.add_script(&path, tmpl_str); } + #[wasm_bindgen(js_name = removeScript)] + pub fn remove_script(&mut self, path: &str) -> bool { + let path = crate::path::normalize(path); + self.group.remove_script(&path) + } + #[wasm_bindgen(js_name = "getDirectDependencies")] pub fn get_direct_dependencies(&self, path: &str) -> Result { let dependencies = self.group.direct_dependencies(&path)?;