Skip to content

Commit e6ff82e

Browse files
committed
no more handlebar caching
1 parent d8f17ba commit e6ff82e

1 file changed

Lines changed: 16 additions & 34 deletions

File tree

codegenr/src/lib.rs

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,6 @@ pub type OptionsMap = BTreeMap<String, Options>;
2626

2727
type OriginalDocumentsHash = HashMap<loaders::DocumentPath, Rc<Value>>;
2828
type ResolvedDocumentsHash = HashMap<loaders::DocumentPath, Rc<Value>>;
29-
type HandlebarsHash<'a> = HashMap<HandlebarsReusableConf, (String, Handlebars<'a>)>;
30-
31-
#[derive(Debug, PartialEq, Eq, Hash)]
32-
struct HandlebarsReusableConf {
33-
pub templates: Vec<String>,
34-
pub custom_helpers: Vec<String>,
35-
}
3629

3730
#[derive(Error, Debug)]
3831
pub enum SaverError {
@@ -55,11 +48,10 @@ pub struct Options {
5548
pub fn run_all_codegenr(options_map: OptionsMap) -> Result<(), CodegenrError> {
5649
let mut original_cache = Default::default();
5750
let mut resolved_cache = Default::default();
58-
let mut reusables = Default::default();
5951
let mut errors_count = 0;
6052
for (name, options) in options_map {
6153
info!("Running code generation section `{}`", name);
62-
if let Err(e) = run_codegenr(options, &mut original_cache, &mut resolved_cache, &mut reusables) {
54+
if let Err(e) = run_codegenr(options, &mut original_cache, &mut resolved_cache) {
6355
error!("Error while executing the `{}` section: `{}`.", name, e);
6456
errors_count += 1;
6557
}
@@ -78,8 +70,7 @@ pub fn run_all_codegenr(options_map: OptionsMap) -> Result<(), CodegenrError> {
7870
pub fn run_one_codegenr(options: Options) -> Result<(), errors::CodegenrError> {
7971
let mut original_cache = Default::default();
8072
let mut resolved_cache = Default::default();
81-
let mut reusables = Default::default();
82-
run_codegenr(options, &mut original_cache, &mut resolved_cache, &mut reusables)
73+
run_codegenr(options, &mut original_cache, &mut resolved_cache)
8374
}
8475

8576
#[allow(clippy::result_large_err)]
@@ -88,7 +79,6 @@ fn run_codegenr(
8879
options: Options,
8980
original_cache: &mut OriginalDocumentsHash,
9081
resolved_cache: &mut ResolvedDocumentsHash,
91-
reusables: &mut HandlebarsHash,
9282
) -> Result<(), errors::CodegenrError> {
9383
let document = loaders::DocumentPath::parse(&options.source)?;
9484
let json = resolver::resolve_refs(document, original_cache, resolved_cache)?;
@@ -97,30 +87,22 @@ fn run_codegenr(
9787
save_intermediate(&options.intermediate, "resolved.json", &format!("{:#}", json))?;
9888
}
9989

100-
let (main_template_name, mut handlebars) = reusables
101-
.entry(HandlebarsReusableConf {
102-
custom_helpers: options.custom_helpers,
103-
templates: options.templates,
104-
})
105-
.or_insert_with_key(|conf| {
106-
let mut all_templates = vec![];
107-
for t in conf.templates.iter() {
108-
let templates = render::get_templates_from_directory(t).unwrap(); //?;
109-
all_templates.extend(templates);
110-
}
111-
let templates = render::TemplateCollection::from_list(all_templates).unwrap(); //?;
112-
113-
let mut handlebars = Handlebars::new();
114-
helpers::handlebars_misc_setup(&mut handlebars);
115-
helpers::handlebars_stateless_setup(&mut handlebars);
116-
117-
templates.setup_handlebars(&mut handlebars).unwrap(); // todo?;
118-
custom::handlebars_setup(&mut handlebars, &conf.custom_helpers).unwrap(); //?;
119-
(templates.main_template_name().to_owned(), handlebars)
120-
})
121-
.clone();
90+
let mut all_templates = vec![];
91+
for t in options.templates.iter() {
92+
let templates = render::get_templates_from_directory(t)?;
93+
all_templates.extend(templates);
94+
}
12295

96+
let mut handlebars = Handlebars::new();
97+
helpers::handlebars_misc_setup(&mut handlebars);
98+
helpers::handlebars_stateless_setup(&mut handlebars);
12399
helpers::handlebars_statefull_setup(&mut handlebars, options.global_parameters);
100+
custom::handlebars_setup(&mut handlebars, &options.custom_helpers)?;
101+
102+
let templates = render::TemplateCollection::from_list(all_templates)?;
103+
templates.setup_handlebars(&mut handlebars)?;
104+
105+
let main_template_name = templates.main_template_name().to_owned();
124106

125107
let rendered = handlebars.render(&main_template_name, &(*json))?;
126108

0 commit comments

Comments
 (0)