Skip to content

Commit 506088e

Browse files
authored
fix: Adding functions to allow backup current config before overwriting it and use it in case of create_new_note_from_template (#1611)
1 parent b2917d6 commit 506088e

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

src/core/Templater.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ export class Templater {
7474
};
7575
}
7676

77+
get_current_running_config(): RunningConfig {
78+
return this.functions_generator.get_config();
79+
}
80+
7781
async read_and_parse_template(config: RunningConfig): Promise<string> {
7882
const template_content = await this.plugin.app.vault.read(
7983
config.template_file as TFile
@@ -164,6 +168,8 @@ export class Templater {
164168
return;
165169
}
166170

171+
const backup_config = this.get_current_running_config();
172+
167173
const { path } = created_note;
168174
this.start_templater_task(path);
169175
let running_config: RunningConfig;
@@ -223,6 +229,10 @@ export class Templater {
223229
});
224230
}
225231

232+
await this.functions_generator.generate_object(
233+
backup_config,
234+
FunctionsMode.USER_INTERNAL
235+
);
226236
await this.end_templater_task(path);
227237
return created_note;
228238
}

src/core/functions/FunctionsGenerator.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export class FunctionsGenerator implements IGenerateObject {
1919
this.user_functions = new UserFunctions(this.plugin);
2020
}
2121

22+
get_config(): RunningConfig {
23+
return this.internal_functions.get_config();
24+
}
25+
2226
async init(): Promise<void> {
2327
await this.internal_functions.init();
2428
}

src/core/functions/internal_functions/InternalFunctions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export class InternalFunctions implements IGenerateObject {
2323
this.modules_array.push(new InternalModuleConfig(this.plugin));
2424
}
2525

26+
get_config(): RunningConfig {
27+
return this.modules_array[0].get_config();
28+
}
29+
2630
async init(): Promise<void> {
2731
for (const mod of this.modules_array) {
2832
await mod.init();

src/core/functions/internal_functions/InternalModule.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export abstract class InternalModule implements IGenerateObject {
1616
return this.name;
1717
}
1818

19+
get_config(): RunningConfig {
20+
return this.config;
21+
}
22+
1923
abstract create_static_templates(): Promise<void>;
2024
abstract create_dynamic_templates(): Promise<void>;
2125
abstract teardown(): Promise<void>;

0 commit comments

Comments
 (0)