Repository navigation
Add ability to add more glob loads without deleting old globs - #1045
tronicboy1 wants to merge 16 commits into
Conversation
… loads without deleting old
|
What's the usecase? |
|
I have a project that shares some templates as a base but adds more depending on which deployment it is and what features are enabled. Tera V1 supported my current project structure, now in V2 the same use of glob loading causes it to reset the previous glob load. |
|
In V1, you could use Tera::extend to run glob multiple times. This is how I used it, however in V2 Tera::extend is gone so I cannot use it the same way anymore. |
|
I think this approach is wrong then. You can change the glob field in Tera to be a Vec and add a new fn like |
|
@Keats I changed it here to a Vec and pushed the globs added to it. By all means if you have a better/more elegant solution I would love it. I just need the ability to add multiple glob directories to restore backwards compatibility with the Tera::extend function. I think the fact that I am implementing two features in this PR makes it seem too complicated. I am restoring the ability to extend multiple glob dirs, but also adding the ability for |
| if let Some(glob) = self.glob.clone().as_ref() { | ||
| self.load_from_glob(glob) | ||
| if self.glob.len() > 0 { | ||
| let current_globs = self.glob.clone(); |
There was a problem hiding this comment.
| let current_globs = self.glob.clone(); | |
| let current_globs = std::mem::take(&mut self.glob); |
We could do it this way so there is no memory alloc cost.
|
This is still way too complex. You can probably do it in 20 loc or something. No need to change anything to load_from_glob except pushing it into a vec for example |
|
@Keats |
|
@Keats |
|
|
||
| // Insert globs already registered | ||
| for dir in self.glob.iter() { | ||
| all_glob_entries.extend(load_from_glob(dir)?); |
There was a problem hiding this comment.
this will return in case of errors before putting back the prev_templates/globs back
| let is_new_and_valid = !glob.is_empty() && self.glob.insert(glob.to_string()); | ||
|
|
||
| if is_new_and_valid { | ||
| all_glob_entries.extend(load_from_glob(glob)?); |
| /// let mut tera = Tera::default(); | ||
| /// tera.load_from_glob("examples/basic/templates/**/*").unwrap(); | ||
| /// | ||
| /// tera.load_from_glob("examples/dashboard/**/*").unwrap(); |
There was a problem hiding this comment.
this is a breaking change, the basic load_from_glob should not change, the PR should add a function to add globs
| /// Only used if the `glob_fs` feature is turned on | ||
| #[allow(dead_code)] | ||
| pub(crate) glob: Option<String>, | ||
| pub(crate) glob: HashSet<String>, |
…dd_from_glob to provide multiple glob registration
Changes
load_from_globto be compatible with multiple glob dirs without breaking previous behaviorfull_reloadis compatible with multiple glob dirs