diff --git a/CHANGELOG.md b/CHANGELOG.md index b42d97b..5fc519e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All changes to this plugin are listed here. +## 0.5.0 (2024-08-31) + +### New + +- Reference output columns in template notes. + ## 0.4.2 (2024-08-01) ### Updated diff --git a/README.md b/README.md index e93af12..47612db 100644 --- a/README.md +++ b/README.md @@ -48,22 +48,22 @@ variables: You can customize the view with the following parameters: -| Parameter | Description | Values | -|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------| -| url | The url of the *.dmn file (required). | Relative/Absolute path, or `[[*.dmn]]` as markdown link. | -| decisionId | An ID (or Name) of a decision table to evaluate (required). | String value | -| title | An optional h1 rendered before the DMN output. | String value | -| title1 | An optional h1 rendered before the DMN output. | String value | -| title2 | An optional h2 rendered before the DMN output. | String value | -| title3 | An optional h3 rendered before the DMN output. | String value | -| title4 | An optional h4 rendered before the DMN output. | String value | -| title5 | An optional h5 rendered before the DMN output. | String value | -| title6 | An optional h6 rendered before the DMN output. | String value | -| text | An optional span text rendered before the DMN output. | String value | -| textafter | An optional span text rendered after the DMN output. | String value | -| noresultmessage | An optional message if the evaluation returns no result. | String value (Default: "No result") | -| variables | A map of variables used as input | YAML Object | - | -| template | Render the result in a template file. The template file is another Note and should contain `{{result}}` where the result of the DMN evaluation is parsed. Other variables or fontmatter data can be referred as well. Note that the `title*` and `text` are ignored. | Relative/Absolute path, or `[[...]]` as markdown link. | - | +| Parameter | Description | Values | +|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------| +| url | The url of the *.dmn file (required). | Relative/Absolute path, or `[[*.dmn]]` as markdown link. | +| decisionId | An ID (or Name) of a decision table to evaluate (required). | String value | +| title | An optional h1 rendered before the DMN output. | String value | +| title1 | An optional h1 rendered before the DMN output. | String value | +| title2 | An optional h2 rendered before the DMN output. | String value | +| title3 | An optional h3 rendered before the DMN output. | String value | +| title4 | An optional h4 rendered before the DMN output. | String value | +| title5 | An optional h5 rendered before the DMN output. | String value | +| title6 | An optional h6 rendered before the DMN output. | String value | +| text | An optional span text rendered before the DMN output. | String value | +| textafter | An optional span text rendered after the DMN output. | String value | +| noresultmessage | An optional message if the evaluation returns no result. | String value (Default: "No result") | +| variables | A map of variables used as input | YAML Object | - | +| template | Render the result in a template file. The template file is another markdown file and should contain `{{result}}` where the result of the DMN evaluation is parsed. Other variables and frontmatter variables can be referenced as well (e.g., `{{variableX}}`). Furthermore, the name of the result columns of the DMN can be used to print individual values (if the DMN returns more than one column). If the DMN returns multiple rows (Hit Policy collect), than the variables can be indexed, e.g., `{{val1}}`. | Relative/Absolute path, or `[[...]]` as markdown link. | - | ### Example diff --git a/main.ts b/main.ts index 0bf700c..2944f66 100644 --- a/main.ts +++ b/main.ts @@ -71,7 +71,7 @@ export default class ObsidianDmnEvalPlugin extends Plugin { } let jarPath = this.getJarPath(); const parameterCopy = parameters; - console.log(dmnParams); + // console.log(dmnParams); exec("java -jar " + jarPath + " " + dmnParams, async (error, stdout, stderr) => { if (error) { console.error(`DMN error: ${error.message}`); @@ -223,7 +223,7 @@ export default class ObsidianDmnEvalPlugin extends Plugin { } } - await MarkdownRenderer.renderMarkdown(mdContent, rootElement, mdFile.path, new Component()); + await MarkdownRenderer.render(this.app, mdContent, rootElement, mdFile.path, new Component()); return true; } return false; @@ -234,13 +234,16 @@ export default class ObsidianDmnEvalPlugin extends Plugin { } private renderSingleResultMd(line: string, mdContent: string): string { - return mdContent.replace("{{result}}", line.split("::")[1]); + const [key, value] = line.split("::"); + return mdContent.replace("{{result}}", value).replace("{{" + key + "}}", value); } private renderResultListMd(lines: string[], mdContent: string) { let newMdList = ''; - lines.forEach(value => { - newMdList += "- " + value.split("::")[1] + '\n'; + lines.forEach((line, index) => { + const [key, value] = line.split("::"); + newMdList += "- " + value + '\n'; + mdContent = mdContent.replace("{{" + key + (1 + index) + "}}", value); }); return mdContent.replace("{{result}}", newMdList); } @@ -253,6 +256,17 @@ export default class ObsidianDmnEvalPlugin extends Plugin { mdTable += '---|'; }); mdTable += '\n'; + console.log(lines); + lines.forEach((line, index) => { + const results = line.split("||"); + results.forEach(result => { + const [key, value] = result.split("::"); + mdContent = mdContent.replace("{{" + key + (1 + index) + "}}", value); + if (index == 0) { + mdContent = mdContent.replace("{{" + key + "}}", value); + } + }); + }); lines.forEach(line => { mdTable += '|'; diff --git a/manifest.json b/manifest.json index ebd6333..f558f59 100644 --- a/manifest.json +++ b/manifest.json @@ -1,9 +1,9 @@ { "id": "dmn-eval", "name": "DMN Eval", - "version": "0.4.2", + "version": "0.5.0", "minAppVersion": "0.15.0", - "description": "This plugin enables evaluating/executing DMN", + "description": "This plugin enables evaluating DMNs in an obsidian note.", "author": "JoLeaf", "authorUrl": "https://github.com/JoLeaf", "fundingUrl": "https://ko-fi.com/joleaf", diff --git a/package.json b/package.json index 7277510..a4269b4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "dmn-eval", - "version": "0.4.2", - "description": "This plugin enables evaluating/executing DMNs.", + "version": "0.5.0", + "description": "This plugin enables evaluating DMNs in an obsidian note.", "main": "main.js", "scripts": { "dev": "node esbuild.config.mjs", diff --git a/versions.json b/versions.json index df77b69..cda2b15 100644 --- a/versions.json +++ b/versions.json @@ -10,5 +10,6 @@ "0.3.0": "0.15.0", "0.4.0": "0.15.0", "0.4.1": "0.15.0", - "0.4.2": "0.15.0" + "0.4.2": "0.15.0", + "0.5.0": "0.15.0" }