Skip to content

Commit

Permalink
Fix VDATE parsing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chhoumann committed Jun 12, 2021
1 parent 213c165 commit bac898c
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
6 changes: 5 additions & 1 deletion src/formatters/completeFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ export class CompleteFormatter extends Formatter {
return this.value;
}

protected async promptForVariable(header?: string): Promise<string> {
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<string> {
const macroEngine: SingleMacroEngine = new SingleMacroEngine(this.app, this.plugin.settings.macros);
return await macroEngine.runAndGetOutput(macroName);
}
Expand Down
4 changes: 4 additions & 0 deletions src/formatters/fileNameDisplayFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ export class FileNameDisplayFormatter extends Formatter {
protected getMacroValue(macroName: string) {
return `_macro: ${macroName}`;
}

protected async promptForVariable(variableName: string): Promise<string> {
return `_${variableName}_`;
}
}
4 changes: 4 additions & 0 deletions src/formatters/formatDisplayFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ export class FormatDisplayFormatter extends Formatter {
protected getMacroValue(macroName: string) {
return `_macro: ${macroName}_`;
}

protected promptForVariable(variableName: string): Promise<string> {
return Promise.resolve(`${variableName}_`);
}
}
10 changes: 6 additions & 4 deletions src/formatters/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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]}`);
}
Expand All @@ -137,5 +137,7 @@ export abstract class Formatter {

protected abstract getNaturalLanguageDates();

protected abstract getMacroValue(macroName: string): string;
protected abstract getMacroValue(macroName: string): Promise<string> | string;

protected abstract promptForVariable(variableName: string): Promise<string>;
}
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"0.1.2": "0.12.4"
"0.1.3": "0.12.4"
}

0 comments on commit bac898c

Please sign in to comment.