Hello,
First of all this is an awesome project, I've been using to add template support to one of my projects!
However I noticed I'm not able to to unregister helpers and in addition script_helpers.
I was wondering if there a is a certain reason for this behavior?
The reason why I want to be able to unregister helpers is I want to use script_helpers to add the ability to modify values for certain templates the user could write, but I believe the only way to register a script_helper or helper is to register it globally to the Handlebars struct.
I took a quick look at the code for the registry module:
|
/// Register a helper |
|
pub fn register_helper(&mut self, name: &str, def: Box<dyn HelperDef + Send + Sync + 'reg>) { |
|
self.helpers.insert(name.to_string(), def.into()); |
|
} |
It looks like it just adds the boxed HelperDef trait to a HashMap, so couldn't there be a function like the following that does the opposite?:
/// Unregister a helper
pub fn unregister_helper(&mut self, name: &str) {
self.helpers.remove(name);
}
I would be happy to create a pull request if this is and acceptable solution.
If this feature doesn't get added I don't mind, as I believe I can just clone the Handlebars struct in rendering function of my project then register the helpers so it creates a temporary registration, though I haven't tested this solution yet.
Hello,
First of all this is an awesome project, I've been using to add template support to one of my projects!
However I noticed I'm not able to to unregister
helpersand in additionscript_helpers.I was wondering if there a is a certain reason for this behavior?
The reason why I want to be able to unregister helpers is I want to use
script_helpersto add the ability to modify values for certain templates the user could write, but I believe the only way to register ascript_helperorhelperis to register it globally to theHandlebarsstruct.I took a quick look at the code for the
registrymodule:handlebars-rust/src/registry.rs
Lines 489 to 492 in 507cbf2
It looks like it just adds the boxed
HelperDeftrait to aHashMap, so couldn't there be a function like the following that does the opposite?:I would be happy to create a pull request if this is and acceptable solution.
If this feature doesn't get added I don't mind, as I believe I can just clone the
Handlebarsstruct in rendering function of my project then register the helpers so it creates a temporary registration, though I haven't tested this solution yet.