Skip to content

Commit

Permalink
Prepare API improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
chhoumann committed Jun 24, 2021
1 parent 6079773 commit 682755a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "metaedit",
"name": "MetaEdit",
"version": "1.6.13",
"version": "1.6.14",
"minAppVersion": "0.12.0",
"description": "MetaEdit helps you manage your metadata.",
"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": "metaedit",
"version": "1.6.13",
"version": "1.6.14",
"description": "MetaEdit helps you manage your metadata.",
"main": "main.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions src/IMetaEditApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ export interface IMetaEditApi {
autoprop: (propertyName: string) => void;
update: (propertyName: string, propertyValue: string, file: TFile | string) => Promise<void>;
getPropertyValue: (propertyName: string, file: (TFile | string)) => Promise<any>;
getFilesWithProperty: (propertyName: string) => TFile[];
createYamlProperty: (propertyName: string, propertyValue: string, file: TFile | string) => Promise<void>;
}

20 changes: 19 additions & 1 deletion src/MetaEditApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export class MetaEditApi {
autoprop: this.getAutopropFunction(),
update: this.getUpdateFunction(),
getPropertyValue: this.getGetPropertyValueFunction(),
getFilesWithProperty: this.getGetFilesWithPropertyFunction(),
createYamlProperty: this.getCreateYamlPropertyFunction()
};
}

private getAutopropFunction() {
return (propertyName: string) => new MetaController(this.plugin.app, this.plugin).handleAutoProperties(propertyName);
}
}

private getUpdateFunction(): (propertyName: string, propertyValue: string, file: (TFile | string)) => Promise<undefined | void> {
return async (propertyName: string, propertyValue: string, file: TFile | string) => {
Expand Down Expand Up @@ -65,4 +67,20 @@ export class MetaEditApi {
return targetProperty.content;
}
}

private getGetFilesWithPropertyFunction() {
return (propertyName: string): TFile[] => {
return this.plugin.getFilesWithProperty(propertyName);
}
}

private getCreateYamlPropertyFunction() {
return async (propertyName: string, propertyValue: string, file: TFile | string) => {
const targetFile = this.getFileFromTFileOrPath(file);
if (!targetFile) return;

const controller: MetaController = new MetaController(this.plugin.app, this.plugin);
await controller.addYamlProp(propertyName, propertyValue, targetFile);
}
}
}
4 changes: 2 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {App, TFile} from "obsidian";
import {parseYaml} from "obsidian";
import {MetaType} from "./Types/metaType";

export type Property = {key: string, content: string, type: MetaType};
export type Property = {key: string, content: any, type: MetaType};

export default class MetaEditParser {
private app: App;
Expand Down Expand Up @@ -34,7 +34,7 @@ export default class MetaEditParser {
let metaYaml: Property[] = [];

for (const key in parsedYaml) {
metaYaml.push({key, content: parsedYaml[key]?.toString(), type: MetaType.YAML});
metaYaml.push({key, content: parsedYaml[key], type: MetaType.YAML});
}

return metaYaml;
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"1.6.13": "0.12.0"
"1.6.14": "0.12.0"
}

0 comments on commit 682755a

Please sign in to comment.