From bac898c1fc819ef70de4cc3cf48e90c75ce484e8 Mon Sep 17 00:00:00 2001 From: Christian Bager Bach Houmann Date: Sat, 12 Jun 2021 14:21:09 +0200 Subject: [PATCH] Fix VDATE parsing bug --- manifest.json | 2 +- package.json | 2 +- src/formatters/completeFormatter.ts | 6 +++++- src/formatters/fileNameDisplayFormatter.ts | 4 ++++ src/formatters/formatDisplayFormatter.ts | 4 ++++ src/formatters/formatter.ts | 10 ++++++---- versions.json | 2 +- 7 files changed, 22 insertions(+), 8 deletions(-) diff --git a/manifest.json b/manifest.json index c3baa6e..4a5bdd2 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "quickadd", "name": "QuickAdd", - "version": "0.1.2", + "version": "0.1.3", "minAppVersion": "0.12.00", "description": "Quickly add new pages or content to your vault.", "author": "Christian B. B. Houmann", diff --git a/package.json b/package.json index a574b57..02f9cd6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "quickadd", - "version": "0.1.2", + "version": "0.1.3", "description": "Quickly add new pages or content to your vault.", "main": "main.js", "scripts": { diff --git a/src/formatters/completeFormatter.ts b/src/formatters/completeFormatter.ts index 6e86a21..48c5d5b 100644 --- a/src/formatters/completeFormatter.ts +++ b/src/formatters/completeFormatter.ts @@ -68,11 +68,15 @@ export class CompleteFormatter extends Formatter { return this.value; } + protected async promptForVariable(header?: string): Promise { + return await GenericInputPrompt.Prompt(this.app, header); + } + protected async suggestForValue(suggestedValues: string[]) { return await GenericSuggester.Suggest(this.app, suggestedValues, suggestedValues); } - protected async getMacroValue(macroName: string) { + protected async getMacroValue(macroName: string): Promise { const macroEngine: SingleMacroEngine = new SingleMacroEngine(this.app, this.plugin.settings.macros); return await macroEngine.runAndGetOutput(macroName); } diff --git a/src/formatters/fileNameDisplayFormatter.ts b/src/formatters/fileNameDisplayFormatter.ts index d8b35b1..83dc91d 100644 --- a/src/formatters/fileNameDisplayFormatter.ts +++ b/src/formatters/fileNameDisplayFormatter.ts @@ -40,4 +40,8 @@ export class FileNameDisplayFormatter extends Formatter { protected getMacroValue(macroName: string) { return `_macro: ${macroName}`; } + + protected async promptForVariable(variableName: string): Promise { + return `_${variableName}_`; + } } \ No newline at end of file diff --git a/src/formatters/formatDisplayFormatter.ts b/src/formatters/formatDisplayFormatter.ts index a8ce4ac..20f3121 100644 --- a/src/formatters/formatDisplayFormatter.ts +++ b/src/formatters/formatDisplayFormatter.ts @@ -42,4 +42,8 @@ export class FormatDisplayFormatter extends Formatter { protected getMacroValue(macroName: string) { return `_macro: ${macroName}_`; } + + protected promptForVariable(variableName: string): Promise { + return Promise.resolve(`${variableName}_`); + } } diff --git a/src/formatters/formatter.ts b/src/formatters/formatter.ts index 69a51b9..0a22a5e 100644 --- a/src/formatters/formatter.ts +++ b/src/formatters/formatter.ts @@ -76,7 +76,7 @@ export abstract class Formatter { const suggestedValues = variableName.split(","); if (suggestedValues.length === 1) - this.variables.set(variableName, await this.promptForValue(variableName)); + this.variables.set(variableName, await this.promptForVariable(variableName)); else this.variables.set(variableName, await this.suggestForValue(suggestedValues)); } @@ -116,12 +116,12 @@ export abstract class Formatter { if (variableName && dateFormat) { if (!this.variables[variableName]) { - this.variables[variableName] = await this.promptForValue(variableName); + this.variables[variableName] = await this.promptForVariable(variableName); const parseAttempt = this.getNaturalLanguageDates().parseDate(this.variables[variableName]); if (parseAttempt) - this.variables[variableName] = window.moment().format(dateFormat); + this.variables[variableName] = parseAttempt.moment.format(dateFormat); else throw new Error(`unable to parse date variable ${this.variables[variableName]}`); } @@ -137,5 +137,7 @@ export abstract class Formatter { protected abstract getNaturalLanguageDates(); - protected abstract getMacroValue(macroName: string): string; + protected abstract getMacroValue(macroName: string): Promise | string; + + protected abstract promptForVariable(variableName: string): Promise; } \ No newline at end of file diff --git a/versions.json b/versions.json index f779ccf..58d5f72 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "0.1.2": "0.12.4" + "0.1.3": "0.12.4" }