A major new feature for my Cross-platform Release Notes Azure DevOps Pipelines Extension–Handlebars Templating Support

I recently got a very interesting PR for my Cross-platform Release Notes Azure DevOps Pipelines Extension from Kenneth Scott. He had added a new templating engine to the task, Handlebars.

Previous to this PR the templating in the task was done with a line by line evaluation of a template that used my own mark-up. This method worked but has limitations, mostly due to the line by line evaluation model.  With the Kenneth’s PR the option was added to write your templates in Handlebars, or stay with my previous templating engine.

Using Handlebars

If you use Handlebars, the template becomes something like

 1\## Notes for release  {{releaseDetails.releaseDefinition.name}}    
 2\*\*Release Number\*\*  : {{releaseDetails.name}}
 3\*\*Release completed\*\* : {{releaseDetails.modifiedOn}}     
 4\*\*Build Number\*\*: {{buildDetails.id}}
 5\*\*Compared Release Number\*\*  : {{compareReleaseDetails.name}}    
 6
 7### Associated Work Items ({{workItems.length}})
 8{{#each workItems}}
 9\*  \*\*{{this.id}}\*\*  {{lookup this.fields 'System.Title'}}
10   - \*\*WIT\*\* {{lookup this.fields 'System.WorkItemType'}} 
11   - \*\*Tags\*\* {{lookup this.fields 'System.Tags'}}
12{{/each}}
13
14### Associated commits ({{commits.length}})
15{{#each commits}}
16\* \*\* ID{{this.id}}\*\* 
17   -  \*\*Message:\*\* {{this.message}}
18   -  \*\*Commited by:\*\* {{this.author.displayName}} 
19{{/each}}

The whole template is evaluated by the Handlebars engine using its own mark-up to provide a means for looping across arrays and the like.

This seemed a great enhancement to the task. However, we soon realised that it could be better. Handlebars is extensible, so why not allow the extensibility to be used?

Using Handlebars Extensions

I have added extensibility in two ways. Firstly I have also added support for the common Handlebar-Helpers extensions, this added over 150 helpers. These are just accessed in a template as follows

1\## To confirm the handbars-helpers is work
2The year is {{year}} 
3We can capitalize "foo bar baz" {{capitalizeAll "foo bar baz"}}

I have also added the ability to provide a block of JavaScript as a task parameter is that is loaded as a custom Handlebars extension. So if you add the following block in the tasks customHandlebarsExtensionCode parameter.

1module.exports = {foo: function () {return 'Returns foo';}};

You can access in the templates as

1\## To confirm our custom extension works
2We can call our custom extension {{foo}}

It will be interesting to see how popular this alternative way of templating will be.