Skip to content

Commit

Permalink
fix: lint errors - add field to formatters & fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
chhoumann committed Mar 7, 2023
1 parent feb5120 commit 7121d3a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 21 deletions.
45 changes: 26 additions & 19 deletions src/formatters/completeFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { SingleMacroEngine } from "../engine/SingleMacroEngine";
import { SingleTemplateEngine } from "../engine/SingleTemplateEngine";
import { MarkdownView } from "obsidian";
import type { IChoiceExecutor } from "../IChoiceExecutor";
import { FIELD_VAR_REGEX, INLINE_JAVASCRIPT_REGEX } from "../constants";
import { INLINE_JAVASCRIPT_REGEX } from "../constants";
import { SingleInlineScriptEngine } from "../engine/SingleInlineScriptEngine";
import { MathModal } from "../gui/MathModal";
import InputPrompt from "../gui/InputPrompt";
import GenericInputPrompt from "src/gui/GenericInputPrompt/GenericInputPrompt";

export class CompleteFormatter extends Formatter {
private valueHeader: string;
Expand All @@ -36,7 +37,7 @@ export class CompleteFormatter extends Formatter {
output = await this.replaceValueInString(output);
output = await this.replaceDateVariableInString(output);
output = await this.replaceVariableInString(output);
output = await this.replaceFieldVarInString(output);
output = await this.replaceFieldVarInString(output);
output = await this.replaceMathValueInString(output);

return output;
Expand Down Expand Up @@ -89,7 +90,9 @@ export class CompleteFormatter extends Formatter {
}

protected async promptForVariable(header?: string): Promise<string> {
return await new InputPrompt().factory().Prompt(this.app, header as string);
return await new InputPrompt()
.factory()
.Prompt(this.app, header as string);
}

protected async promptForMathValue(): Promise<string> {
Expand All @@ -104,25 +107,29 @@ export class CompleteFormatter extends Formatter {
);
}

protected async suggestForField(variableName: string) {
const suggestedValues: string[] = [];
for (const file of this.app.vault.getMarkdownFiles()) {
const cache = this.app.metadataCache.getFileCache(file);
const value = cache?.frontmatter?.[variableName];
if(!value || typeof value == 'object') continue;
suggestedValues.push(value);
}
protected async suggestForField(variableName: string) {
const suggestedValues: string[] = [];
for (const file of this.app.vault.getMarkdownFiles()) {
const cache = this.app.metadataCache.getFileCache(file);
const value = cache?.frontmatter?.[variableName];
if (!value || typeof value == "object") continue;
suggestedValues.push(value);
}

if (suggestedValues.length === 0) {
return await GenericInputPrompt.Prompt(app, `Enter value for ${variableName}`, `No existing values were found in your vault.`);
return await GenericInputPrompt.Prompt(
app,
`Enter value for ${variableName}`,
`No existing values were found in your vault.`
);
}

return await GenericSuggester.Suggest(
this.app,
suggestedValues,
suggestedValues
)
}
return await GenericSuggester.Suggest(
this.app,
suggestedValues,
suggestedValues
);
}

protected async getMacroValue(macroName: string): Promise<string> {
const macroEngine: SingleMacroEngine = new SingleMacroEngine(
Expand Down
9 changes: 9 additions & 0 deletions src/formatters/fileNameDisplayFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class FileNameDisplayFormatter extends Formatter {
output = await this.replaceValueInString(output);
output = await this.replaceDateVariableInString(output);
output = await this.replaceVariableInString(output);
output = await this.replaceFieldVarInString(output);

return `File Name: ${output}`;
}
Expand Down Expand Up @@ -57,4 +58,12 @@ export class FileNameDisplayFormatter extends Formatter {
protected async getSelectedText(): Promise<string> {
return "_selected_";
}

protected async suggestForField(variableName: string) {
return Promise.resolve(``);
}

protected async replaceFieldVarInString(input: string): Promise<string> {
return Promise.resolve(`_field_`);
}
}
9 changes: 9 additions & 0 deletions src/formatters/formatDisplayFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class FormatDisplayFormatter extends Formatter {
output = await this.replaceLinkToCurrentFileInString(output);
output = await this.replaceMacrosInString(output);
output = await this.replaceTemplateInString(output);
output = await this.replaceFieldVarInString(output);
output = this.replaceLinebreakInString(output);

return output;
Expand Down Expand Up @@ -71,4 +72,12 @@ export class FormatDisplayFormatter extends Formatter {
protected async getSelectedText(): Promise<string> {
return "_selected_";
}

protected async suggestForField(variableName: string) {
return Promise.resolve(``);
}

protected async replaceFieldVarInString(input: string): Promise<string> {
return Promise.resolve(`_field_`);
}
}
11 changes: 9 additions & 2 deletions src/migrations/useQuickAddTemplateFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,29 @@ export default {

if (obsidianTemplatesPlugin) {
const obsidianTemplatesSettings =
//@ts-ignore
obsidianTemplatesPlugin.instance.options;
if (obsidianTemplatesSettings["folder"]) {
plugin.settings.templateFolderPath =
obsidianTemplatesSettings["folder"];

log.logMessage("Migrated template folder path to Obsidian Templates' setting.");
log.logMessage(
"Migrated template folder path to Obsidian Templates' setting."
);
}
}

if (templaterPlugin) {
const templaterSettings = templaterPlugin.settings;
//@ts-ignore
if (templaterSettings["template_folder"]) {
plugin.settings.templateFolderPath =
//@ts-ignore
templaterSettings["template_folder"];

log.logMessage("Migrated template folder path to Templaters setting.");
log.logMessage(
"Migrated template folder path to Templaters setting."
);
}
}
} catch (error) {
Expand Down

1 comment on commit 7121d3a

@vercel
Copy link

@vercel vercel bot commented on 7121d3a Mar 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

quickadd – ./

quickadd-chrisbbh.vercel.app
quickadd.obsidian.guide
quickadd-git-master-chrisbbh.vercel.app

Please sign in to comment.