Merge branch 'master' of github.com:Budibase/budibase into form-builder
This commit is contained in:
commit
4d411857fd
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": "0.6.2",
|
||||
"version": "0.7.1",
|
||||
"npmClient": "yarn",
|
||||
"packages": [
|
||||
"packages/*"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/builder",
|
||||
"version": "0.6.2",
|
||||
"version": "0.7.1",
|
||||
"license": "AGPL-3.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
@ -64,9 +64,9 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@budibase/bbui": "^1.56.0",
|
||||
"@budibase/client": "^0.6.2",
|
||||
"@budibase/client": "^0.7.1",
|
||||
"@budibase/colorpicker": "^1.0.1",
|
||||
"@budibase/string-templates": "^0.6.2",
|
||||
"@budibase/string-templates": "^0.7.1",
|
||||
"@budibase/svelte-ag-grid": "^0.0.16",
|
||||
"@sentry/browser": "5.19.1",
|
||||
"@svelteschool/svelte-forms": "^0.7.0",
|
||||
|
|
|
@ -119,6 +119,18 @@ export const getBackendUiStore = () => {
|
|||
return json
|
||||
},
|
||||
save: async (datasourceId, query) => {
|
||||
const integrations = get(store).integrations
|
||||
const dataSource = get(store).datasources.filter(
|
||||
ds => ds._id === datasourceId
|
||||
)
|
||||
// check if readable attribute is found
|
||||
if (dataSource.length !== 0) {
|
||||
const integration = integrations[dataSource[0].source]
|
||||
const readable = integration.query[query.queryVerb].readable
|
||||
if (readable) {
|
||||
query.readable = readable
|
||||
}
|
||||
}
|
||||
query.datasourceId = datasourceId
|
||||
const response = await api.post(`/api/queries`, query)
|
||||
const json = await response.json()
|
||||
|
|
|
@ -83,6 +83,7 @@
|
|||
<div class="binding__description">
|
||||
{@html helper.description || ''}
|
||||
</div>
|
||||
<pre>{helper.example || ''}</pre>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
@ -166,7 +167,13 @@
|
|||
.binding__description {
|
||||
color: var(--grey-8);
|
||||
margin-top: 2px;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
pre {
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.binding__type {
|
||||
font-family: monospace;
|
||||
background-color: var(--grey-2);
|
||||
|
|
|
@ -103,6 +103,7 @@
|
|||
<div class="description">
|
||||
{@html helper.description}
|
||||
</div>
|
||||
<pre>{helper.example || ''}</pre>
|
||||
</div>
|
||||
</li>
|
||||
{/each}
|
||||
|
@ -169,6 +170,11 @@
|
|||
border-width: 1px 0 1px 0;
|
||||
}
|
||||
|
||||
pre,
|
||||
.description {
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
li:hover {
|
||||
color: var(--ink);
|
||||
font-weight: 500;
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
return [...acc, ...viewsArr]
|
||||
}, [])
|
||||
$: queries = $backendUiStore.queries
|
||||
.filter(query => query.queryVerb === "read")
|
||||
.filter(query => query.queryVerb === "read" || query.readable)
|
||||
.map(query => ({
|
||||
label: query.name,
|
||||
name: query.name,
|
||||
|
|
|
@ -7,6 +7,7 @@ export function handlebarsCompletions() {
|
|||
Object.entries(manifest[key]).map(([helperName, helperConfig]) => ({
|
||||
text: helperName,
|
||||
path: helperName,
|
||||
example: helperConfig.example,
|
||||
label: helperName,
|
||||
displayText: helperName,
|
||||
description: helperConfig.description,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/client",
|
||||
"version": "0.6.2",
|
||||
"version": "0.7.1",
|
||||
"license": "MPL-2.0",
|
||||
"main": "dist/budibase-client.js",
|
||||
"module": "dist/budibase-client.js",
|
||||
|
@ -9,14 +9,14 @@
|
|||
"dev:builder": "rollup -cw"
|
||||
},
|
||||
"dependencies": {
|
||||
"@budibase/string-templates": "^0.6.2",
|
||||
"@budibase/string-templates": "^0.7.1",
|
||||
"deep-equal": "^2.0.1",
|
||||
"regexparam": "^1.3.0",
|
||||
"shortid": "^2.2.15",
|
||||
"svelte-spa-router": "^3.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@budibase/standard-components": "^0.6.2",
|
||||
"@budibase/standard-components": "^0.7.1",
|
||||
"@rollup/plugin-commonjs": "^16.0.0",
|
||||
"@rollup/plugin-node-resolve": "^10.0.0",
|
||||
"fs-extra": "^8.1.0",
|
||||
|
|
|
@ -18,7 +18,7 @@ export const fetchViewData = async ({
|
|||
params.set("calculation", calculation)
|
||||
}
|
||||
if (groupBy) {
|
||||
params.set("group", groupBy)
|
||||
params.set("group", groupBy ? "true" : "false")
|
||||
}
|
||||
|
||||
const QUERY_VIEW_URL = field
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@budibase/server",
|
||||
"email": "hi@budibase.com",
|
||||
"version": "0.6.2",
|
||||
"version": "0.7.1",
|
||||
"description": "Budibase Web Server",
|
||||
"main": "src/electron.js",
|
||||
"repository": {
|
||||
|
@ -50,8 +50,8 @@
|
|||
"author": "Budibase",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"@budibase/client": "^0.6.2",
|
||||
"@budibase/string-templates": "^0.6.2",
|
||||
"@budibase/client": "^0.7.1",
|
||||
"@budibase/string-templates": "^0.7.1",
|
||||
"@elastic/elasticsearch": "^7.10.0",
|
||||
"@koa/router": "^8.0.0",
|
||||
"@sendgrid/mail": "^7.1.1",
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
const handlebars = require("handlebars")
|
||||
const { processString } = require("@budibase/string-templates")
|
||||
const CouchDB = require("../../db")
|
||||
const { generateQueryID, getQueryParams } = require("../../db/utils")
|
||||
const { integrations } = require("../../integrations")
|
||||
|
||||
function formatResponse(resp) {
|
||||
if (typeof resp === "string") {
|
||||
resp = JSON.parse(resp)
|
||||
}
|
||||
if (!Array.isArray(resp)) {
|
||||
resp = [resp]
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
exports.fetch = async function(ctx) {
|
||||
const db = new CouchDB(ctx.user.appId)
|
||||
|
||||
|
@ -29,19 +39,22 @@ exports.save = async function(ctx) {
|
|||
ctx.message = `Query ${query.name} saved successfully.`
|
||||
}
|
||||
|
||||
function enrichQueryFields(fields, parameters) {
|
||||
async function enrichQueryFields(fields, parameters) {
|
||||
const enrichedQuery = {}
|
||||
|
||||
// enrich the fields with dynamic parameters
|
||||
for (let key in fields) {
|
||||
const template = handlebars.compile(fields[key])
|
||||
enrichedQuery[key] = template(parameters)
|
||||
for (let key of Object.keys(fields)) {
|
||||
enrichedQuery[key] = await processString(fields[key], parameters)
|
||||
}
|
||||
|
||||
if (enrichedQuery.json || enrichedQuery.customData) {
|
||||
enrichedQuery.json = JSON.parse(
|
||||
enrichedQuery.json || enrichedQuery.customData
|
||||
)
|
||||
try {
|
||||
enrichedQuery.json = JSON.parse(
|
||||
enrichedQuery.json || enrichedQuery.customData
|
||||
)
|
||||
} catch (err) {
|
||||
throw { message: `JSON Invalid - error: ${err}` }
|
||||
}
|
||||
delete enrichedQuery.customData
|
||||
}
|
||||
|
||||
|
@ -62,9 +75,11 @@ exports.preview = async function(ctx) {
|
|||
|
||||
const { fields, parameters, queryVerb } = ctx.request.body
|
||||
|
||||
const enrichedQuery = enrichQueryFields(fields, parameters)
|
||||
const enrichedQuery = await enrichQueryFields(fields, parameters)
|
||||
|
||||
ctx.body = await new Integration(datasource.config)[queryVerb](enrichedQuery)
|
||||
ctx.body = formatResponse(
|
||||
await new Integration(datasource.config)[queryVerb](enrichedQuery)
|
||||
)
|
||||
}
|
||||
|
||||
exports.execute = async function(ctx) {
|
||||
|
@ -80,17 +95,15 @@ exports.execute = async function(ctx) {
|
|||
return
|
||||
}
|
||||
|
||||
const enrichedQuery = enrichQueryFields(
|
||||
const enrichedQuery = await enrichQueryFields(
|
||||
query.fields,
|
||||
ctx.request.body.parameters
|
||||
)
|
||||
|
||||
// call the relevant CRUD method on the integration class
|
||||
const response = await new Integration(datasource.config)[query.queryVerb](
|
||||
enrichedQuery
|
||||
ctx.body = formatResponse(
|
||||
await new Integration(datasource.config)[query.queryVerb](enrichedQuery)
|
||||
)
|
||||
|
||||
ctx.body = response
|
||||
}
|
||||
|
||||
exports.destroy = async function(ctx) {
|
||||
|
|
|
@ -26,6 +26,7 @@ function generateQueryValidation() {
|
|||
name: Joi.string().required(),
|
||||
fields: Joi.object().required(),
|
||||
datasourceId: Joi.string().required(),
|
||||
readable: Joi.boolean(),
|
||||
parameters: Joi.array().items(Joi.object({
|
||||
name: Joi.string(),
|
||||
default: Joi.string()
|
||||
|
|
|
@ -17,20 +17,27 @@ const SCHEMA = {
|
|||
type: FIELD_TYPES.PASSWORD,
|
||||
required: true,
|
||||
},
|
||||
endpoint: {
|
||||
type: FIELD_TYPES.STRING,
|
||||
required: false,
|
||||
default: "https://dynamodb.us-east-1.amazonaws.com",
|
||||
},
|
||||
},
|
||||
query: {
|
||||
create: {
|
||||
type: QUERY_TYPES.FIELDS,
|
||||
customisable: true,
|
||||
fields: {
|
||||
table: {
|
||||
type: FIELD_TYPES.STRING,
|
||||
required: true,
|
||||
},
|
||||
customisable: true,
|
||||
},
|
||||
},
|
||||
read: {
|
||||
type: QUERY_TYPES.FIELDS,
|
||||
customisable: true,
|
||||
readable: true,
|
||||
fields: {
|
||||
table: {
|
||||
type: FIELD_TYPES.STRING,
|
||||
|
@ -39,30 +46,51 @@ const SCHEMA = {
|
|||
index: {
|
||||
type: FIELD_TYPES.STRING,
|
||||
},
|
||||
customisable: true,
|
||||
},
|
||||
},
|
||||
scan: {
|
||||
type: QUERY_TYPES.FIELDS,
|
||||
customisable: true,
|
||||
readable: true,
|
||||
fields: {
|
||||
table: {
|
||||
type: FIELD_TYPES.STRING,
|
||||
required: true,
|
||||
},
|
||||
index: {
|
||||
type: FIELD_TYPES.STRING,
|
||||
},
|
||||
},
|
||||
},
|
||||
get: {
|
||||
type: QUERY_TYPES.FIELDS,
|
||||
customisable: true,
|
||||
readable: true,
|
||||
fields: {
|
||||
table: {
|
||||
type: FIELD_TYPES.STRING,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
update: {
|
||||
type: QUERY_TYPES.FIELDS,
|
||||
customisable: true,
|
||||
fields: {
|
||||
table: {
|
||||
type: FIELD_TYPES.STRING,
|
||||
required: true,
|
||||
},
|
||||
customisable: true,
|
||||
},
|
||||
},
|
||||
delete: {
|
||||
type: QUERY_TYPES.FIELDS,
|
||||
customisable: true,
|
||||
fields: {
|
||||
table: {
|
||||
type: FIELD_TYPES.STRING,
|
||||
required: true,
|
||||
},
|
||||
key: {
|
||||
type: FIELD_TYPES.STRING,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -72,7 +100,15 @@ class DynamoDBIntegration {
|
|||
constructor(config) {
|
||||
this.config = config
|
||||
this.connect()
|
||||
this.client = new AWS.DynamoDB.DocumentClient()
|
||||
let options = {
|
||||
correctClockSkew: true,
|
||||
}
|
||||
if (config.endpoint) {
|
||||
options.endpoint = config.endpoint
|
||||
}
|
||||
this.client = new AWS.DynamoDB.DocumentClient({
|
||||
correctClockSkew: true,
|
||||
})
|
||||
}
|
||||
|
||||
async connect() {
|
||||
|
@ -80,37 +116,65 @@ class DynamoDBIntegration {
|
|||
}
|
||||
|
||||
async create(query) {
|
||||
const response = await this.client.query({
|
||||
const params = {
|
||||
TableName: query.table,
|
||||
Item: query.json,
|
||||
})
|
||||
return response
|
||||
...query.json,
|
||||
}
|
||||
return this.client.put(params).promise()
|
||||
}
|
||||
|
||||
async read(query) {
|
||||
const response = await this.client.query({
|
||||
TableName: query.Table,
|
||||
const params = {
|
||||
TableName: query.table,
|
||||
...query.json,
|
||||
})
|
||||
}
|
||||
if (query.index) {
|
||||
params.IndexName = query.index
|
||||
}
|
||||
const response = await this.client.query(params).promise()
|
||||
if (response.Items) {
|
||||
return response.Items
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
async scan(query) {
|
||||
const params = {
|
||||
TableName: query.table,
|
||||
...query.json,
|
||||
}
|
||||
if (query.index) {
|
||||
params.IndexName = query.index
|
||||
}
|
||||
const response = await this.client.scan(params).promise()
|
||||
if (response.Items) {
|
||||
return response.Items
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
async get(query) {
|
||||
const params = {
|
||||
TableName: query.table,
|
||||
...query.json,
|
||||
}
|
||||
return this.client.get(params).promise()
|
||||
}
|
||||
|
||||
async update(query) {
|
||||
const response = await this.client.query({
|
||||
const params = {
|
||||
TableName: query.Table,
|
||||
...query.json,
|
||||
})
|
||||
return response
|
||||
}
|
||||
return this.client.update(params).promise()
|
||||
}
|
||||
|
||||
async delete(query) {
|
||||
const response = await this.client.query({
|
||||
TableName: query.Table,
|
||||
Key: {
|
||||
id: query.key,
|
||||
},
|
||||
})
|
||||
return response
|
||||
const params = {
|
||||
TableName: query.table,
|
||||
...query.json,
|
||||
}
|
||||
return this.client.delete(params).promise()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,11 @@ const SCHEMA = {
|
|||
type: FIELD_TYPES.STRING,
|
||||
default: "localhost",
|
||||
},
|
||||
port: {
|
||||
type: FIELD_TYPES.NUMBER,
|
||||
required: false,
|
||||
default: 1433,
|
||||
},
|
||||
database: {
|
||||
type: FIELD_TYPES.STRING,
|
||||
default: "root",
|
||||
|
|
|
@ -1,25 +1,31 @@
|
|||
const mysql = require("mysql")
|
||||
const { FIELD_TYPES } = require("./Integration")
|
||||
|
||||
const SCHEMA = {
|
||||
docs: "https://github.com/mysqljs/mysql",
|
||||
datasource: {
|
||||
host: {
|
||||
type: "string",
|
||||
type: FIELD_TYPES.STRING,
|
||||
default: "localhost",
|
||||
required: true,
|
||||
},
|
||||
port: {
|
||||
type: FIELD_TYPES.NUMBER,
|
||||
default: 1433,
|
||||
required: false,
|
||||
},
|
||||
user: {
|
||||
type: "string",
|
||||
type: FIELD_TYPES.STRING,
|
||||
default: "root",
|
||||
required: true,
|
||||
},
|
||||
password: {
|
||||
type: "password",
|
||||
type: FIELD_TYPES.PASSWORD,
|
||||
default: "root",
|
||||
required: true,
|
||||
},
|
||||
database: {
|
||||
type: "string",
|
||||
type: FIELD_TYPES.STRING,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -35,7 +35,7 @@
|
|||
"keywords": [
|
||||
"svelte"
|
||||
],
|
||||
"version": "0.6.2",
|
||||
"version": "0.7.1",
|
||||
"license": "MIT",
|
||||
"gitHead": "62ebf3cedcd7e9b2494b4f8cbcfb90927609b491",
|
||||
"dependencies": {
|
||||
|
|
|
@ -45,9 +45,9 @@
|
|||
to-fast-properties "^2.0.0"
|
||||
|
||||
"@budibase/bbui@^1.55.1":
|
||||
version "1.55.1"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-1.55.1.tgz#291fb6fa10479b49f078d3a911ad0ed42c2e6b12"
|
||||
integrity sha512-bxsHBwkOqCtuFz89e0hAXwvwycfS4xPPrEge5PxK1Lh3uqetO4bXoIxYaIDjfi2Ku7CYIzEmOwSloNaQWeTF4g==
|
||||
version "1.56.2"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-1.56.2.tgz#bb8f7d9b9b5ed06a22df877fbe028780d7602471"
|
||||
integrity sha512-cWYkT1FNwNGTjisxtC5/MlQ1zeu7MYbMJsD6UyCEW3Ku6JIQZ6jyOkV6HKrmNND8VzVfddEGpzR37q+NoDpDFQ==
|
||||
dependencies:
|
||||
markdown-it "^12.0.2"
|
||||
quill "^1.3.7"
|
||||
|
@ -1111,7 +1111,12 @@ fill-range@^7.0.1:
|
|||
dependencies:
|
||||
to-regex-range "^5.0.1"
|
||||
|
||||
flatpickr@^4.5.2, flatpickr@^4.6.6:
|
||||
flatpickr@^4.5.2:
|
||||
version "4.6.9"
|
||||
resolved "https://registry.yarnpkg.com/flatpickr/-/flatpickr-4.6.9.tgz#9a13383e8a6814bda5d232eae3fcdccb97dc1499"
|
||||
integrity sha512-F0azNNi8foVWKSF+8X+ZJzz8r9sE1G4hl06RyceIaLvyltKvDl6vqk9Lm/6AUUCi5HWaIjiUbk7UpeE/fOXOpw==
|
||||
|
||||
flatpickr@^4.6.6:
|
||||
version "4.6.6"
|
||||
resolved "https://registry.yarnpkg.com/flatpickr/-/flatpickr-4.6.6.tgz#34d2ad80adfa34254e62583a34264d472f1038d6"
|
||||
integrity sha512-EZ48CJMttMg3maMhJoX+GvTuuEhX/RbA1YeuI19attP3pwBdbYy6+yqAEVm0o0hSBFYBiLbVxscLW6gJXq6H3A==
|
||||
|
@ -1640,9 +1645,9 @@ loadicons@^1.0.0:
|
|||
integrity sha512-KSywiudfuOK5sTdhNMM8hwRpMxZ5TbQlU4ZijMxUFwRW7jpxUmb9YJoLIzDn7+xuxeLzCZWBmLJS2JDjDWCpsw==
|
||||
|
||||
local-access@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/local-access/-/local-access-1.0.1.tgz#5121258146d64e869046c642ea4f1dd39ff942bb"
|
||||
integrity sha512-ykt2pgN0aqIy6KQC1CqdWTWkmUwNgaOS6dcpHVjyBJONA+Xi7AtSB1vuxC/U/0tjIP3wcRudwQk1YYzUvzk2bA==
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/local-access/-/local-access-1.1.0.tgz#e007c76ba2ca83d5877ba1a125fc8dfe23ba4798"
|
||||
integrity sha512-XfegD5pyTAfb+GY6chk283Ox5z8WexG56OvM06RWLpAc/UHozO8X6xAxEkIitZOtsSMM1Yr3DkHgW5W+onLhCw==
|
||||
|
||||
lodash.camelcase@^4.3.0:
|
||||
version "4.3.0"
|
||||
|
@ -1730,9 +1735,9 @@ miller-rabin@^4.0.0:
|
|||
brorand "^1.0.1"
|
||||
|
||||
mime@^2.3.1:
|
||||
version "2.4.6"
|
||||
resolved "https://registry.yarnpkg.com/mime/-/mime-2.4.6.tgz#e5b407c90db442f2beb5b162373d07b69affa4d1"
|
||||
integrity sha512-RZKhC3EmpBchfTGBVb8fb+RL2cWyw/32lshnsETttkBAyAUXSGHxbEJWWRXc751DrIxG1q04b8QwMbAwkRPpUA==
|
||||
version "2.5.0"
|
||||
resolved "https://registry.yarnpkg.com/mime/-/mime-2.5.0.tgz#2b4af934401779806ee98026bb42e8c1ae1876b1"
|
||||
integrity sha512-ft3WayFSFUVBuJj7BMLKAQcSlItKtfjsKDDsii3rqFDAZ7t11zRe8ASw/GlmivGwVUYtwkQrxiGGpL6gFvB0ag==
|
||||
|
||||
minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1:
|
||||
version "1.0.1"
|
||||
|
@ -2583,9 +2588,9 @@ rollup@^2.11.2:
|
|||
fsevents "~2.1.2"
|
||||
|
||||
sade@^1.4.0:
|
||||
version "1.7.3"
|
||||
resolved "https://registry.yarnpkg.com/sade/-/sade-1.7.3.tgz#a217ccc4fb4abb2d271648bf48f6628b2636fa1b"
|
||||
integrity sha512-m4BctppMvJ60W1dXnHq7jMmFe3hPJZDAH85kQ3ACTo7XZNVUuTItCQ+2HfyaMeV5cKrbw7l4vD/6We3GBxvdJw==
|
||||
version "1.7.4"
|
||||
resolved "https://registry.yarnpkg.com/sade/-/sade-1.7.4.tgz#ea681e0c65d248d2095c90578c03ca0bb1b54691"
|
||||
integrity sha512-y5yauMD93rX840MwUJr7C1ysLFBgMspsdTo4UVrDg3fXDvtwOyIqykhVAAm6fk/3au77773itJStObgK+LKaiA==
|
||||
dependencies:
|
||||
mri "^1.1.0"
|
||||
|
||||
|
|
|
@ -2,26 +2,30 @@
|
|||
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
|
||||
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 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.
|
||||
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`
|
||||
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`.
|
||||
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
|
||||
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`.
|
||||
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
|
||||
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"}}`.
|
||||
|
||||
## Date formatting
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
"a"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ abs 12012.1000 }} -> 12012.1",
|
||||
"description": "<p>Return the magnitude of <code>a</code>.</p>\n"
|
||||
},
|
||||
"add": {
|
||||
|
@ -13,6 +14,7 @@
|
|||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ add 1 2 }} -> 3",
|
||||
"description": "<p>Return the sum of <code>a</code> plus <code>b</code>.</p>\n"
|
||||
},
|
||||
"avg": {
|
||||
|
@ -20,6 +22,7 @@
|
|||
"array"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ avg [1,2,3,4,5] }} -> 3",
|
||||
"description": "<p>Returns the average of all numbers in the given array.</p>\n"
|
||||
},
|
||||
"ceil": {
|
||||
|
@ -27,6 +30,7 @@
|
|||
"value"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ ceil 1.2 }} -> 2",
|
||||
"description": "<p>Get the <code>Math.ceil()</code> of the given value.</p>\n"
|
||||
},
|
||||
"divide": {
|
||||
|
@ -35,6 +39,7 @@
|
|||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ divide 10 5 }} -> 2",
|
||||
"description": "<p>Divide <code>a</code> by <code>b</code></p>\n"
|
||||
},
|
||||
"floor": {
|
||||
|
@ -42,6 +47,7 @@
|
|||
"value"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ floor 1.2 }} -> 1",
|
||||
"description": "<p>Get the <code>Math.floor()</code> of the given value.</p>\n"
|
||||
},
|
||||
"minus": {
|
||||
|
@ -50,6 +56,7 @@
|
|||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ subtract 10 5 }} -> 5",
|
||||
"description": "<p>Return the product of <code>a</code> minus <code>b</code>.</p>\n"
|
||||
},
|
||||
"modulo": {
|
||||
|
@ -58,6 +65,7 @@
|
|||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ modulo 10 5 }} -> 0",
|
||||
"description": "<p>Get the remainder of a division operation.</p>\n"
|
||||
},
|
||||
"multiply": {
|
||||
|
@ -66,6 +74,7 @@
|
|||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ product 10 5 }} -> 50",
|
||||
"description": "<p>Return the product of <code>a</code> times <code>b</code>.</p>\n"
|
||||
},
|
||||
"plus": {
|
||||
|
@ -74,6 +83,7 @@
|
|||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ plus 10 5 }} -> 15",
|
||||
"description": "<p>Add <code>a</code> by <code>b</code>.</p>\n"
|
||||
},
|
||||
"random": {
|
||||
|
@ -82,6 +92,7 @@
|
|||
"max"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ random 0 20 }} -> 10",
|
||||
"description": "<p>Generate a random number between two values</p>\n"
|
||||
},
|
||||
"remainder": {
|
||||
|
@ -90,6 +101,7 @@
|
|||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ remainder 10 6 }} -> 4",
|
||||
"description": "<p>Get the remainder when <code>a</code> is divided by <code>b</code>.</p>\n"
|
||||
},
|
||||
"round": {
|
||||
|
@ -97,6 +109,7 @@
|
|||
"number"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ round 10.3 }} -> 10",
|
||||
"description": "<p>Round the given number.</p>\n"
|
||||
},
|
||||
"subtract": {
|
||||
|
@ -105,6 +118,7 @@
|
|||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ subtract 10 5 }} -> 5",
|
||||
"description": "<p>Return the product of <code>a</code> minus <code>b</code>.</p>\n"
|
||||
},
|
||||
"sum": {
|
||||
|
@ -112,6 +126,7 @@
|
|||
"array"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ sum [1, 2, 3] }} -> 6",
|
||||
"description": "<p>Returns the sum of all numbers in the given array.</p>\n"
|
||||
},
|
||||
"times": {
|
||||
|
@ -120,6 +135,7 @@
|
|||
"b"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ times 10 5 }} -> 50",
|
||||
"description": "<p>Multiply number <code>a</code> by number <code>b</code>.</p>\n"
|
||||
}
|
||||
},
|
||||
|
@ -130,6 +146,7 @@
|
|||
"n"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ after [1, 2, 3] 1}} -> [3]",
|
||||
"description": "<p>Returns all of the items in an array after the specified index. Opposite of <a href=\"#before\">before</a>.</p>\n"
|
||||
},
|
||||
"arrayify": {
|
||||
|
@ -137,6 +154,7 @@
|
|||
"value"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ arrayify \"foo\" }} -> [\"foo\"]",
|
||||
"description": "<p>Cast the given <code>value</code> to an array.</p>\n"
|
||||
},
|
||||
"before": {
|
||||
|
@ -145,6 +163,7 @@
|
|||
"n"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ before [1, 2, 3] 2}} -> [1, 2]",
|
||||
"description": "<p>Return all of the items in the collection before the specified count. Opposite of <a href=\"#after\">after</a>.</p>\n"
|
||||
},
|
||||
"eachIndex": {
|
||||
|
@ -153,6 +172,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{#eachIndex [1, 2, 3]}} {{item}} is {{index}} {{/eachIndex}}",
|
||||
"description": "<p>Iterates the array, listing an item and the index of it.</p>\n"
|
||||
},
|
||||
"filter": {
|
||||
|
@ -162,6 +182,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#filter [1, 2, 3] 2}}2 Found{{else}}2 not found{{/filter}}",
|
||||
"description": "<p>Block helper that filters the given array and renders the block for values that evaluate to <code>true</code>, otherwise the inverse block is returned.</p>\n"
|
||||
},
|
||||
"first": {
|
||||
|
@ -170,6 +191,7 @@
|
|||
"n"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{first [1, 2, 3, 4] 2}} -> [1, 2]",
|
||||
"description": "<p>Returns the first item, or first <code>n</code> items of an array.</p>\n"
|
||||
},
|
||||
"forEach": {
|
||||
|
@ -177,6 +199,7 @@
|
|||
"array"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{#forEach [{ 'name': 'John' }] }} {{ name }} {{/forEach}}",
|
||||
"description": "<p>Iterates over each item in an array and exposes the current item in the array as context to the inner block. In addition to the current array item, the helper exposes the following variables to the inner block: - <code>index</code> - <code>total</code> - <code>isFirst</code> - <code>isLast</code> Also, <code>@index</code> is exposed as a private variable, and additional private variables may be defined as hash arguments.</p>\n"
|
||||
},
|
||||
"inArray": {
|
||||
|
@ -186,6 +209,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#inArray [1, 2, 3] 2}} 2 exists {{else}} 2 does not exist {{/inArray}} -> 2 exists",
|
||||
"description": "<p>Block helper that renders the block if an array has the given <code>value</code>. Optionally specify an inverse block to render when the array does not have the given value.</p>\n"
|
||||
},
|
||||
"isArray": {
|
||||
|
@ -193,6 +217,7 @@
|
|||
"value"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{isArray [1, 2]}} -> true",
|
||||
"description": "<p>Returns true if <code>value</code> is an es5 array.</p>\n"
|
||||
},
|
||||
"itemAt": {
|
||||
|
@ -201,6 +226,7 @@
|
|||
"idx"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{itemAt [1, 2, 3] 1}} -> 2",
|
||||
"description": "<p>Returns the item from <code>array</code> at index <code>idx</code>.</p>\n"
|
||||
},
|
||||
"join": {
|
||||
|
@ -209,6 +235,7 @@
|
|||
"separator"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{join [1, 2, 3]}} -> '1, 2, 3'",
|
||||
"description": "<p>Join all elements of array into a string, optionally using a given separator.</p>\n"
|
||||
},
|
||||
"equalsLength": {
|
||||
|
@ -218,6 +245,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{equalsLength [1, 2, 3] 3}} -> true",
|
||||
"description": "<p>Returns true if the the length of the given <code>value</code> is equal to the given <code>length</code>. Can be used as a block or inline helper.</p>\n"
|
||||
},
|
||||
"last": {
|
||||
|
@ -226,6 +254,7 @@
|
|||
"n"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{last [1, 2, 3]}} -> 3",
|
||||
"description": "<p>Returns the last item, or last <code>n</code> items of an array or string. Opposite of <a href=\"#first\">first</a>.</p>\n"
|
||||
},
|
||||
"length": {
|
||||
|
@ -233,6 +262,7 @@
|
|||
"value"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{length [1, 2, 3]}} -> 3",
|
||||
"description": "<p>Returns the length of the given string or array.</p>\n"
|
||||
},
|
||||
"lengthEqual": {
|
||||
|
@ -242,6 +272,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{equalsLength [1, 2, 3] 3}} -> true",
|
||||
"description": "<p>Returns true if the the length of the given <code>value</code> is equal to the given <code>length</code>. Can be used as a block or inline helper.</p>\n"
|
||||
},
|
||||
"map": {
|
||||
|
@ -250,6 +281,7 @@
|
|||
"fn"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{map [1, 2, 3] double}} -> [2, 4, 6]",
|
||||
"description": "<p>Returns a new array, created by calling <code>function</code> on each element of the given <code>array</code>. For example,</p>\n"
|
||||
},
|
||||
"pluck": {
|
||||
|
@ -258,6 +290,7 @@
|
|||
"prop"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{pluck [{ 'name': 'Bob' }] \"name\" }} -> ['Bob']",
|
||||
"description": "<p>Map over the given object or array or objects and create an array of values from the given <code>prop</code>. Dot-notation may be used (as a string) to get nested properties.</p>\n"
|
||||
},
|
||||
"reverse": {
|
||||
|
@ -265,6 +298,7 @@
|
|||
"value"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{reverse [1, 2, 3]}} -> [3, 2, 1]",
|
||||
"description": "<p>Reverse the elements in an array, or the characters in a string.</p>\n"
|
||||
},
|
||||
"some": {
|
||||
|
@ -274,6 +308,7 @@
|
|||
"provided"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#some [1, 'b', 3] isString}} string found {{else}} No string found {{/some}} -> string found",
|
||||
"description": "<p>Block helper that returns the block if the callback returns true for some value in the given array.</p>\n"
|
||||
},
|
||||
"sort": {
|
||||
|
@ -282,6 +317,7 @@
|
|||
"key"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ sort ['b', 'a', 'c'] }} -> ['a', 'b', 'c']",
|
||||
"description": "<p>Sort the given <code>array</code>. If an array of objects is passed, you may optionally pass a <code>key</code> to sort on as the second argument. You may alternatively pass a sorting function as the second argument.</p>\n"
|
||||
},
|
||||
"sortBy": {
|
||||
|
@ -290,6 +326,7 @@
|
|||
"props"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ sortBy [{a: 'zzz'}, {a: 'aaa'}] \"a\" }} -> [{\"a\":\"aaa\"}, {\"a\":\"zzz\"}]",
|
||||
"description": "<p>Sort an <code>array</code>. If an array of objects is passed, you may optionally pass a <code>key</code> to sort on as the second argument. You may alternatively pass a sorting function as the second argument.</p>\n"
|
||||
},
|
||||
"withAfter": {
|
||||
|
@ -299,6 +336,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{ withAfter [1, 2, 3] 1 }} {{this}} {{/withAfter}}",
|
||||
"description": "<p>Use the items in the array <em>after</em> the specified index as context inside a block. Opposite of <a href=\"#withBefore\">withBefore</a>.</p>\n"
|
||||
},
|
||||
"withBefore": {
|
||||
|
@ -308,6 +346,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{ withBefore [1, 2, 3] 2 }} {{this}} {{/withBefore}}",
|
||||
"description": "<p>Use the items in the array <em>before</em> the specified index as context inside a block. Opposite of <a href=\"#withAfter\">withAfter</a>.</p>\n"
|
||||
},
|
||||
"withFirst": {
|
||||
|
@ -317,6 +356,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{ withFirst [1, 2, 3] }} {{this}} {{/withFirst}}",
|
||||
"description": "<p>Use the first item in a collection inside a handlebars block expression. Opposite of <a href=\"#withLast\">withLast</a>.</p>\n"
|
||||
},
|
||||
"withGroup": {
|
||||
|
@ -326,6 +366,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#withGroup [1, 2, 3, 4] 2}} {{#each this}} {{.}} {{each}} <br> {{/withGroup}} -> 1,2<br> 3,4<br>",
|
||||
"description": "<p>Block helper that groups array elements by given group <code>size</code>.</p>\n"
|
||||
},
|
||||
"withLast": {
|
||||
|
@ -335,6 +376,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#withLast [1, 2, 3, 4]}} {{this}} {{/withLast}} -> 4",
|
||||
"description": "<p>Use the last item or <code>n</code> items in an array as context inside a block. Opposite of <a href=\"#withFirst\">withFirst</a>.</p>\n"
|
||||
},
|
||||
"withSort": {
|
||||
|
@ -344,6 +386,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#withSort ['b', 'a', 'c']}} {{this}} {{/withSort}} -> abc",
|
||||
"description": "<p>Block helper that sorts a collection and exposes the sorted collection as context inside the block.</p>\n"
|
||||
},
|
||||
"unique": {
|
||||
|
@ -352,6 +395,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{#each (unique ['a', 'a', 'c', 'b', 'e', 'e']) }} {{.}} {{/each}} -> acbe",
|
||||
"description": "<p>Block helper that return an array with all duplicate values removed. Best used along with a <a href=\"#each\">each</a> helper.</p>\n"
|
||||
}
|
||||
},
|
||||
|
@ -361,6 +405,7 @@
|
|||
"number"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ bytes 1386 }} -> 1.4Kb",
|
||||
"description": "<p>Format a number to it's equivalent in bytes. If a string is passed, it's length will be formatted and returned. <strong>Examples:</strong> - <code>'foo' => 3 B</code> - <code>13661855 => 13.66 MB</code> - <code>825399 => 825.39 kB</code> - <code>1396 => 1.4 kB</code></p>\n"
|
||||
},
|
||||
"addCommas": {
|
||||
|
@ -368,6 +413,7 @@
|
|||
"num"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ addCommas 1000000 }} -> 1,000,000",
|
||||
"description": "<p>Add commas to numbers</p>\n"
|
||||
},
|
||||
"phoneNumber": {
|
||||
|
@ -375,6 +421,7 @@
|
|||
"num"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ phoneNumber 8005551212 }} -> (800) 555-1212",
|
||||
"description": "<p>Convert a string or number to a formatted phone number.</p>\n"
|
||||
},
|
||||
"toAbbr": {
|
||||
|
@ -383,6 +430,7 @@
|
|||
"precision"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ toAbbr 10123 2 }} -> 10.12k",
|
||||
"description": "<p>Abbreviate numbers to the given number of <code>precision</code>. This for general numbers, not size in bytes.</p>\n"
|
||||
},
|
||||
"toExponential": {
|
||||
|
@ -391,6 +439,7 @@
|
|||
"fractionDigits"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ toExponential 10123 2 }} -> 101e+4",
|
||||
"description": "<p>Returns a string representing the given number in exponential notation.</p>\n"
|
||||
},
|
||||
"toFixed": {
|
||||
|
@ -399,6 +448,7 @@
|
|||
"digits"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ toFixed 1.1234 2 }} -> 1.12",
|
||||
"description": "<p>Formats the given number using fixed-point notation.</p>\n"
|
||||
},
|
||||
"toFloat": {
|
||||
|
@ -421,6 +471,7 @@
|
|||
"precision"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{toPrecision \"1.1234\" 2}}",
|
||||
"description": "<p>Returns a string representing the <code>Number</code> object to the specified precision.</p>\n"
|
||||
}
|
||||
},
|
||||
|
@ -430,6 +481,7 @@
|
|||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ encodeURI \"https://myurl?Hello There\" }} -> https://myurl?Hello%20There",
|
||||
"description": "<p>Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character.</p>\n"
|
||||
},
|
||||
"escape": {
|
||||
|
@ -437,6 +489,7 @@
|
|||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ escape \"https://myurl?Hello+There\" }} -> https://myurl?Hello%20There",
|
||||
"description": "<p>Escape the given string by replacing characters with escape sequences. Useful for allowing the string to be used in a URL, etc.</p>\n"
|
||||
},
|
||||
"decodeURI": {
|
||||
|
@ -444,6 +497,7 @@
|
|||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ escape \"https://myurl?Hello%20There\" }} -> https://myurl?Hello+There",
|
||||
"description": "<p>Decode a Uniform Resource Identifier (URI) component.</p>\n"
|
||||
},
|
||||
"url_encode": {
|
||||
|
@ -462,6 +516,7 @@
|
|||
"href"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ urlResolve \"https://myurl\" \"/api/test\" }} -> https://myurl/api/test",
|
||||
"description": "<p>Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag.</p>\n"
|
||||
},
|
||||
"urlParse": {
|
||||
|
@ -469,6 +524,7 @@
|
|||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ urlParse \"https://myurl/api/test\" }}",
|
||||
"description": "<p>Parses a <code>url</code> string into an object.</p>\n"
|
||||
},
|
||||
"stripQuerystring": {
|
||||
|
@ -476,6 +532,7 @@
|
|||
"url"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ stripQueryString \"https://myurl/api/test?foo=bar\" }} -> \"https://myurl/api/test\"",
|
||||
"description": "<p>Strip the query string from the given <code>url</code>.</p>\n"
|
||||
},
|
||||
"stripProtocol": {
|
||||
|
@ -483,6 +540,7 @@
|
|||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ stripProtocol \"https://myurl/api/test\" }} -> \"myurl/api/test\"",
|
||||
"description": "<p>Strip protocol from a <code>url</code>. Useful for displaying media that may have an 'http' protocol on secure connections.</p>\n"
|
||||
}
|
||||
},
|
||||
|
@ -493,6 +551,7 @@
|
|||
"suffix"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{append \"index\" \".html\"}} -> index.html",
|
||||
"description": "<p>Append the specified <code>suffix</code> to the given string.</p>\n"
|
||||
},
|
||||
"camelcase": {
|
||||
|
@ -500,6 +559,7 @@
|
|||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{camelcase \"foo bar baz\"}} -> fooBarBaz",
|
||||
"description": "<p>camelCase the characters in the given <code>string</code>.</p>\n"
|
||||
},
|
||||
"capitalize": {
|
||||
|
@ -507,6 +567,7 @@
|
|||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{capitalize \"foo bar baz\"}} -> Foo bar baz",
|
||||
"description": "<p>Capitalize the first word in a sentence.</p>\n"
|
||||
},
|
||||
"capitalizeAll": {
|
||||
|
@ -514,6 +575,7 @@
|
|||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ capitalizeAll \"foo bar baz\"}} -> Foo Bar Baz",
|
||||
"description": "<p>Capitalize all words in a string.</p>\n"
|
||||
},
|
||||
"center": {
|
||||
|
@ -522,6 +584,7 @@
|
|||
"spaces"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ center \"test\" 1}} -> \" test \"",
|
||||
"description": "<p>Center a string using non-breaking spaces</p>\n"
|
||||
},
|
||||
"chop": {
|
||||
|
@ -529,6 +592,7 @@
|
|||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{ chop \" ABC \"}} -> \"ABC\"",
|
||||
"description": "<p>Like trim, but removes both extraneous whitespace <strong>and non-word characters</strong> from the beginning and end of a string.</p>\n"
|
||||
},
|
||||
"dashcase": {
|
||||
|
@ -536,6 +600,7 @@
|
|||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{dashcase \"a-b-c d_e\"}} -> a-b-c-d-e",
|
||||
"description": "<p>dash-case the characters in <code>string</code>. Replaces non-word characters and periods with hyphens.</p>\n"
|
||||
},
|
||||
"dotcase": {
|
||||
|
@ -543,6 +608,7 @@
|
|||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{dotcase \"a-b-c d_e\"}} -> a.b.c.d.e",
|
||||
"description": "<p>dot.case the characters in <code>string</code>.</p>\n"
|
||||
},
|
||||
"downcase": {
|
||||
|
@ -550,6 +616,7 @@
|
|||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{downcase \"aBcDeF\"}} -> abcdef",
|
||||
"description": "<p>Lowercase all of the characters in the given string. Alias for <a href=\"#lowercase\">lowercase</a>.</p>\n"
|
||||
},
|
||||
"ellipsis": {
|
||||
|
@ -558,6 +625,7 @@
|
|||
"length"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{ellipsis \"foo bar baz\", 7}} -> foo bar…",
|
||||
"description": "<p>Truncates a string to the specified <code>length</code>, and appends it with an elipsis, <code>…</code>.</p>\n"
|
||||
},
|
||||
"hyphenate": {
|
||||
|
@ -565,6 +633,7 @@
|
|||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{hyphenate \"foo bar baz qux\"}} -> foo-bar-baz-qux",
|
||||
"description": "<p>Replace spaces in a string with hyphens.</p>\n"
|
||||
},
|
||||
"isString": {
|
||||
|
@ -572,6 +641,7 @@
|
|||
"value"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{isString \"foo\"}} -> true",
|
||||
"description": "<p>Return true if <code>value</code> is a string.</p>\n"
|
||||
},
|
||||
"lowercase": {
|
||||
|
@ -579,6 +649,7 @@
|
|||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{lowercase \"Foo BAR baZ\"}} -> foo bar baz",
|
||||
"description": "<p>Lowercase all characters in the given string.</p>\n"
|
||||
},
|
||||
"occurrences": {
|
||||
|
@ -587,6 +658,7 @@
|
|||
"substring"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{occurrences \"foo bar foo bar baz\" \"foo\"}} -> 2",
|
||||
"description": "<p>Return the number of occurrences of <code>substring</code> within the given <code>string</code>.</p>\n"
|
||||
},
|
||||
"pascalcase": {
|
||||
|
@ -594,6 +666,7 @@
|
|||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{pascalcase \"foo bar baz\"}} -> FooBarBaz",
|
||||
"description": "<p>PascalCase the characters in <code>string</code>.</p>\n"
|
||||
},
|
||||
"pathcase": {
|
||||
|
@ -601,6 +674,7 @@
|
|||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{pathcase \"a-b-c d_e\"}} -> a/b/c/d/e",
|
||||
"description": "<p>path/case the characters in <code>string</code>.</p>\n"
|
||||
},
|
||||
"plusify": {
|
||||
|
@ -608,6 +682,7 @@
|
|||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{plusify \"foo bar baz\"}} -> foo+bar+baz",
|
||||
"description": "<p>Replace spaces in the given string with pluses.</p>\n"
|
||||
},
|
||||
"prepend": {
|
||||
|
@ -616,6 +691,7 @@
|
|||
"prefix"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{prepend \"bar\" \"foo-\"}} -> foo-bar",
|
||||
"description": "<p>Prepends the given <code>string</code> with the specified <code>prefix</code>.</p>\n"
|
||||
},
|
||||
"raw": {
|
||||
|
@ -623,6 +699,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{{{#raw}}}} {{foo}} {{{{/raw}}}} -> {{foo}}",
|
||||
"description": "<p>Render a block without processing mustache templates inside the block.</p>\n"
|
||||
},
|
||||
"remove": {
|
||||
|
@ -631,6 +708,7 @@
|
|||
"substring"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{remove \"a b a b a b\" \"a \"}} -> b b b",
|
||||
"description": "<p>Remove all occurrences of <code>substring</code> from the given <code>str</code>.</p>\n"
|
||||
},
|
||||
"removeFirst": {
|
||||
|
@ -639,6 +717,7 @@
|
|||
"substring"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{remove \"a b a b a b\" \"a\"}} -> b a b a b",
|
||||
"description": "<p>Remove the first occurrence of <code>substring</code> from the given <code>str</code>.</p>\n"
|
||||
},
|
||||
"replace": {
|
||||
|
@ -648,6 +727,7 @@
|
|||
"b"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{replace \"a b a b a b\" \"a\" \"z\"}} -> z b z b z b",
|
||||
"description": "<p>Replace all occurrences of substring <code>a</code> with substring <code>b</code>.</p>\n"
|
||||
},
|
||||
"replaceFirst": {
|
||||
|
@ -657,6 +737,7 @@
|
|||
"b"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{replace \"a b a b a b\" \"a\" \"z\"}} -> z b a b a b",
|
||||
"description": "<p>Replace the first occurrence of substring <code>a</code> with substring <code>b</code>.</p>\n"
|
||||
},
|
||||
"sentence": {
|
||||
|
@ -664,6 +745,7 @@
|
|||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{sentence \"hello world. goodbye world.\"}} -> Hello world. Goodbye world.",
|
||||
"description": "<p>Sentence case the given string</p>\n"
|
||||
},
|
||||
"snakecase": {
|
||||
|
@ -671,6 +753,7 @@
|
|||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{snakecase \"a-b-c d_e\"}} -> a_b_c_d_e",
|
||||
"description": "<p>snake_case the characters in the given <code>string</code>.</p>\n"
|
||||
},
|
||||
"split": {
|
||||
|
@ -678,6 +761,7 @@
|
|||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{split \"a,b,c\"}} -> ['a', 'b', 'c']",
|
||||
"description": "<p>Split <code>string</code> by the given <code>character</code>.</p>\n"
|
||||
},
|
||||
"startsWith": {
|
||||
|
@ -687,6 +771,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#startsWith \"Goodbye\" \"Hello, world!\"}} Yep {{else}} Nope {{/startsWith}} -> Nope",
|
||||
"description": "<p>Tests whether a string begins with the given prefix.</p>\n"
|
||||
},
|
||||
"titleize": {
|
||||
|
@ -694,6 +779,7 @@
|
|||
"str"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{#titleize \"this is title case\" }} -> This Is Title Case",
|
||||
"description": "<p>Title case the given string.</p>\n"
|
||||
},
|
||||
"trim": {
|
||||
|
@ -701,6 +787,7 @@
|
|||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{trim \" ABC \" }} -> ABC",
|
||||
"description": "<p>Removes extraneous whitespace from the beginning and end of a string.</p>\n"
|
||||
},
|
||||
"trimLeft": {
|
||||
|
@ -708,6 +795,7 @@
|
|||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{trimLeft \" ABC \" }} -> \"ABC \"",
|
||||
"description": "<p>Removes extraneous whitespace from the beginning of a string.</p>\n"
|
||||
},
|
||||
"trimRight": {
|
||||
|
@ -715,6 +803,7 @@
|
|||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{trimRight \" ABC \" }} -> \" ABC \"",
|
||||
"description": "<p>Removes extraneous whitespace from the end of a string.</p>\n"
|
||||
},
|
||||
"truncate": {
|
||||
|
@ -724,6 +813,7 @@
|
|||
"suffix"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{truncate \"foo bar baz\" 7 }} -> foo bar",
|
||||
"description": "<p>Truncate a string to the specified <code>length</code>. Also see <a href=\"#ellipsis\">ellipsis</a>.</p>\n"
|
||||
},
|
||||
"truncateWords": {
|
||||
|
@ -733,6 +823,7 @@
|
|||
"suffix"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{truncateWords \"foo bar baz\" 1 }} -> foo",
|
||||
"description": "<p>Truncate a string to have the specified number of words. Also see <a href=\"#truncate\">truncate</a>.</p>\n"
|
||||
},
|
||||
"upcase": {
|
||||
|
@ -740,6 +831,7 @@
|
|||
"string"
|
||||
],
|
||||
"numArgs": 1,
|
||||
"example": "{{upcase \"aBcDef\"}} -> ABCDEF",
|
||||
"description": "<p>Uppercase all of the characters in the given string. Alias for <a href=\"#uppercase\">uppercase</a>.</p>\n"
|
||||
},
|
||||
"uppercase": {
|
||||
|
@ -748,6 +840,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{uppercase \"aBcDef\"}} -> ABCDEF",
|
||||
"description": "<p>Uppercase all of the characters in the given string. If used as a block helper it will uppercase the entire block. This helper does not support inverse blocks.</p>\n"
|
||||
}
|
||||
},
|
||||
|
@ -759,6 +852,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#and great magnificent}}both{{else}}no{{/and}}",
|
||||
"description": "<p>Helper that renders the block if <strong>both</strong> of the given values are truthy. If an inverse block is specified it will be rendered when falsy. Works as a block helper, inline helper or subexpression.</p>\n"
|
||||
},
|
||||
"compare": {
|
||||
|
@ -769,6 +863,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 4,
|
||||
"example": "{{compare 10 \"<\" 5 }} -> true",
|
||||
"description": "<p>Render a block when a comparison of the first and third arguments returns true. The second argument is the [arithemetic operator][operators] to use. You may also optionally specify an inverse block to render when falsy.</p>\n"
|
||||
},
|
||||
"contains": {
|
||||
|
@ -779,6 +874,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 4,
|
||||
"example": "{{#contains ['a', 'b', 'c'] \"d\"}} This will not be rendered. {{else}} This will be rendered. {{/contains}}",
|
||||
"description": "<p>Block helper that renders the block if <code>collection</code> has the given <code>value</code>, using strict equality (<code>===</code>) for comparison, otherwise the inverse block is rendered (if specified). If a <code>startIndex</code> is specified and is negative, it is used as the offset from the end of the collection.</p>\n"
|
||||
},
|
||||
"default": {
|
||||
|
@ -787,6 +883,7 @@
|
|||
"defaultValue"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{default null null \"default\"}} -> default",
|
||||
"description": "<p>Returns the first value that is not undefined, otherwise the "default" value is returned.</p>\n"
|
||||
},
|
||||
"eq": {
|
||||
|
@ -796,6 +893,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#eq 3 3}} equal{{else}} not equal{{/eq}} -> equal",
|
||||
"description": "<p>Block helper that renders a block if <code>a</code> is <strong>equal to</strong> <code>b</code>. If an inverse block is specified it will be rendered when falsy. You may optionally use the <code>compare=""</code> hash argument for the second value.</p>\n"
|
||||
},
|
||||
"gt": {
|
||||
|
@ -805,6 +903,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#gt 4 3}} greater than{{else}} not greater than{{/gt}} -> greater than",
|
||||
"description": "<p>Block helper that renders a block if <code>a</code> is <strong>greater than</strong> <code>b</code>. If an inverse block is specified it will be rendered when falsy. You may optionally use the <code>compare=""</code> hash argument for the second value.</p>\n"
|
||||
},
|
||||
"gte": {
|
||||
|
@ -814,6 +913,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#gte 4 3}} greater than or equal{{else}} not greater than{{/gte}} -> greater than or equal",
|
||||
"description": "<p>Block helper that renders a block if <code>a</code> is <strong>greater than or equal to</strong> <code>b</code>. If an inverse block is specified it will be rendered when falsy. You may optionally use the <code>compare=""</code> hash argument for the second value.</p>\n"
|
||||
},
|
||||
"has": {
|
||||
|
@ -823,6 +923,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#has \"foobar\" \"foo\"}} has it{{else}} doesn't{{/has}} -> has it",
|
||||
"description": "<p>Block helper that renders a block if <code>value</code> has <code>pattern</code>. If an inverse block is specified it will be rendered when falsy.</p>\n"
|
||||
},
|
||||
"isFalsey": {
|
||||
|
@ -831,6 +932,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{isFalsey \"\" }} -> true",
|
||||
"description": "<p>Returns true if the given <code>value</code> is falsey. Uses the [falsey][] library for comparisons. Please see that library for more information or to report bugs with this helper.</p>\n"
|
||||
},
|
||||
"isTruthy": {
|
||||
|
@ -839,6 +941,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{isTruthy \"12\" }} -> true",
|
||||
"description": "<p>Returns true if the given <code>value</code> is truthy. Uses the [falsey][] library for comparisons. Please see that library for more information or to report bugs with this helper.</p>\n"
|
||||
},
|
||||
"ifEven": {
|
||||
|
@ -847,6 +950,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{#ifEven 2}} even {{else}} odd {{/ifEven}} -> even",
|
||||
"description": "<p>Return true if the given value is an even number.</p>\n"
|
||||
},
|
||||
"ifNth": {
|
||||
|
@ -856,6 +960,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#ifNth 10 2}} remainder {{else}} no remainder {{/ifNth}} -> remainder",
|
||||
"description": "<p>Conditionally renders a block if the remainder is zero when <code>a</code> operand is divided by <code>b</code>. If an inverse block is specified it will be rendered when the remainder is <strong>not zero</strong>.</p>\n"
|
||||
},
|
||||
"ifOdd": {
|
||||
|
@ -864,6 +969,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{#ifOdd 3}} odd {{else}} even {{/ifOdd}} -> odd",
|
||||
"description": "<p>Block helper that renders a block if <code>value</code> is <strong>an odd number</strong>. If an inverse block is specified it will be rendered when falsy.</p>\n"
|
||||
},
|
||||
"is": {
|
||||
|
@ -873,6 +979,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#is 3 3}} is {{else}} is not {{/is}} -> is",
|
||||
"description": "<p>Block helper that renders a block if <code>a</code> is <strong>equal to</strong> <code>b</code>. If an inverse block is specified it will be rendered when falsy. Similar to <a href=\"#eq\">eq</a> but does not do strict equality.</p>\n"
|
||||
},
|
||||
"isnt": {
|
||||
|
@ -882,6 +989,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#isnt 3 3}} isnt {{else}} is {{/isnt}} -> is",
|
||||
"description": "<p>Block helper that renders a block if <code>a</code> is <strong>not equal to</strong> <code>b</code>. If an inverse block is specified it will be rendered when falsy. Similar to <a href=\"#unlesseq\">unlessEq</a> but does not use strict equality for comparisons.</p>\n"
|
||||
},
|
||||
"lt": {
|
||||
|
@ -890,6 +998,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{#lt 2 3}} less than {{else}} more than or equal {{/lt}} -> less than",
|
||||
"description": "<p>Block helper that renders a block if <code>a</code> is <strong>less than</strong> <code>b</code>. If an inverse block is specified it will be rendered when falsy. You may optionally use the <code>compare=""</code> hash argument for the second value.</p>\n"
|
||||
},
|
||||
"lte": {
|
||||
|
@ -899,6 +1008,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#lte 2 3}} less than or equal {{else}} more than {{/lte}} -> less than or equal",
|
||||
"description": "<p>Block helper that renders a block if <code>a</code> is <strong>less than or equal to</strong> <code>b</code>. If an inverse block is specified it will be rendered when falsy. You may optionally use the <code>compare=""</code> hash argument for the second value.</p>\n"
|
||||
},
|
||||
"neither": {
|
||||
|
@ -908,6 +1018,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#neither null null}} both falsey {{else}} both not falsey {{/neither}} -> both falsey",
|
||||
"description": "<p>Block helper that renders a block if <strong>neither of</strong> the given values are truthy. If an inverse block is specified it will be rendered when falsy.</p>\n"
|
||||
},
|
||||
"not": {
|
||||
|
@ -916,6 +1027,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{#not undefined }} falsey {{else}} not falsey {{/not}} -> falsey",
|
||||
"description": "<p>Returns true if <code>val</code> is falsey. Works as a block or inline helper.</p>\n"
|
||||
},
|
||||
"or": {
|
||||
|
@ -924,6 +1036,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 2,
|
||||
"example": "{{#or 1 2 undefined }} at least one truthy {{else}} all falsey {{/or}} -> at least one truthy",
|
||||
"description": "<p>Block helper that renders a block if <strong>any of</strong> the given values is truthy. If an inverse block is specified it will be rendered when falsy.</p>\n"
|
||||
},
|
||||
"unlessEq": {
|
||||
|
@ -933,6 +1046,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#unlessEq 2 1 }} not equal {{else}} equal {{/unlessEq}} -> not equal",
|
||||
"description": "<p>Block helper that always renders the inverse block <strong>unless <code>a</code> is equal to <code>b</code></strong>.</p>\n"
|
||||
},
|
||||
"unlessGt": {
|
||||
|
@ -942,6 +1056,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#unlessGt 20 1 }} not greater than {{else}} greater than {{/unlessGt}} -> greater than",
|
||||
"description": "<p>Block helper that always renders the inverse block <strong>unless <code>a</code> is greater than <code>b</code></strong>.</p>\n"
|
||||
},
|
||||
"unlessLt": {
|
||||
|
@ -951,6 +1066,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#unlessLt 20 1 }} greater than or equal {{else}} less than {{/unlessLt}} -> greater than or equal",
|
||||
"description": "<p>Block helper that always renders the inverse block <strong>unless <code>a</code> is less than <code>b</code></strong>.</p>\n"
|
||||
},
|
||||
"unlessGteq": {
|
||||
|
@ -960,6 +1076,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#unlessGteq 20 1 }} less than {{else}} greater than or equal to {{/unlessGteq}} -> greater than or equal to",
|
||||
"description": "<p>Block helper that always renders the inverse block <strong>unless <code>a</code> is greater than or equal to <code>b</code></strong>.</p>\n"
|
||||
},
|
||||
"unlessLteq": {
|
||||
|
@ -969,6 +1086,7 @@
|
|||
"options"
|
||||
],
|
||||
"numArgs": 3,
|
||||
"example": "{{#unlessLteq 20 1 }} greater than {{else}} less than or equal to {{/unlessLteq}} -> greater than",
|
||||
"description": "<p>Block helper that always renders the inverse block <strong>unless <code>a</code> is less than or equal to <code>b</code></strong>.</p>\n"
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@budibase/string-templates",
|
||||
"version": "0.6.2",
|
||||
"version": "0.7.1",
|
||||
"description": "Handlebars wrapper for Budibase templating.",
|
||||
"main": "src/index.js",
|
||||
"module": "src/index.js",
|
||||
|
@ -14,7 +14,7 @@
|
|||
"manifest": "node ./scripts/gen-collection-info.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@budibase/handlebars-helpers": "^0.11.1",
|
||||
"@budibase/handlebars-helpers": "^0.11.3",
|
||||
"handlebars": "^4.7.6",
|
||||
"handlebars-utils": "^1.0.6",
|
||||
"helper-date": "^1.0.1",
|
||||
|
|
|
@ -14,6 +14,8 @@ const EXTERNAL_FUNCTION_COLLECTIONS = [
|
|||
"url",
|
||||
"string",
|
||||
"comparison",
|
||||
"object",
|
||||
"regex",
|
||||
]
|
||||
|
||||
const DATE_NAME = "date"
|
||||
|
|
|
@ -110,7 +110,7 @@ module.exports.makePropSafe = property => {
|
|||
* @returns {boolean} Whether or not the input string is valid.
|
||||
*/
|
||||
module.exports.isValid = string => {
|
||||
const specialCases = ["isNumber", "expected a number"]
|
||||
const specialCases = ["string", "number", "object", "array"]
|
||||
// don't really need a real context to check if its valid
|
||||
const context = {}
|
||||
try {
|
||||
|
@ -118,7 +118,9 @@ module.exports.isValid = string => {
|
|||
return true
|
||||
} catch (err) {
|
||||
const msg = err ? err.message : ""
|
||||
const foundCase = specialCases.find(spCase => msg.includes(spCase))
|
||||
const foundCase = specialCases.find(spCase =>
|
||||
msg.toLowerCase().includes(spCase)
|
||||
)
|
||||
// special case for maths functions - don't have inputs yet
|
||||
return !!foundCase
|
||||
}
|
||||
|
|
|
@ -4,15 +4,15 @@ const {
|
|||
|
||||
describe("Handling context properties with spaces in their name", () => {
|
||||
it("should allow through literal specifiers", async () => {
|
||||
const output = await processString("test {{ [test thing] }}", {
|
||||
"test thing": 1
|
||||
const output = await processString("test {{ [one thing] }}", {
|
||||
"one thing": 1
|
||||
})
|
||||
expect(output).toBe("test 1")
|
||||
})
|
||||
|
||||
it("should convert to dot notation where required", async () => {
|
||||
const output = await processString("test {{ test[0] }}", {
|
||||
test: [2]
|
||||
const output = await processString("test {{ one[0] }}", {
|
||||
one: [2]
|
||||
})
|
||||
expect(output).toBe("test 2")
|
||||
})
|
||||
|
@ -25,9 +25,9 @@ describe("Handling context properties with spaces in their name", () => {
|
|||
})
|
||||
|
||||
it("should be able to handle an object with layers that requires escaping", async () => {
|
||||
const output = await processString("testcase {{ testing.[test case] }}", {
|
||||
testing: {
|
||||
"test case": 1
|
||||
const output = await processString("testcase {{ thing.[one case] }}", {
|
||||
thing: {
|
||||
"one case": 1
|
||||
}
|
||||
})
|
||||
expect(output).toBe("testcase 1")
|
||||
|
@ -52,10 +52,10 @@ describe("attempt some complex problems", () => {
|
|||
it("should be able to process an odd string produced by builder", async () => {
|
||||
const context = {
|
||||
"c306d140d7e854f388bae056db380a0eb": {
|
||||
"test prop": "test",
|
||||
"one prop": "test",
|
||||
}
|
||||
}
|
||||
const hbs = "null{{ [c306d140d7e854f388bae056db380a0eb].[test prop] }}"
|
||||
const hbs = "null{{ [c306d140d7e854f388bae056db380a0eb].[one prop] }}"
|
||||
const output = await processString(hbs, context)
|
||||
expect(output).toBe("nulltest")
|
||||
})
|
||||
|
|
|
@ -291,14 +291,29 @@ describe("Cover a few complex use cases", () => {
|
|||
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", () => {
|
||||
const validity = isValid("{{ avg [c355ec2b422e54f988ae553c8acd811ea].[a] [c355ec2b422e54f988ae553c8acd811ea].[b] }}")
|
||||
expect(validity).toBe(true)
|
||||
})
|
||||
|
||||
it("should make sure object functions check out valid", () => {
|
||||
const validity = isValid("{{ JSONstringify obj }}")
|
||||
expect(validity).toBe(true)
|
||||
})
|
||||
|
||||
it("should be able to solve an example from docs", async () => {
|
||||
const output = await processString(`{{first ( split "a-b-c" "-") 2}}`, {})
|
||||
expect(output).toBe(`a,b`)
|
||||
})
|
||||
|
||||
it("should confirm a subtraction validity", () => {
|
||||
const validity = isValid("{{ subtract [c390c23a7f1b6441c98d2fe2a51248ef3].[total profit] [c390c23a7f1b6441c98d2fe2a51248ef3].[total revenue] }}")
|
||||
expect(validity).toBe(true)
|
||||
})
|
||||
})
|
|
@ -270,10 +270,10 @@
|
|||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
||||
|
||||
"@budibase/handlebars-helpers@^0.11.1":
|
||||
version "0.11.1"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/handlebars-helpers/-/handlebars-helpers-0.11.1.tgz#fe8672612fb4ad8fd3bad338ee15759f45e421eb"
|
||||
integrity sha512-s72LhOhlHk43QYGVcqjogaGa4h4e6y6X1AfshqWBWceTRYBs/9tUnoYDUiRJ/Mt3WoTmx8Hj5GOZekSqrUsOFQ==
|
||||
"@budibase/handlebars-helpers@^0.11.3":
|
||||
version "0.11.3"
|
||||
resolved "https://registry.yarnpkg.com/@budibase/handlebars-helpers/-/handlebars-helpers-0.11.3.tgz#b6e5c91b83e8906e7d7ff10ddde277a3d561016e"
|
||||
integrity sha512-MS1ptZEYq8o9J3tNLM7cZ2RGSSJIer4GiMIUHtbBI3sC9UKqZebao1JYNfmZKpNjntuqhZKgjqc5GfnVIEjsYQ==
|
||||
dependencies:
|
||||
arr-flatten "^1.1.0"
|
||||
array-sort "^0.1.4"
|
||||
|
@ -4386,9 +4386,9 @@ source-map-support@^0.5.6, source-map-support@~0.5.19:
|
|||
source-map "^0.6.0"
|
||||
|
||||
source-map-url@^0.4.0:
|
||||
version "0.4.0"
|
||||
resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"
|
||||
integrity sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM=
|
||||
version "0.4.1"
|
||||
resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.1.tgz#0af66605a745a5a2f91cf1bbf8a7afbc283dec56"
|
||||
integrity sha512-cPiFOTLUKvJFIg4SKVScy4ilPPW6rFgMgfuZJPNoDuMs3nC1HbMUycBoJw77xFIp6z1UJQJOfx6C9GMH80DiTw==
|
||||
|
||||
source-map@^0.5.0, source-map@^0.5.6:
|
||||
version "0.5.7"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@budibase/deployment",
|
||||
"email": "hi@budibase.com",
|
||||
"version": "0.6.2",
|
||||
"version": "0.7.1",
|
||||
"description": "Budibase Deployment Server",
|
||||
"main": "src/index.js",
|
||||
"repository": {
|
||||
|
|
Loading…
Reference in New Issue