accordproject / template-archive

Smart Legal Contracts & Templating System
https://accordproject.org/projects/cicero/
Apache License 2.0
280 stars 119 forks source link

Extend 'separators' that are supported in join blocks #710

Open OliverTod opened 2 years ago

OliverTod commented 2 years ago

At the moment, a simple separator can be set by the user that will be inserted between all values in an array when populating a template.

So, for example:

TemplateMark: Discount applies to the following items: {{#join items separator=", "}}{{name}} ({{id}}){{/join}}

will accept an array of {{"name": "Pineapple", "id": 111}, {"name": "Strawberries", "id": 222}, {"name": "Pomegranate", "id": 333}}

to give: Discount applies to the following items: Pineapple (111), Strawberries (222), Pomegranate (333)

Each list item is separated by a comma.

Request: There should be support for specifically setting the standard, penultimate and final separators. This is already done in other doc generation tools which use the | symbol is used to indicate the punctuation as "list item | penultimate item | final item"

Example syntax: ;|; and|.

So, the example above with the new functionality would be:

TemplateMark: Discount applies to the following items: {{#join items separator=",|and|. "}}{{name}} ({{id}}){{/join}}.

will accept an array of {{"name": "Pineapple", "id": 111}, {"name": "Strawberries", "id": 222}, {"name": "Pomegranate", "id": 333}}

to give: Discount applies to the following items: Pineapple (111), Strawberries (222) and Pomegranate (333).