Adding a getManifest function to string templates.

This commit is contained in:
mike12345567 2021-01-29 14:35:37 +00:00
parent 9e3d2a3553
commit d5b8ffe086
3 changed files with 20 additions and 0 deletions

View File

@ -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

View File

@ -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
}

View File

@ -3,6 +3,7 @@ const {
processString,
isValid,
makePropSafe,
getManifest,
} = require("../src/index")
describe("Test that the string processing works correctly", () => {
@ -101,3 +102,11 @@ describe("check the utility functions", () => {
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`.")
})
})