From 79bc5215e87a00718f6e1d30736d62035c8a2680 Mon Sep 17 00:00:00 2001 From: Cleon <18450687+meld-cp@users.noreply.github.com> Date: Sat, 4 Feb 2023 18:11:02 +1300 Subject: [PATCH] add load and get to markers --- docs/api.md | 4 ++++ manifest.json | 2 +- package.json | 2 +- src/rci-markers.ts | 11 +++++++++++ src/run-context.ts | 4 +++- versions.json | 3 ++- 6 files changed, 22 insertions(+), 4 deletions(-) diff --git a/docs/api.md b/docs/api.md index 947c7f0..da30d34 100644 --- a/docs/api.md +++ b/docs/api.md @@ -146,6 +146,10 @@ Markers can be used to replace sections of a note with dynamic values. Sections - `$.markers.target_file( file? )` - Sets the target file to `file` - `file` is optional and defaults to the current note +- `await $.markers.load()` + - Loads target file markers into memory +- `$.markers.get( name )` + - Gets the marker value named `name` from memory - `$.markers.set( name, value )` - Sets the marker value named `name` in memory - `$.markers.clear()` diff --git a/manifest.json b/manifest.json index 1494b48..2bdc4e2 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "meld-build", "name": "Meld Build", - "version": "0.1.5", + "version": "0.1.6", "minAppVersion": "1.0.1", "description": "Write and execute (sandboxed) JavaScript to render templates, query DataView and create dynamic notes.", "author": "meld-cp", diff --git a/package.json b/package.json index 4c198cf..d1cb8df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meld-build-obsidian-plugin", - "version": "0.1.5", + "version": "0.1.6", "description": "This is a sample plugin for Obsidian (https://obsidian.md)", "main": "main.js", "scripts": { diff --git a/src/rci-markers.ts b/src/rci-markers.ts index cfcd8ee..0fa33b4 100644 --- a/src/rci-markers.ts +++ b/src/rci-markers.ts @@ -43,6 +43,17 @@ export class MarkerRunContextImplemention implements TMarkerRunContext { this.newValues.clear(); } + async load() : Promise{ + const markers = await this.fetch(); + markers.forEach(mk => { + this.set(mk.name, mk.value); + }); + } + + get( name: string ) : string|null|undefined { + return this.newValues.get( name ); + } + set( name: string, value: string|null ): void { this.newValues.set( name, value ); } diff --git a/src/run-context.ts b/src/run-context.ts index 86555d7..2ab01fc 100644 --- a/src/run-context.ts +++ b/src/run-context.ts @@ -73,8 +73,10 @@ export type TMarkerRunContext = { clear() : void; + get( name:string ): string|null|undefined; set( name:string, value:string|null ): void; - + + load() : Promise; fetch() : Promise; apply( clearUnknownMarkerValues?:boolean ) : Promise; diff --git a/versions.json b/versions.json index 8ba2338..13ff464 100644 --- a/versions.json +++ b/versions.json @@ -3,5 +3,6 @@ "0.1.2": "1.0.1", "0.1.3": "1.0.1", "0.1.4": "1.0.1", - "0.1.5": "1.0.1" + "0.1.5": "1.0.1", + "0.1.6": "1.0.1" } \ No newline at end of file