Merge branch 'feature/handlebars-helpers-update' of github.com:Budibase/budibase into bug/integration-fixes
This commit is contained in:
commit
32c2a78148
|
@ -2,26 +2,30 @@
|
||||||
This package provides a common system for string templating across the Budibase Builder, client and server.
|
This package provides a common system for string templating across the Budibase Builder, client and server.
|
||||||
The templating is provided through the use of [Handlebars](https://handlebarsjs.com/) an extension of Mustache
|
The templating is provided through the use of [Handlebars](https://handlebarsjs.com/) an extension of Mustache
|
||||||
which is capable of carrying out logic. We have also extended the base Handlebars functionality through the use
|
which is capable of carrying out logic. We have also extended the base Handlebars functionality through the use
|
||||||
of a set of helpers provided through the [handlebars-helpers](https://github.com/helpers/handlebars-helpers) package.
|
of a set of helpers provided through the [handlebars-helpers](https://github.com/budibase/handlebars-helpers) package.
|
||||||
|
|
||||||
We have not implemented all the helpers provided by the helpers package as some of them provide functionality
|
We have not implemented all the helpers provided by the helpers package as some of them provide functionality
|
||||||
we felt would not be beneficial. The following collections of helpers have been implemented:
|
we felt would not be beneficial. The following collections of helpers have been implemented:
|
||||||
1. [Math](https://github.com/helpers/handlebars-helpers/tree/master#math) - a set of useful helpers for
|
1. [Math](https://github.com/budibase/handlebars-helpers/tree/master#math) - a set of useful helpers for
|
||||||
carrying out logic pertaining to numbers e.g. `avg`, `add`, `abs` and so on.
|
carrying out logic pertaining to numbers e.g. `avg`, `add`, `abs` and so on.
|
||||||
2. [Array](https://github.com/helpers/handlebars-helpers/tree/master#array) - some very specific helpers
|
2. [Array](https://github.com/budibase/handlebars-helpers/tree/master#array) - some very specific helpers
|
||||||
for use with arrays, useful for example in automations. Helpers like `first`, `last`, `after` and `join`
|
for use with arrays, useful for example in automations. Helpers like `first`, `last`, `after` and `join`
|
||||||
can be useful for getting particular portions of arrays or turning them into strings.
|
can be useful for getting particular portions of arrays or turning them into strings.
|
||||||
3. [Number](https://github.com/helpers/handlebars-helpers/tree/master#number) - unlike the math helpers these
|
3. [Number](https://github.com/budibase/handlebars-helpers/tree/master#number) - unlike the math helpers these
|
||||||
are useful for converting numbers into useful formats for display, e.g. `bytes`, `addCommas` and `toPrecision`.
|
are useful for converting numbers into useful formats for display, e.g. `bytes`, `addCommas` and `toPrecision`.
|
||||||
4. [URL](https://github.com/helpers/handlebars-helpers/tree/master#url) - very specific helpers for dealing with URLs,
|
4. [URL](https://github.com/budibase/handlebars-helpers/tree/master#url) - very specific helpers for dealing with URLs,
|
||||||
such as `encodeURI`, `escape`, `stripQueryString` and `stripProtocol`. These are primarily useful
|
such as `encodeURI`, `escape`, `stripQueryString` and `stripProtocol`. These are primarily useful
|
||||||
for building up particular URLs to hit as say part of an automation.
|
for building up particular URLs to hit as say part of an automation.
|
||||||
5. [String](https://github.com/helpers/handlebars-helpers/tree/master#string) - these helpers are useful for building
|
5. [String](https://github.com/budibase/handlebars-helpers/tree/master#string) - these helpers are useful for building
|
||||||
strings and preparing them for display, e.g. `append`, `camelcase`, `capitalize` and `ellipsis`.
|
strings and preparing them for display, e.g. `append`, `camelcase`, `capitalize` and `ellipsis`.
|
||||||
6. [Comparison](https://github.com/helpers/handlebars-helpers/tree/master#comparison) - these helpers are mainly for
|
6. [Comparison](https://github.com/budibase/handlebars-helpers/tree/master#comparison) - these helpers are mainly for
|
||||||
building strings when particular conditions are met, for example `and`, `or`, `gt`, `lt`, `not` and so on. This is a very
|
building strings when particular conditions are met, for example `and`, `or`, `gt`, `lt`, `not` and so on. This is a very
|
||||||
extensive set of helpers but is mostly as would be expected from a set of logical operators.
|
extensive set of helpers but is mostly as would be expected from a set of logical operators.
|
||||||
7. [Date](https://github.com/helpers/helper-date) - last but certainly not least is a moment based date helper, which can
|
7. [Object](https://github.com/budibase/handlebars-helpers/tree/master#object) - useful operator for parsing objects, as well
|
||||||
|
as converting them to JSON strings.
|
||||||
|
8. [Regex](https://github.com/budibase/handlebars-helpers/tree/master#regex) - allows performing regex tests on strings that
|
||||||
|
can be used in conditional statements.
|
||||||
|
9. [Date](https://github.com/helpers/helper-date) - last but certainly not least is a moment based date helper, which can
|
||||||
format ISO/timestamp based dates into something human-readable. An example of this would be `{{date dateProperty "DD-MM-YYYY"}}`.
|
format ISO/timestamp based dates into something human-readable. An example of this would be `{{date dateProperty "DD-MM-YYYY"}}`.
|
||||||
|
|
||||||
## Date formatting
|
## Date formatting
|
||||||
|
|
|
@ -983,4 +983,4 @@
|
||||||
"description": "<p>Format a date using moment.js data formatting.</p>\n"
|
"description": "<p>Format a date using moment.js data formatting.</p>\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
"manifest": "node ./scripts/gen-collection-info.js"
|
"manifest": "node ./scripts/gen-collection-info.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@budibase/handlebars-helpers": "^0.11.1",
|
"@budibase/handlebars-helpers": "^0.11.3",
|
||||||
"handlebars": "^4.7.6",
|
"handlebars": "^4.7.6",
|
||||||
"handlebars-utils": "^1.0.6",
|
"handlebars-utils": "^1.0.6",
|
||||||
"helper-date": "^1.0.1",
|
"helper-date": "^1.0.1",
|
||||||
|
|
|
@ -14,6 +14,8 @@ const EXTERNAL_FUNCTION_COLLECTIONS = [
|
||||||
"url",
|
"url",
|
||||||
"string",
|
"string",
|
||||||
"comparison",
|
"comparison",
|
||||||
|
"object",
|
||||||
|
"regex",
|
||||||
]
|
]
|
||||||
|
|
||||||
const DATE_NAME = "date"
|
const DATE_NAME = "date"
|
||||||
|
|
|
@ -291,6 +291,12 @@ describe("Cover a few complex use cases", () => {
|
||||||
expect(output).toBe("e")
|
expect(output).toBe("e")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should allow a complex forIn case", async () => {
|
||||||
|
const input = `{{#forIn (JSONparse '{"a":1, "b":2, "c":3}' )}}number: {{.}}\n{{/forIn}}`
|
||||||
|
const output = await processString(input, {})
|
||||||
|
expect(output).toBe("number: 1\nnumber: 2\nnumber: 3\n")
|
||||||
|
})
|
||||||
|
|
||||||
it("should make sure case is valid", () => {
|
it("should make sure case is valid", () => {
|
||||||
const validity = isValid("{{ avg [c355ec2b422e54f988ae553c8acd811ea].[a] [c355ec2b422e54f988ae553c8acd811ea].[b] }}")
|
const validity = isValid("{{ avg [c355ec2b422e54f988ae553c8acd811ea].[a] [c355ec2b422e54f988ae553c8acd811ea].[b] }}")
|
||||||
expect(validity).toBe(true)
|
expect(validity).toBe(true)
|
||||||
|
@ -299,6 +305,5 @@ describe("Cover a few complex use cases", () => {
|
||||||
it("should be able to solve an example from docs", async () => {
|
it("should be able to solve an example from docs", async () => {
|
||||||
const output = await processString(`{{first ( split "a-b-c" "-") 2}}`, {})
|
const output = await processString(`{{first ( split "a-b-c" "-") 2}}`, {})
|
||||||
expect(output).toBe(`a,b`)
|
expect(output).toBe(`a,b`)
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
|
@ -270,10 +270,10 @@
|
||||||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
||||||
|
|
||||||
"@budibase/handlebars-helpers@^0.11.1":
|
"@budibase/handlebars-helpers@^0.11.3":
|
||||||
version "0.11.1"
|
version "0.11.3"
|
||||||
resolved "https://registry.yarnpkg.com/@budibase/handlebars-helpers/-/handlebars-helpers-0.11.1.tgz#fe8672612fb4ad8fd3bad338ee15759f45e421eb"
|
resolved "https://registry.yarnpkg.com/@budibase/handlebars-helpers/-/handlebars-helpers-0.11.3.tgz#b6e5c91b83e8906e7d7ff10ddde277a3d561016e"
|
||||||
integrity sha512-s72LhOhlHk43QYGVcqjogaGa4h4e6y6X1AfshqWBWceTRYBs/9tUnoYDUiRJ/Mt3WoTmx8Hj5GOZekSqrUsOFQ==
|
integrity sha512-MS1ptZEYq8o9J3tNLM7cZ2RGSSJIer4GiMIUHtbBI3sC9UKqZebao1JYNfmZKpNjntuqhZKgjqc5GfnVIEjsYQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
arr-flatten "^1.1.0"
|
arr-flatten "^1.1.0"
|
||||||
array-sort "^0.1.4"
|
array-sort "^0.1.4"
|
||||||
|
|
Loading…
Reference in New Issue