Ouinon bug (#10)
* rename * change order of removals in fillIfBlock to properly remove right/left content
This commit is contained in:
parent
9fa9c9eb62
commit
5aac86553c
@ -207,9 +207,9 @@ class TemplateBlock{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//console.group('\n== TemplateBlock ==')
|
//console.group('\n== TemplateBlock ==')
|
||||||
//console.log('startBranch', this.startBranch.at(1).nodeName, this.startBranch.at(1).textContent)
|
//this.startBranch.logBranch('startBranch')
|
||||||
//console.log('middleContent', this.#middleContent.map(n => n.textContent).join(''))
|
//console.log('middleContent', this.#middleContent.map(n => n.textContent).join(''))
|
||||||
//console.log('endBranch', this.startBranch.at(1).nodeName, this.endBranch.at(1).textContent)
|
//this.endBranch.logBranch('endBranch')
|
||||||
//console.log('common ancestor', this.#commonAncestor.nodeName, '\n')
|
//console.log('common ancestor', this.#commonAncestor.nodeName, '\n')
|
||||||
//console.groupEnd()
|
//console.groupEnd()
|
||||||
}
|
}
|
||||||
@ -425,6 +425,8 @@ function findPlacesToFillInString(str, compartment) {
|
|||||||
* @param {Compartment} compartment
|
* @param {Compartment} compartment
|
||||||
*/
|
*/
|
||||||
function fillIfBlock(ifOpeningMarkerNode, ifElseMarkerNode, ifClosingMarkerNode, ifBlockConditionExpression, compartment) {
|
function fillIfBlock(ifOpeningMarkerNode, ifElseMarkerNode, ifClosingMarkerNode, ifBlockConditionExpression, compartment) {
|
||||||
|
//const docEl = ifOpeningMarkerNode.ownerDocument.documentElement
|
||||||
|
|
||||||
const conditionValue = compartment.evaluate(ifBlockConditionExpression)
|
const conditionValue = compartment.evaluate(ifBlockConditionExpression)
|
||||||
|
|
||||||
/** @type {TemplateBlock | undefined} */
|
/** @type {TemplateBlock | undefined} */
|
||||||
@ -445,21 +447,26 @@ function fillIfBlock(ifOpeningMarkerNode, ifElseMarkerNode, ifClosingMarkerNode,
|
|||||||
thenTemplateBlock = new TemplateBlock(ifOpeningMarkerNode, ifClosingMarkerNode)
|
thenTemplateBlock = new TemplateBlock(ifOpeningMarkerNode, ifClosingMarkerNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
thenTemplateBlock.removeMarkersAndEmptyAncestors()
|
|
||||||
if(elseTemplateBlock){
|
|
||||||
elseTemplateBlock.removeMarkersAndEmptyAncestors()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(conditionValue) {
|
if(conditionValue) {
|
||||||
thenTemplateBlock.fillBlockContentTemplate(compartment)
|
|
||||||
|
|
||||||
if(elseTemplateBlock){
|
if(elseTemplateBlock){
|
||||||
elseTemplateBlock.removeContent()
|
elseTemplateBlock.removeContent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
thenTemplateBlock.removeMarkersAndEmptyAncestors()
|
||||||
|
if(elseTemplateBlock){
|
||||||
|
elseTemplateBlock.removeMarkersAndEmptyAncestors()
|
||||||
|
}
|
||||||
|
|
||||||
|
thenTemplateBlock.fillBlockContentTemplate(compartment)
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
// remove content before removing markers so that right and left content are fully removed
|
||||||
thenTemplateBlock.removeContent()
|
thenTemplateBlock.removeContent()
|
||||||
|
|
||||||
|
thenTemplateBlock.removeMarkersAndEmptyAncestors()
|
||||||
|
if(elseTemplateBlock){
|
||||||
|
elseTemplateBlock.removeMarkersAndEmptyAncestors()
|
||||||
|
}
|
||||||
|
|
||||||
if(elseTemplateBlock){
|
if(elseTemplateBlock){
|
||||||
elseTemplateBlock.fillBlockContentTemplate(compartment)
|
elseTemplateBlock.fillBlockContentTemplate(compartment)
|
||||||
|
|||||||
@ -167,8 +167,8 @@ test('template filling - formatted-start-each-single-paragraph', async t => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
test('template filling - formatted ghost if', async t => {
|
test('template filling - formatted ghost if then', async t => {
|
||||||
const templatePath = join(import.meta.dirname, '../fixtures/reducing.odt')
|
const templatePath = join(import.meta.dirname, '../fixtures/ghost-if.odt')
|
||||||
const templateContent = `
|
const templateContent = `
|
||||||
Utilisation de sources lumineuses : {#if scientifique.source_lumineuses}Oui{:else}Non{/if}
|
Utilisation de sources lumineuses : {#if scientifique.source_lumineuses}Oui{:else}Non{/if}
|
||||||
`
|
`
|
||||||
@ -188,3 +188,24 @@ test('template filling - formatted ghost if', async t => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('template filling - formatted ghost if else', async t => {
|
||||||
|
const templatePath = join(import.meta.dirname, '../fixtures/ghost-if.odt')
|
||||||
|
const templateContent = `
|
||||||
|
Utilisation de sources lumineuses : {#if scientifique.source_lumineuses}Oui{:else}Non{/if}
|
||||||
|
`
|
||||||
|
|
||||||
|
const data = {scientifique: {source_lumineuses: false}}
|
||||||
|
|
||||||
|
const odtTemplate = await getOdtTemplate(templatePath)
|
||||||
|
|
||||||
|
const templateTextContent = await getOdtTextContent(odtTemplate)
|
||||||
|
t.deepEqual(templateTextContent.trim(), templateContent.trim(), 'reconnaissance du template')
|
||||||
|
let odtResult = await fillOdtTemplate(odtTemplate, data)
|
||||||
|
|
||||||
|
const odtResultTextContent = await getOdtTextContent(odtResult)
|
||||||
|
t.deepEqual(odtResultTextContent.trim(), `
|
||||||
|
Utilisation de sources lumineuses : Non
|
||||||
|
`.trim())
|
||||||
|
|
||||||
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user