Compare commits
3 Commits
main
...
bug-ap-sci
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffc682f70b | ||
|
|
549c53ce35 | ||
|
|
657f8ce624 |
@ -601,6 +601,7 @@ export default function fillOdtElementTemplate(rootElements, compartment) {
|
||||
// @ts-ignore
|
||||
traverse(rootElement, currentNode => {
|
||||
//console.log('currentlyOpenBlocks', currentlyOpenBlocks)
|
||||
//console.log('eachOpeningMarkerNode', eachOpeningMarkerNode)
|
||||
|
||||
const insideAnOpenBlock = currentlyOpenBlocks.length >= 1
|
||||
|
||||
@ -637,11 +638,10 @@ export default function fillOdtElementTemplate(rootElements, compartment) {
|
||||
|
||||
if(isEachClosingBlock) {
|
||||
|
||||
//console.log('isEachClosingBlock', isEachClosingBlock)
|
||||
//console.log('isEachClosingBlock', isEachClosingBlock, currentlyOpenBlocks)
|
||||
|
||||
if(!eachOpeningMarkerNode){
|
||||
throw new Error(`{/each} found without corresponding opening {#each x as y}`)
|
||||
}
|
||||
if(!insideAnOpenBlock)
|
||||
throw new Error('{/each} found without corresponding opening {#each x as y}')
|
||||
|
||||
if(currentlyOpenBlocks.at(-1) !== EACH)
|
||||
throw new Error(`{/each} found while the last opened block was not an opening {#each x as y}`)
|
||||
|
||||
25
tests/fill-odt-template/complex.js
Normal file
25
tests/fill-odt-template/complex.js
Normal file
@ -0,0 +1,25 @@
|
||||
import test from 'ava';
|
||||
import {join} from 'node:path';
|
||||
|
||||
import {getOdtTemplate} from '../../scripts/odf/odtTemplate-forNode.js'
|
||||
|
||||
import {fillOdtTemplate, getOdtTextContent} from '../../exports.js'
|
||||
|
||||
|
||||
test('template with {#each} inside an {#if}', async t => {
|
||||
const templatePath = join(import.meta.dirname, '../fixtures/if-then-each.odt')
|
||||
const templateContent = `{#if liste_départements.length >= 2}{#each liste_départements as département}{département}, {/each} {/if}`
|
||||
|
||||
const data = {liste_départements : ['95', '33']}
|
||||
|
||||
const odtTemplate = await getOdtTemplate(templatePath)
|
||||
const templateTextContent = await getOdtTextContent(odtTemplate)
|
||||
t.deepEqual(templateTextContent.trim(), templateContent.trim(), 'reconnaissance du template')
|
||||
|
||||
const odtResult = await fillOdtTemplate(odtTemplate, data)
|
||||
|
||||
const odtResultTextContent = await getOdtTextContent(odtResult)
|
||||
t.deepEqual(odtResultTextContent.trim(), `95, 33,`)
|
||||
|
||||
});
|
||||
|
||||
BIN
tests/fixtures/if-then-each.odt
vendored
Normal file
BIN
tests/fixtures/if-then-each.odt
vendored
Normal file
Binary file not shown.
@ -103,6 +103,7 @@ const templatePath = join(import.meta.dirname, '../tests/fixtures/partially-form
|
||||
const data = {nombre : 37}
|
||||
*/
|
||||
|
||||
/*
|
||||
const templatePath = join(import.meta.dirname, '../tests/fixtures/text-after-closing-each.odt')
|
||||
const data = {
|
||||
saison: 'Printemps',
|
||||
@ -112,7 +113,10 @@ const data = {
|
||||
'Blette'
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
const templatePath = join(import.meta.dirname, '../tests/fixtures/if-then-each.odt')
|
||||
const data = {liste_départements : ['95', '33']}
|
||||
|
||||
|
||||
const odtTemplate = await getOdtTemplate(templatePath)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user