Releases: splumhoff/PSMustache
v1.3.2 - Custom Delimiters
Added Delimiter Support to Get-MustacheTemplate
and ConvertFrom-MustacheTemplate
as requested in #2 .
This can be usefull if you want to use a template which already contains mustache-like tags for another templating engine which shall be left untouched.
ConvertFrom-MustacheTemplate -Template 'Hi [[Name]], {{keepThisUntouched}}!' -Values @{Name='Joe'} -DelimiterLeft '[[' -DelimiterRight ']]'
Hi Joe, {{keepThisUntouched}}!
v1.3.1 - Template Caching Support
The new Function Get-MustacheTemplate
was added to enable caching of a Mustache Template for multiple runs. (As asked in #1 )
If the values comes from the pipeline, the Template is also implicitly cached upon the first run.
PS> # Generate Test Data
PS> $data = New-Object System.Collections.ArrayList
PS> 1..1000 | %{ $data.Add(@{Num = $_}) | Out-Null }
PS> # Explicit Caching
PS> (Measure-Command { $template = Get-MustacheTemplate -Template 'Current Iteration {{Num}}'; $data | ConvertFrom-MustacheTemplate -Template $template }).TotalMilliseconds
192,4528
PS> # Implicit Caching
PS> (Measure-Command { $data | ConvertFrom-MustacheTemplate -Template 'Current Iteration {{Num}}' }).TotalMilliseconds
191,006
PS> # No Caching / iterating
PS> (Measure-Command { $data | ForEach-Object { ConvertFrom-MustacheTemplate -Template 'Current Iteration {{Num}}' -Values $_ }}).TotalMilliseconds
584,1476
If you have any feedback how this affects complex runs please leave it here. :)
v1.3 - Lambda Support
This release adds "Lambda-Support" to PSMustache along with a few minor performance improvements.
You can simply pass a ScriptBlock as Member of a Hashtable to get the code executed.
The Lambda-Functions can be used in Interpolation-Tags {{MyFunction}}
as well as in Sections.
When used in Interpolation Tags, the ScriptBlock is called without any parameters.
PS> ConvertFrom-MustacheTemplate -Template 'Current Time: {{Time}}' -Values @{'time' = { Get-Date }}
Current Time: 05/11/2021 17:00:00
In Sections-Tags the content of the section is passed to the ScriptBlock:
PS> ConvertFrom-MustacheTemplate -Template 'Current Date: {{#Time}}yyyy-MM-dd{{/Time}}' -Values @{'time' = {Get-Date -Format $args[0]}}
Current Date: 2021-05-11
You can grab the content of the section tags via $args[0]
(as in the above example) or via params, when defined in the ScriptBlock:
ConvertFrom-MustacheTemplate -Template 'Current Time: {{#Time}}yyyy-MM-dd{{/Time}}' -Values @{'time' = {param($format) Get-Date -Format $format}}
Current Date: 2021-05-11
Hope you enjoy the new feature and find it useful. :-)