Skip to content

Commit

Permalink
Merge pull request #214 from SgLy/feat-stringify-tmpl-cbindgen
Browse files Browse the repository at this point in the history
feat(template-compiler): add stringify_tmpl for cbindgen
  • Loading branch information
LastLeaf authored Nov 13, 2024
2 parents 7503d8a + d68aeed commit f85b102
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions glass-easel-template-compiler/glass_easel_template_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ int32_t tmpl_group_set_inline_script(TmplGroup *self,
const uint8_t *content_buf,
size_t content_len);

StrRef tmpl_group_stringify_tmpl(const TmplGroup *self, const uint8_t *path_buf, size_t path_len);

void tmpl_parse_warning_array_free(TmplParseWarningArray self);

void tmpl_parse_warning_free(TmplParseWarning self);
Expand Down
6 changes: 6 additions & 0 deletions glass-easel-template-compiler/src/cbinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ impl TmplGroup {
pub unsafe extern "C" fn tmpl_group_export_all_scripts(&self) -> StrRef {
self.inner().export_all_scripts().unwrap_or_default().into()
}

#[no_mangle]
pub unsafe extern "C" fn tmpl_group_stringify_tmpl(&self, path_buf: &u8, path_len: usize) -> StrRef {
let path = String::from_utf8_lossy(slice::from_raw_parts(path_buf, path_len));
self.inner().stringify_tmpl(&path).unwrap_or_default().into()
}
}

impl Drop for TmplGroup {
Expand Down
2 changes: 1 addition & 1 deletion glass-easel-template-compiler/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl TmplGroup {
}

/// Regenerate a template content string of the specified template.
pub fn stringify_tmpl(&mut self, path: &str) -> Option<String> {
pub fn stringify_tmpl(&self, path: &str) -> Option<String> {
let template = self.trees.get(path)?;
let mut stringifier = crate::stringify::Stringifier::new(String::new(), path, "");
template.stringify_write(&mut stringifier).unwrap();
Expand Down

0 comments on commit f85b102

Please sign in to comment.