passing tests except the if one
This commit is contained in:
parent
64dbb65635
commit
2c20c65375
@ -294,7 +294,8 @@ function fillTemplatedOdtElement(rootElement, compartment){
|
||||
|
||||
// @ts-ignore
|
||||
traverse(rootElement, currentNode => {
|
||||
const insideAnEachBlock = !!eachBlockOpeningNode
|
||||
//console.log('currentlyUnclosedBlocks', currentlyUnclosedBlocks)
|
||||
const insideAnOpenBlock = currentlyUnclosedBlocks.length >= 1
|
||||
|
||||
if(currentNode.nodeType === Node.TEXT_NODE){
|
||||
const text = currentNode.textContent || ''
|
||||
@ -303,9 +304,15 @@ function fillTemplatedOdtElement(rootElement, compartment){
|
||||
const eachStartRegex = /{#each\s+([^}]+?)\s+as\s+([^}]+?)\s*}/;
|
||||
const startMatch = text.match(eachStartRegex);
|
||||
|
||||
//console.log('text, match', )
|
||||
|
||||
if(startMatch){
|
||||
if(insideAnEachBlock){
|
||||
currentlyUnclosedBlocks.push(EACH)
|
||||
//console.log('startMatch', startMatch)
|
||||
|
||||
currentlyUnclosedBlocks.push(EACH)
|
||||
|
||||
if(insideAnOpenBlock){
|
||||
// do nothing
|
||||
}
|
||||
else{
|
||||
let [_, _iterableExpression, _itemExpression] = startMatch
|
||||
@ -320,16 +327,18 @@ function fillTemplatedOdtElement(rootElement, compartment){
|
||||
const eachClosingBlockString = '{/each}'
|
||||
const isEachClosingBlock = text.includes(eachClosingBlockString)
|
||||
|
||||
if(isEachClosingBlock){
|
||||
if(isEachClosingBlock){
|
||||
|
||||
//console.log('isEachClosingBlock', isEachClosingBlock)
|
||||
|
||||
if(!eachBlockOpeningNode)
|
||||
throw new Error(`{/each} found without corresponding opening {#each x as y}`)
|
||||
|
||||
if(currentlyUnclosedBlocks.at(-1) !== EACH)
|
||||
throw new Error(`{/each} found while the last opened block was not an opening {#each x as y}`)
|
||||
|
||||
if(currentlyUnclosedBlocks.length >= 1){
|
||||
if(currentlyUnclosedBlocks.filter(x => x === EACH).length > 1){
|
||||
// ignore because it will be treated as part of the outer {#each}
|
||||
currentlyUnclosedBlocks.pop()
|
||||
}
|
||||
else{
|
||||
eachBlockClosingNode = currentNode
|
||||
@ -343,11 +352,13 @@ function fillTemplatedOdtElement(rootElement, compartment){
|
||||
eachBlockItemExpression = undefined
|
||||
eachBlockClosingNode = undefined
|
||||
}
|
||||
|
||||
currentlyUnclosedBlocks.pop()
|
||||
}
|
||||
|
||||
|
||||
// Looking for variables for substitutions
|
||||
if(!insideAnEachBlock){
|
||||
if(!insideAnOpenBlock){
|
||||
// @ts-ignore
|
||||
if (currentNode.data) {
|
||||
// @ts-ignore
|
||||
@ -369,7 +380,7 @@ function fillTemplatedOdtElement(rootElement, compartment){
|
||||
|
||||
if(currentNode.nodeType === Node.ATTRIBUTE_NODE){
|
||||
// Looking for variables for substitutions
|
||||
if(!insideAnEachBlock){
|
||||
if(!insideAnOpenBlock){
|
||||
// @ts-ignore
|
||||
if (currentNode.value) {
|
||||
// @ts-ignore
|
||||
|
||||
@ -4,7 +4,6 @@ import {join} from 'node:path';
|
||||
import {getOdtTemplate} from '../../scripts/odf/odtTemplate-forNode.js'
|
||||
|
||||
import {fillOdtTemplate, getOdtTextContent} from '../../exports.js'
|
||||
import { listZipEntries } from '../helpers/zip-analysis.js';
|
||||
|
||||
|
||||
test('basic template filling with variable substitution', async t => {
|
||||
|
||||
@ -4,11 +4,9 @@ import {join} from 'node:path';
|
||||
import {getOdtTemplate} from '../../scripts/odf/odtTemplate-forNode.js'
|
||||
|
||||
import {fillOdtTemplate, getOdtTextContent} from '../../exports.js'
|
||||
import { listZipEntries } from '../helpers/zip-analysis.js';
|
||||
|
||||
|
||||
|
||||
test.skip('basic template filling with {#each}', async t => {
|
||||
test('basic template filling with {#each}', async t => {
|
||||
const templatePath = join(import.meta.dirname, '../fixtures/enum-courses.odt')
|
||||
const templateContent = `🧺 La liste de courses incroyable 🧺
|
||||
|
||||
@ -45,7 +43,7 @@ Pâtes à lasagne (fraîches !)
|
||||
});
|
||||
|
||||
|
||||
test.skip('Filling with {#each} and non-iterable value results in no error and empty result', async t => {
|
||||
test('Filling with {#each} and non-iterable value results in no error and empty result', async t => {
|
||||
const templatePath = join(import.meta.dirname, '../fixtures/enum-courses.odt')
|
||||
const templateContent = `🧺 La liste de courses incroyable 🧺
|
||||
|
||||
@ -75,7 +73,7 @@ test.skip('Filling with {#each} and non-iterable value results in no error and e
|
||||
});
|
||||
|
||||
|
||||
test.skip('template filling with {#each} generating a list', async t => {
|
||||
test('template filling with {#each} generating a list', async t => {
|
||||
const templatePath = join(import.meta.dirname, '../fixtures/liste-courses.odt')
|
||||
const templateContent = `🧺 La liste de courses incroyable 🧺
|
||||
|
||||
@ -112,7 +110,7 @@ test.skip('template filling with {#each} generating a list', async t => {
|
||||
});
|
||||
|
||||
|
||||
test.skip('template filling with 2 sequential {#each}', async t => {
|
||||
test('template filling with 2 sequential {#each}', async t => {
|
||||
const templatePath = join(import.meta.dirname, '../fixtures/liste-fruits-et-légumes.odt')
|
||||
const templateContent = `Liste de fruits et légumes
|
||||
|
||||
@ -164,7 +162,7 @@ Poivron 🫑
|
||||
});
|
||||
|
||||
|
||||
test.skip('template filling with nested {#each}s', async t => {
|
||||
test('template filling with nested {#each}s', async t => {
|
||||
const templatePath = join(import.meta.dirname, '../fixtures/légumes-de-saison.odt')
|
||||
const templateContent = `Légumes de saison
|
||||
|
||||
@ -249,7 +247,7 @@ Hiver
|
||||
});
|
||||
|
||||
|
||||
test.skip('template filling {#each ...}{/each} within a single text node', async t => {
|
||||
test('template filling {#each ...}{/each} within a single text node', async t => {
|
||||
const templatePath = join(import.meta.dirname, '../fixtures/liste-nombres.odt')
|
||||
const templateContent = `Liste de nombres
|
||||
|
||||
@ -276,7 +274,7 @@ Les nombres : 1 1 2 3 5 8 13 21 !!
|
||||
});
|
||||
|
||||
|
||||
test.skip('template filling of a table', async t => {
|
||||
test('template filling of a table', async t => {
|
||||
const templatePath = join(import.meta.dirname, '../fixtures/tableau-simple.odt')
|
||||
const templateContent = `Évolution énergie en kWh par personne en France
|
||||
|
||||
|
||||
@ -4,10 +4,9 @@ import {join} from 'node:path';
|
||||
import {getOdtTemplate} from '../../scripts/odf/odtTemplate-forNode.js'
|
||||
|
||||
import {fillOdtTemplate, getOdtTextContent} from '../../exports.js'
|
||||
import { listZipEntries } from '../helpers/zip-analysis.js';
|
||||
|
||||
|
||||
test.skip('basic template filling with {#if}', async t => {
|
||||
test('basic template filling with {#if}', async t => {
|
||||
const templatePath = join(import.meta.dirname, '../fixtures/description-nombre.odt')
|
||||
const templateContent = `Description du nombre {n}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ import {join} from 'node:path';
|
||||
|
||||
import {getOdtTemplate} from '../../scripts/odf/odtTemplate-forNode.js'
|
||||
|
||||
import {fillOdtTemplate, getOdtTextContent} from '../../exports.js'
|
||||
import {fillOdtTemplate} from '../../exports.js'
|
||||
import { listZipEntries } from '../helpers/zip-analysis.js';
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user