Probesys / lotemplate

LOTemplate is document generator used to create documents programatically (ODT, DOCX, PDF) from a template (DOCX or ODT) and a json file.
GNU Affero General Public License v3.0
23 stars 1 forks source link

[FEATURE] Add for/endfor syntax for loops #10

Closed philippe-levan closed 1 year ago

philippe-levan commented 1 year ago

Is your feature request related to a problem? Please describe.

I need to display a list of people in a document. They have several properties : names, phone, email...

This can be displayed as bullet points or different paragraph for each people.

Describe the solution you'd like

I imagine a syntax in the word file like

People in company $companyName
[for index, item in people]
People number $index
Civility: [if $item(civility) == Mr]Mister[endif][if $item(civility) == Miss]Miss[endif]
Name : $item(firstName) $item(lastName)
Address : $item(adr.street1) $item(adr.street2) $item(adr.zip)$item(adr.city)
[endfor]

with a json file like

"variables": {
  "companyName": {"type": "text", "value": "Dev Inc."},
  "people": {"type": "array", "value": [
    {
      "firstName": "Corinne",
      "lastName": "Dupont",
      "civility": "Miss",
      "addr": {
        "street1": "5 rue de la paix",
        "street2": "",
        "zip": "38000",
        "city": "Grenoble"
      }
    },
    {
      "firstName": "Robert",
      "lastName": "Durand",
      "civility": "Mr",
      "addr": {
        "street1": "15 place des fêtes",
        "street2": "",
        "zip": "38000",
        "city": "Grenoble",
      },
    }
  ]}
}

And the result would be

People in company Dev Inc.

People number 0
Civility: Miss
Name : Corinne Dupont
Address : 5 rue de la paix, 38000 Grenoble

People number 1
Civility: Mister
Name : Robert Durand
Address : 15 place des fêtes, 38000 Grenoble

Note :

This syntax can work with a simple array or with a dict for the "people" value

Describe alternatives you've considered

No response

Additional context

This syntax is not very easy because the syntax used implies a change in the scanning system of simple vars. But I believe we should not continue to create new prefix like $ or & for each variable type.

philippe-levan commented 1 year ago

Note : I can work on the PR that will implement this feature, but I need to be confident with the syntax choice inside the libre office document. So I think this is a good idea to work on this syntax.

cyrilus commented 1 year ago

done