jehugaleahsa / mustache-sharp

An extension of the mustache text template engine for .NET.
The Unlicense
306 stars 80 forks source link

Created a Delimiter tag that allows nicely delimited lists #75

Open Andrew-Hanlon opened 7 years ago

Andrew-Hanlon commented 7 years ago

A common requirement is to have a list with a delimiter that is not shown for the final item - i.e. 1, 2, 3 instead of 1, 2, 3,. This is often accomplished using the string.Join method in C#.

With this pull request, content between delimiter tags will only be shown when not on the final item.

The implementation does not introduce any performance changes as I implemented a custom iteration block such that there is no chance for double-enumeration or requirement for the count/length.

I added two unit tests, and all tests pass.

Andrew-Hanlon commented 7 years ago

I realised after pushing this that other variations of mustache use the 'delimiter' keyword to change the bracketing. Maybe a better tag for this new delimiter would be 'separator', or a short form like 'sep'. I would be happy to change the pull request.