Browse Source

Adding a getManifest function to string templates.

master
mike12345567 6 years ago
parent
commit
d5b8ffe086
  1. 1
      packages/string-templates/README.md
  2. 10
      packages/string-templates/src/index.js
  3. 9
      packages/string-templates/test/basic.spec.js

1
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

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

9
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`.")
})
})
Loading…
Cancel
Save