Skip to content

Commit 7fbfe2f

Browse files
committed
docs(cpp-matrix): handlebars helpers
1 parent 16eddf0 commit 7fbfe2f

File tree

2 files changed

+51
-12
lines changed

2 files changed

+51
-12
lines changed

cpp-matrix/action.yml

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ description: |
140140
existing values in the matrix. For instance, consider an entry in the matrix that has
141141
the `x86` factor set to true.
142142
143-
When using `b2`, we should set `address-model=32` for this entry. Otherwise, we should set
143+
Assume we are using `b2` and should set `address-model=32` for this entry. Otherwise, we should set
144144
`address-model=64`. With GitHub expressions, we can generate this value based on the `x86` factor:
145145
146146
`b2 address-model={{ matrix.x86 && '32' || '64' }}`
147147
148-
If this pattern needs to be repeated in many entries, this pattern might become cumbersome.
148+
If this pattern needs to be repeated in many entries, it might become cumbersome.
149149
In this case, the action allows the user to define extra values to be injected in each entry
150150
of the matrix. These values can be used to generate new values based on existing values in
151151
the matrix with handlebars. You could set the following extra values in each entry of the matrix:
@@ -159,6 +159,45 @@ description: |
159159
run: |
160160
b2 address-model={{ matrix.address-model }}
161161
----
162+
163+
or
164+
165+
[source,yml]
166+
----
167+
extra-values: |
168+
address-model-arg: address-model={{#if x86}}32{{else}}64{{/if}}
169+
170+
# ...
171+
run: |
172+
b2 {{ matrix.address-model-arg }}
173+
----
174+
175+
The syntax for each entry in the `extra-values` input is a key-value pair, where the key is the name of the
176+
value to be injected in the matrix and the value is a handlebars expression that generates the value based on
177+
other values in the matrix. The handlebars expression can access previous values in the matrix, including
178+
other extra values.
179+
180+
Besides referencing other values in the matrix, the handlebars expressions can also use the
181+
built-in https://handlebarsjs.com/guide/builtin-helpers.html[helpers] provided by Handlebars and the
182+
predefined helpers defined by the action:
183+
184+
[cols="1,3"]
185+
|===
186+
| Helper | Description
187+
| `lowercase` | Converts the value to lowercase
188+
| `uppercase` | Converts the value to uppercase
189+
| `contains` | Checks if the value contains a substring
190+
| `startsWith` / `starts-with` | Checks if the value starts with a substring
191+
| `endsWith` / `ends-with` | Checks if the value ends with a substring
192+
| `substring` | Extracts a substring from the value
193+
| `and` | Logical AND operator
194+
| `or` | Logical OR operator
195+
| `not` | Logical NOT operator
196+
| `eq` | Equality operator
197+
| `ieq` | Case-insensitive equality operator
198+
| `ne` | Inequality operator
199+
| `ine` | Case-insensitive inequality operator
200+
|===
162201
163202
== Ordering entries
164203

cpp-matrix/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,16 @@ function registerHelpers() {
11651165
args.pop()
11661166
return args.every((it) => it)
11671167
})
1168+
Handlebars.registerHelper('or', function(...args) {
1169+
const numArgs = args.length
1170+
if (numArgs === 3) return args[0] || args[1]
1171+
if (numArgs < 3) throw new Error('{{or}} helper expects at least 2 arguments')
1172+
args.pop()
1173+
return args.some((it) => it)
1174+
})
1175+
Handlebars.registerHelper('not', function(value) {
1176+
return !value
1177+
})
11681178
Handlebars.registerHelper('eq', function(a, b) {
11691179
return a === b
11701180
})
@@ -1177,16 +1187,6 @@ function registerHelpers() {
11771187
Handlebars.registerHelper('ine', function(a, b) {
11781188
return a.toLowerCase() !== b.toLowerCase()
11791189
})
1180-
Handlebars.registerHelper('or', function(...args) {
1181-
const numArgs = args.length
1182-
if (numArgs === 3) return args[0] || args[1]
1183-
if (numArgs < 3) throw new Error('{{or}} helper expects at least 2 arguments')
1184-
args.pop()
1185-
return args.some((it) => it)
1186-
})
1187-
Handlebars.registerHelper('not', function(value) {
1188-
return !value
1189-
})
11901190
}
11911191

11921192

0 commit comments

Comments
 (0)