Skip to content

Commit 57cd807

Browse files
committed
Template block with-metadata argument
If you supply a 2nd positional argument, then the data will be passed to the template as: ``` { ...attributes, data = data } ``` For example ``` [template, partial$foo.json, with-data, from=100, to=200] --- {{#each data}} The data item from foo.json is {{.}}. The global metadata is: from: {{@root.from}} to: {{@root.to}}) {{/each}} --- ```
1 parent 26d7dc9 commit 57cd807

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/template-block.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function register (registry, config) {
3333
const self = this
3434

3535
self.named('template')
36-
self.positionalAttributes('dataResourceId')
36+
self.positionalAttributes(['dataResourceId', 'withMetadata'])
3737
self.onContext('open')
3838

3939
self.process((parent, reader, attributes) => process(parent, reader, attributes, config, self));
@@ -44,13 +44,18 @@ function register (registry, config) {
4444
function process (parent, reader, attributes, config, block) {
4545
try {
4646
// resolve json or .yml data
47-
const data = getResource(attributes.dataResourceId, config)
47+
var data = getResource(attributes.dataResourceId, config)
4848

4949
// compile .hbs template
5050
setupHandlebars(attributes, config)
5151
const source = reader.getLines().join('\n')
5252

5353
const template = handlebars.compile(source)
54+
55+
if (attributes.withMetadata) {
56+
data = { ...attributes, data }
57+
}
58+
5459
// output
5560
const output = template(data)
5661
const parsed = asciidoctor.load(output)

0 commit comments

Comments
 (0)