diff --git a/packages/string-templates/README.md b/packages/string-templates/README.md index e2b060b989..d9433b387b 100644 --- a/packages/string-templates/README.md +++ b/packages/string-templates/README.md @@ -75,6 +75,7 @@ specifiers so that it is safe for use in Handlebars. Ideally this function shoul being accessed, for example `[Table 1].[property name]` is the syntax that is required for Handlebars. 6. `isValid` - `(string)` - checks the given string for any templates and provides a boolean stating whether it is a valid template. +7. `getManifest` - returns the manifest JSON which has been generated for the helpers, describing them and their params. ## Development This library is built with [Rollup](https://rollupjs.org/guide/en/) as many of the packages built by Budibase are. We have diff --git a/packages/string-templates/src/index.js b/packages/string-templates/src/index.js index 529bb35cfd..8318454b0b 100644 --- a/packages/string-templates/src/index.js +++ b/packages/string-templates/src/index.js @@ -3,6 +3,7 @@ const { registerAll } = require("./helpers/index") const processors = require("./processors") const { cloneDeep } = require("lodash/fp") const { removeNull, addConstants } = require("./utilities") +const manifest = require("../manifest.json") const hbsInstance = handlebars.create() registerAll(hbsInstance) @@ -118,3 +119,12 @@ module.exports.isValid = string => { return false } } + +/** + * We have generated a static manifest file from the helpers that this string templating package makes use of. + * This manifest provides information about each of the helpers and how it can be used. + * @returns The manifest JSON which has been generated from the helpers. + */ +module.exports.getManifest = () => { + return manifest +} diff --git a/packages/string-templates/test/basic.spec.js b/packages/string-templates/test/basic.spec.js index 6fe57d67b3..dc5e4bb9ac 100644 --- a/packages/string-templates/test/basic.spec.js +++ b/packages/string-templates/test/basic.spec.js @@ -3,6 +3,7 @@ const { processString, isValid, makePropSafe, + getManifest, } = require("../src/index") describe("Test that the string processing works correctly", () => { @@ -100,4 +101,12 @@ describe("check the utility functions", () => { const property = makePropSafe("thing") expect(property).toEqual("[thing]") }) +}) + +describe("check manifest", () => { + it("should be able to retrieve the manifest", () => { + const manifest = getManifest() + expect(manifest.math).not.toBeNull() + expect(manifest.math.abs.description).toBe("Return the magnitude of `a`.") + }) }) \ No newline at end of file