test if qui passe
This commit is contained in:
parent
8ff3f581c5
commit
9e35737995
@ -173,28 +173,70 @@ function extractBlockContent(blockStartNode, blockEndNode){
|
|||||||
* @param {Compartment} compartment
|
* @param {Compartment} compartment
|
||||||
*/
|
*/
|
||||||
function fillIfBlock(ifOpeningMarkerNode, ifElseMarkerNode, ifClosingMarkerNode, ifBlockConditionExpression, compartment){
|
function fillIfBlock(ifOpeningMarkerNode, ifElseMarkerNode, ifClosingMarkerNode, ifBlockConditionExpression, compartment){
|
||||||
console.log('fillIfBlock pas encore codée')
|
|
||||||
|
|
||||||
const conditionValue = compartment.evaluate(ifBlockConditionExpression)
|
const conditionValue = compartment.evaluate(ifBlockConditionExpression)
|
||||||
|
|
||||||
if(conditionValue){
|
let startChild
|
||||||
// récupérer le morceau entre ifOpeningMarkerNode et ifElseMarkerNode
|
let endChild
|
||||||
// l'executer
|
|
||||||
|
let markerNodes = new Set()
|
||||||
|
|
||||||
|
let chosenFragment
|
||||||
|
|
||||||
|
if(ifElseMarkerNode){
|
||||||
|
const {
|
||||||
|
startChild: startIfThenChild,
|
||||||
|
endChild: endIfThenChild,
|
||||||
|
content: thenFragment
|
||||||
|
} = extractBlockContent(ifOpeningMarkerNode, ifElseMarkerNode)
|
||||||
|
|
||||||
|
const {
|
||||||
|
startChild: startIfElseChild,
|
||||||
|
endChild: endIfElseChild,
|
||||||
|
content: elseFragment
|
||||||
|
} = extractBlockContent(ifElseMarkerNode, ifClosingMarkerNode)
|
||||||
|
|
||||||
|
chosenFragment = conditionValue ? thenFragment : elseFragment
|
||||||
|
startChild = startIfThenChild
|
||||||
|
endChild = endIfElseChild
|
||||||
|
|
||||||
|
markerNodes
|
||||||
|
.add(startIfThenChild).add(endIfThenChild)
|
||||||
|
.add(startIfElseChild).add(endIfElseChild)
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
const {
|
||||||
|
startChild: startIfThenChild,
|
||||||
|
endChild: endIfThenChild,
|
||||||
|
content: thenFragment
|
||||||
|
} = extractBlockContent(ifOpeningMarkerNode, ifClosingMarkerNode)
|
||||||
|
|
||||||
|
chosenFragment = conditionValue ? thenFragment : undefined
|
||||||
|
startChild = startIfThenChild
|
||||||
|
endChild = endIfThenChild
|
||||||
|
|
||||||
|
markerNodes
|
||||||
|
.add(startIfThenChild).add(endIfThenChild)
|
||||||
}
|
}
|
||||||
|
|
||||||
// dans tous les cas, recupérer ce qu'il y a entre ifOpeningMarkerNode et ifClosingMarkerNode
|
|
||||||
// et le supprimer de l'arbre
|
|
||||||
|
|
||||||
|
if(chosenFragment){
|
||||||
|
fillTemplatedOdtElement(
|
||||||
|
chosenFragment,
|
||||||
|
compartment
|
||||||
|
)
|
||||||
|
|
||||||
|
endChild.parentNode.insertBefore(chosenFragment, endChild)
|
||||||
|
}
|
||||||
|
|
||||||
|
for(const markerNode of markerNodes){
|
||||||
|
try{
|
||||||
|
// may throw if node already out of tree
|
||||||
|
// might happen if
|
||||||
|
markerNode.parentNode.removeChild(markerNode)
|
||||||
|
}
|
||||||
|
catch(e){}
|
||||||
|
}
|
||||||
|
|
||||||
/*throw `PPP
|
|
||||||
- executer l'expression
|
|
||||||
- selon la valeur, choisir le bon block à extraire/remplir
|
|
||||||
-
|
|
||||||
`*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -242,7 +284,7 @@ function fillEachBlock(startNode, iterableExpression, itemExpression, endNode, c
|
|||||||
endChild.parentNode.insertBefore(itemFragment, endChild)
|
endChild.parentNode.insertBefore(itemFragment, endChild)
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove block elements
|
// remove block marker elements
|
||||||
startChild.parentNode.removeChild(startChild)
|
startChild.parentNode.removeChild(startChild)
|
||||||
endChild.parentNode.removeChild(endChild)
|
endChild.parentNode.removeChild(endChild)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,10 +10,10 @@ test('basic template filling with {#if}', async t => {
|
|||||||
const templatePath = join(import.meta.dirname, '../fixtures/description-nombre.odt')
|
const templatePath = join(import.meta.dirname, '../fixtures/description-nombre.odt')
|
||||||
const templateContent = `Description du nombre {n}
|
const templateContent = `Description du nombre {n}
|
||||||
|
|
||||||
{#if n >5}
|
{#if n<5}
|
||||||
n est un grand nombre
|
|
||||||
{:else}
|
|
||||||
n est un petit nombre
|
n est un petit nombre
|
||||||
|
{:else}
|
||||||
|
n est un grand nombre
|
||||||
{/if}
|
{/if}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|||||||
BIN
tests/fixtures/description-nombre.odt
vendored
BIN
tests/fixtures/description-nombre.odt
vendored
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user