mirror of
https://github.com/meld-cp/obsidian-build.git
synced 2026-07-22 07:30:25 +00:00
Compare commits
6 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60b609a904 | ||
|
|
26e6163047 | ||
|
|
e75c9c7454 | ||
|
|
f161094121 | ||
|
|
f40da8d781 | ||
|
|
0bbb5f0d44 |
7 changed files with 24 additions and 15 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -22,4 +22,7 @@ data.json
|
|||
.DS_Store
|
||||
|
||||
# Test vault
|
||||
test-vault
|
||||
test-vault
|
||||
|
||||
# Other
|
||||
desktop.ini
|
||||
|
|
|
|||
2
LICENSE
2
LICENSE
|
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2021 Michael Brenan
|
||||
Copyright (c) 2023 Cleon Pinto
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
|||
|
|
@ -75,8 +75,8 @@ const ans4 = await $.ui.ask( 'Title', 'question 4', ['1', '2', '3'] );
|
|||
// show a message
|
||||
await $.ui.message( `Your answers were:\n\n${ans1}, ${ans2}, ${ans3}, ${ans4}` );
|
||||
|
||||
// show a message with title
|
||||
await $.ui.message( 'A Title', 'A titled <b>message</b>' );
|
||||
// show a 2 line message with title
|
||||
await $.ui.message( 'A Title', 'A titled message\nLine 2' );
|
||||
await $.ui.message( 'Math', 13 * 67 );
|
||||
|
||||
// rebuild the current view, may be needed if you have an embedded note which was modified
|
||||
|
|
|
|||
|
|
@ -100,8 +100,8 @@ Say your note looks like this:
|
|||
# My Runnable Note
|
||||
|
||||
The template codeblock:
|
||||
```html
|
||||
<p>Greetings <strong>{{name}}</strong>, {{message}}</p>
|
||||
```
|
||||
Greetings {{name}}, {{message}}
|
||||
```
|
||||
|
||||
The meld-build block to run:
|
||||
|
|
@ -116,7 +116,7 @@ await $.ui.message( result );
|
|||
|
||||
````
|
||||
|
||||
Running this note will show a message with the following text: 'Greetings **John**, How are you?'
|
||||
Running this note will show a message with the following text: 'Greetings John, How are you?'
|
||||
|
||||
See the `$.io.import` and `$.io.load` [API](api.md) functions for other ways to load templates.
|
||||
|
||||
|
|
|
|||
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "meld-build-obsidian-plugin",
|
||||
"version": "0.1.6",
|
||||
"version": "0.1.9",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "meld-build-obsidian-plugin",
|
||||
"version": "0.1.6",
|
||||
"version": "0.1.9",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/handlebars": "^4.1.0",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { DataSet } from "./data-set";
|
||||
import { TMarkdownHelperRunContext } from "./run-context";
|
||||
import { TMarkdownHelperRunContext, TMarkdownHelperTableCellFormatter } from "./run-context";
|
||||
import { RunLogger } from "./run-logger";
|
||||
|
||||
export class MarkdownHelperRunContextImplementation implements TMarkdownHelperRunContext{
|
||||
|
|
@ -14,7 +14,7 @@ export class MarkdownHelperRunContextImplementation implements TMarkdownHelperRu
|
|||
return MarkdownTableHelper.buildTable( headings, rows );
|
||||
}
|
||||
|
||||
buildTableFromDataSet(data: DataSet): string {
|
||||
buildTableFromDataSet(data: DataSet, cellFormatter?:TMarkdownHelperTableCellFormatter): string {
|
||||
const headings = data.columns;
|
||||
const rowValues : any[][] = [];
|
||||
|
||||
|
|
@ -23,7 +23,13 @@ export class MarkdownHelperRunContextImplementation implements TMarkdownHelperRu
|
|||
|
||||
for (const heading of headings) {
|
||||
const prop = data.getPropertyName(heading);
|
||||
const value = prop == undefined ? undefined : row[prop];
|
||||
let value = prop == undefined ? undefined : row[prop];
|
||||
if (prop != undefined && cellFormatter != null){
|
||||
const formattedValue = cellFormatter(prop, value);
|
||||
if (formattedValue != undefined){
|
||||
value = formattedValue;
|
||||
}
|
||||
}
|
||||
values.push(value);
|
||||
}
|
||||
|
||||
|
|
@ -35,7 +41,7 @@ export class MarkdownHelperRunContextImplementation implements TMarkdownHelperRu
|
|||
|
||||
public table(arg1: unknown, arg2?: unknown): string {
|
||||
if (arg1 instanceof DataSet){
|
||||
return this.buildTableFromDataSet(arg1);
|
||||
return this.buildTableFromDataSet(arg1, arg2 as TMarkdownHelperTableCellFormatter);
|
||||
}
|
||||
if ( Array.isArray(arg1) && Array.isArray(arg2) ){
|
||||
return this.buildTable(arg1, arg2);
|
||||
|
|
|
|||
|
|
@ -118,9 +118,9 @@ export class MarkerChange{
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
export type TMarkdownHelperTableCellFormatter = (propName:string, value:any) => string|undefined;
|
||||
|
||||
export type TMarkdownHelperRunContext = {
|
||||
table( headings:Array<string>, rows:Array<Array<any>> ) : string;
|
||||
table( data:DataSet ) : string;
|
||||
table( data:DataSet, cellFormatter?:TMarkdownHelperTableCellFormatter ) : string;
|
||||
}
|
||||
Loading…
Reference in a new issue