Skip to content

Commit

Permalink
feature(decorators) Add concerto metamodel + decorators for CiceroMar…
Browse files Browse the repository at this point in the history
…k/TemplateMark/Slate

Signed-off-by: Jerome Simeon <[email protected]>
  • Loading branch information
jeromesimeon committed Sep 15, 2020
1 parent 4975fc6 commit 841277a
Show file tree
Hide file tree
Showing 20 changed files with 6,616 additions and 13,915 deletions.
19,167 changes: 5,277 additions & 13,890 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/markdown-cicero/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @module markdown-transform
*/

module.exports.ConcertoMetaModel = require('./lib/externalModels/ConcertoMetaModel');
module.exports.CiceroMarkModel = require('./lib/externalModels/CiceroMarkModel');

module.exports.CiceroMarkTransformer = require('./lib/CiceroMarkTransformer');
Expand Down
2 changes: 2 additions & 0 deletions packages/markdown-cicero/lib/CiceroMarkTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const { CommonMarkModel } = require('@accordproject/markdown-common').CommonMark
const FromCiceroEditVisitor = require('./FromCiceroEditVisitor');
const ToCommonMarkVisitor = require('./ToCommonMarkVisitor');
const { CiceroMarkModel } = require('./externalModels/CiceroMarkModel');
const { ConcertoMetaModel } = require('./externalModels/ConcertoMetaModel');
const unquoteVariables = require('./UnquoteVariables');

/**
Expand All @@ -47,6 +48,7 @@ class CiceroMarkTransformer {

// Setup for validation
this.modelManager = new ModelManager();
this.modelManager.addModelFile(ConcertoMetaModel, 'metamodel.cto');
this.modelManager.addModelFile(CommonMarkModel, 'commonmark.cto');
this.modelManager.addModelFile(CiceroMarkModel, 'ciceromark.cto');
const factory = new Factory(this.modelManager);
Expand Down
2 changes: 2 additions & 0 deletions packages/markdown-cicero/lib/ToCiceroMarkUnwrappedVisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class ToCiceroMarkUnwrappedVisitor {

delete thing.name;
delete thing.elementType;
delete thing.decorators;
}
break;
case 'Variable':
Expand All @@ -78,6 +79,7 @@ class ToCiceroMarkUnwrappedVisitor {
thing.text = decodeURIComponent(thing.value);

delete thing.elementType;
delete thing.decorators;
delete thing.name;
delete thing.value;
delete thing.format;
Expand Down
2 changes: 1 addition & 1 deletion packages/markdown-slate/lib/SlateTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class SlateTransformer {
* @returns {*} Slate JSON
*/
fromCiceroMark(input) {

if(!input.getType) {
input = this.serializer.fromJSON(input);
}

const CLAUSE = 'clause';
const parameters = {};
parameters.serializer = this.serializer;
parameters.result = {};
const visitor = new ToSlateVisitor();
input.accept( visitor, parameters );
Expand Down
22 changes: 22 additions & 0 deletions packages/markdown-slate/lib/ToSlateVisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class ToSlateVisitor {
nodes.forEach(node => {
//console.log(`Processing ${thing.getType()} > ${node.getType()}`);
const newParameters = {
serializer: parameters.serializer,
strong: parameters.strong,
emph: parameters.emph,
};
Expand Down Expand Up @@ -238,6 +239,9 @@ class ToSlateVisitor {
if (thing.elementType) {
data.elementType = thing.elementType;
}
if (thing.decorators) {
data.decorators = thing.decorators.map(x => parameters.serializer.toJSON(x));
}
result = {
object: 'block',
type: 'clause',
Expand All @@ -251,6 +255,9 @@ class ToSlateVisitor {
if (thing.elementType) {
data.elementType = thing.elementType;
}
if (thing.decorators) {
data.decorators = thing.decorators.map(x => parameters.serializer.toJSON(x));
}
if (thing.identifiedBy) {
data.identifiedBy = thing.identifiedBy;
}
Expand All @@ -262,6 +269,9 @@ class ToSlateVisitor {
if (thing.elementType) {
data.elementType = thing.elementType;
}
if (thing.decorators) {
data.decorators = thing.decorators.map(x => parameters.serializer.toJSON(x));
}
result = ToSlateVisitor.handleVariable('variable', data, thing.value, parameters);
}
break;
Expand All @@ -270,6 +280,9 @@ class ToSlateVisitor {
if (thing.elementType) {
data.elementType = thing.elementType;
}
if (thing.decorators) {
data.decorators = thing.decorators.map(x => parameters.serializer.toJSON(x));
}
result = ToSlateVisitor.handleVariable('variable', data, thing.value, parameters);
}
break;
Expand All @@ -284,6 +297,9 @@ class ToSlateVisitor {
if (thing.elementType) {
data.elementType = thing.elementType;
}
if (thing.decorators) {
data.decorators = thing.decorators.map(x => parameters.serializer.toJSON(x));
}
result = ToSlateVisitor.handleConditionalVariable(data, nodes, localParameters);
}
break;
Expand All @@ -298,6 +314,9 @@ class ToSlateVisitor {
if (thing.elementType) {
data.elementType = thing.elementType;
}
if (thing.decorators) {
data.decorators = thing.decorators.map(x => parameters.serializer.toJSON(x));
}
result = ToSlateVisitor.handleOptionalVariable(data, nodes, localParameters);
}
break;
Expand Down Expand Up @@ -477,6 +496,9 @@ class ToSlateVisitor {
if (thing.elementType) {
data.elementType = thing.elementType;
}
if (thing.decorators) {
data.decorators = thing.decorators.map(x => parameters.serializer.toJSON(x));
}
result = {
object: 'block',
data: data,
Expand Down
Loading

0 comments on commit 841277a

Please sign in to comment.