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
|
// @ts-ignore
|
||||||
traverse(rootElement, currentNode => {
|
traverse(rootElement, currentNode => {
|
||||||
const insideAnEachBlock = !!eachBlockOpeningNode
|
//console.log('currentlyUnclosedBlocks', currentlyUnclosedBlocks)
|
||||||
|
const insideAnOpenBlock = currentlyUnclosedBlocks.length >= 1
|
||||||
|
|
||||||
if(currentNode.nodeType === Node.TEXT_NODE){
|
if(currentNode.nodeType === Node.TEXT_NODE){
|
||||||
const text = currentNode.textContent || ''
|
const text = currentNode.textContent || ''
|
||||||
@ -303,9 +304,15 @@ function fillTemplatedOdtElement(rootElement, compartment){
|
|||||||
const eachStartRegex = /{#each\s+([^}]+?)\s+as\s+([^}]+?)\s*}/;
|
const eachStartRegex = /{#each\s+([^}]+?)\s+as\s+([^}]+?)\s*}/;
|
||||||
const startMatch = text.match(eachStartRegex);
|
const startMatch = text.match(eachStartRegex);
|
||||||
|
|
||||||
|
//console.log('text, match', )
|
||||||
|
|
||||||
if(startMatch){
|
if(startMatch){
|
||||||
if(insideAnEachBlock){
|
//console.log('startMatch', startMatch)
|
||||||
currentlyUnclosedBlocks.push(EACH)
|
|
||||||
|
currentlyUnclosedBlocks.push(EACH)
|
||||||
|
|
||||||
|
if(insideAnOpenBlock){
|
||||||
|
// do nothing
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
let [_, _iterableExpression, _itemExpression] = startMatch
|
let [_, _iterableExpression, _itemExpression] = startMatch
|
||||||
@ -320,16 +327,18 @@ function fillTemplatedOdtElement(rootElement, compartment){
|
|||||||
const eachClosingBlockString = '{/each}'
|
const eachClosingBlockString = '{/each}'
|
||||||
const isEachClosingBlock = text.includes(eachClosingBlockString)
|
const isEachClosingBlock = text.includes(eachClosingBlockString)
|
||||||
|
|
||||||
if(isEachClosingBlock){
|
if(isEachClosingBlock){
|
||||||
|
|
||||||
|
//console.log('isEachClosingBlock', isEachClosingBlock)
|
||||||
|
|
||||||
if(!eachBlockOpeningNode)
|
if(!eachBlockOpeningNode)
|
||||||
throw new Error(`{/each} found without corresponding opening {#each x as y}`)
|
throw new Error(`{/each} found without corresponding opening {#each x as y}`)
|
||||||
|
|
||||||
if(currentlyUnclosedBlocks.at(-1) !== EACH)
|
if(currentlyUnclosedBlocks.at(-1) !== EACH)
|
||||||
throw new Error(`{/each} found while the last opened block was not an opening {#each x as y}`)
|
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}
|
// ignore because it will be treated as part of the outer {#each}
|
||||||
currentlyUnclosedBlocks.pop()
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
eachBlockClosingNode = currentNode
|
eachBlockClosingNode = currentNode
|
||||||
@ -343,11 +352,13 @@ function fillTemplatedOdtElement(rootElement, compartment){
|
|||||||
eachBlockItemExpression = undefined
|
eachBlockItemExpression = undefined
|
||||||
eachBlockClosingNode = undefined
|
eachBlockClosingNode = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentlyUnclosedBlocks.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Looking for variables for substitutions
|
// Looking for variables for substitutions
|
||||||
if(!insideAnEachBlock){
|
if(!insideAnOpenBlock){
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (currentNode.data) {
|
if (currentNode.data) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@ -369,7 +380,7 @@ function fillTemplatedOdtElement(rootElement, compartment){
|
|||||||
|
|
||||||
if(currentNode.nodeType === Node.ATTRIBUTE_NODE){
|
if(currentNode.nodeType === Node.ATTRIBUTE_NODE){
|
||||||
// Looking for variables for substitutions
|
// Looking for variables for substitutions
|
||||||
if(!insideAnEachBlock){
|
if(!insideAnOpenBlock){
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (currentNode.value) {
|
if (currentNode.value) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import {join} from 'node:path';
|
|||||||
import {getOdtTemplate} from '../../scripts/odf/odtTemplate-forNode.js'
|
import {getOdtTemplate} from '../../scripts/odf/odtTemplate-forNode.js'
|
||||||
|
|
||||||
import {fillOdtTemplate, getOdtTextContent} from '../../exports.js'
|
import {fillOdtTemplate, getOdtTextContent} from '../../exports.js'
|
||||||
import { listZipEntries } from '../helpers/zip-analysis.js';
|
|
||||||
|
|
||||||
|
|
||||||
test('basic template filling with variable substitution', async t => {
|
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 {getOdtTemplate} from '../../scripts/odf/odtTemplate-forNode.js'
|
||||||
|
|
||||||
import {fillOdtTemplate, getOdtTextContent} from '../../exports.js'
|
import {fillOdtTemplate, getOdtTextContent} from '../../exports.js'
|
||||||
import { listZipEntries } from '../helpers/zip-analysis.js';
|
|
||||||
|
|
||||||
|
|
||||||
|
test('basic template filling with {#each}', async t => {
|
||||||
test.skip('basic template filling with {#each}', async t => {
|
|
||||||
const templatePath = join(import.meta.dirname, '../fixtures/enum-courses.odt')
|
const templatePath = join(import.meta.dirname, '../fixtures/enum-courses.odt')
|
||||||
const templateContent = `🧺 La liste de courses incroyable 🧺
|
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 templatePath = join(import.meta.dirname, '../fixtures/enum-courses.odt')
|
||||||
const templateContent = `🧺 La liste de courses incroyable 🧺
|
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 templatePath = join(import.meta.dirname, '../fixtures/liste-courses.odt')
|
||||||
const templateContent = `🧺 La liste de courses incroyable 🧺
|
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 templatePath = join(import.meta.dirname, '../fixtures/liste-fruits-et-légumes.odt')
|
||||||
const templateContent = `Liste de fruits et légumes
|
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 templatePath = join(import.meta.dirname, '../fixtures/légumes-de-saison.odt')
|
||||||
const templateContent = `Légumes de saison
|
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 templatePath = join(import.meta.dirname, '../fixtures/liste-nombres.odt')
|
||||||
const templateContent = `Liste de nombres
|
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 templatePath = join(import.meta.dirname, '../fixtures/tableau-simple.odt')
|
||||||
const templateContent = `Évolution énergie en kWh par personne en France
|
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 {getOdtTemplate} from '../../scripts/odf/odtTemplate-forNode.js'
|
||||||
|
|
||||||
import {fillOdtTemplate, getOdtTextContent} from '../../exports.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 templatePath = join(import.meta.dirname, '../fixtures/description-nombre.odt')
|
||||||
const templateContent = `Description du nombre {n}
|
const templateContent = `Description du nombre {n}
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import {join} from 'node:path';
|
|||||||
|
|
||||||
import {getOdtTemplate} from '../../scripts/odf/odtTemplate-forNode.js'
|
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';
|
import { listZipEntries } from '../helpers/zip-analysis.js';
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user