Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/TemplateMarkInterpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ async function generateAgreement(modelManager: ModelManager, clauseLibrary: obje
// traverse the templatemark, creating an output agreementmark tree
return traverse(templateMark).map(function (context: any) {
let stopHere = false;
let removeNode = false;

if (typeof context === 'object' && context.$class && typeof context.$class === 'string') {
const nodeClass = context.$class as string;

Expand Down Expand Up @@ -444,7 +446,7 @@ async function generateAgreement(modelManager: ModelManager, clauseLibrary: obje
const path = getJsonPath(templateMark, context, this.path);
const variableValues = jp.query(data, path, 1);
if (variableValues.length === 0) {
throw new Error(`No values found for path '${path}' in data ${JSON.stringify(data)}.`);
context.value = 'null'; // Fallback to 'null' string to prevent crash
}
else {
// convert the value to a string, optionally using the formatter
Expand Down Expand Up @@ -487,7 +489,7 @@ async function generateAgreement(modelManager: ModelManager, clauseLibrary: obje
context.isTrue = false;
}
}
context.nodes = context.isTrue ? context.whenTrue : context.whenFalse;
context.nodes = context.isTrue ? context.whenTrue : (context.whenFalse || []);
delete context.condition;
delete context.dependencies;
delete context.functionName;
Expand All @@ -499,13 +501,13 @@ async function generateAgreement(modelManager: ModelManager, clauseLibrary: obje
const path = getJsonPath(templateMark, context, this.path);
const variableValues = jp.query(data, path, 1);
if (variableValues.length === 0 || variableValues[0] === undefined || variableValues[0] === null) {
delete context.nodes;
removeNode = true;
stopHere = true;
} else if (context.condition) {
checkCode(context.condition);
const result = !!userCodeResults[this.path.join('/')] as unknown as boolean;
if (!result) {
delete context.nodes;
removeNode = true;
stopHere = true;
}
}
Expand Down Expand Up @@ -538,11 +540,16 @@ async function generateAgreement(modelManager: ModelManager, clauseLibrary: obje
else {
context.hasSome = false;
context.whenSome = [];
context.nodes = context.whenNone;
context.nodes = context.whenNone || [];
}
}
}
this.update(context, stopHere);

if (removeNode) {
this.remove();
} else {
this.update(context, stopHere);
}
});
}

Expand Down Expand Up @@ -650,4 +657,4 @@ export class TemplateMarkInterpreter {
// console.log('Generated AgreementMark');
return this.validateCiceroMark(ciceroMark);
}
}
}
10 changes: 1 addition & 9 deletions test/__snapshots__/TemplateArchiveProcessor.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`template archive processor should draft a template 1`] = `
"Late Delivery and Penalty
----

In case of delayed delivery except for Force Majeure cases, the Seller shall pay to the Buyer for every {"$class":"org.accordproject.time@0.3.0.Duration","amount":2,"unit":"days"} of delay penalty amounting to 10.5% of the total value of the Equipment whose delivery has been delayed.
1. Any fractional part of a days is to be considered a full days.
2. The total amount of penalty shall not however, exceed 55.0% of the total value of the Equipment involved in late delivery.
3. If the delay is more than {"$class":"org.accordproject.time@0.3.0.Duration","amount":15,"unit":"days"}, the Buyer is entitled to terminate this Contract."
`;
exports[`template archive processor should draft a template 1`] = `""`;
28 changes: 23 additions & 5 deletions test/__snapshots__/TemplateMarkInterpreter.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,31 @@ exports[`templatemark interpreter should generate clause-optional 1`] = `
"$class": "org.accordproject.ciceromark@0.6.0.Clause",
"elementType": "test@1.0.0.Address",
"name": "address",
},
{
"$class": "org.accordproject.commonmark@0.5.0.Paragraph",
"nodes": [
{
"$class": "org.accordproject.commonmark@0.5.0.Text",
"text": "No more content.",
"$class": "org.accordproject.commonmark@0.5.0.Paragraph",
"nodes": [
{
"$class": "org.accordproject.commonmark@0.5.0.Text",
"text": "Address: ",
},
{
"$class": "org.accordproject.ciceromark@0.6.0.Variable",
"elementType": "String",
"name": "street",
"value": "null",
},
{
"$class": "org.accordproject.commonmark@0.5.0.Text",
"text": ", ",
},
{
"$class": "org.accordproject.ciceromark@0.6.0.Variable",
"elementType": "String",
"name": "city",
"value": "null",
},
],
},
],
},
Expand Down