Skip to content

Commit

Permalink
fix(util) pass template concept
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Selman <danscode@selman.org>
  • Loading branch information
dselman committed Jun 6, 2023
1 parent 5deb491 commit a2cab30
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
12 changes: 7 additions & 5 deletions packages/markdown-template/src/TemplateMarkTransformer.js
Expand Up @@ -43,15 +43,16 @@ class TemplateMarkTransformer {
* @param {string} templateKind - either 'clause' or 'contract'
* @param {object} [options] configuration options
* @param {boolean} [options.verbose] verbose output
* @returns {object} the result of parsing
* @param {string} [conceptFullyQualifiedName] - the fully qualified name of the template concept
* @returns {object} the result of parsing
*/
tokensToMarkdownTemplate(tokenStream, modelManager, templateKind, options) {
tokensToMarkdownTemplate(tokenStream, modelManager, templateKind, options, conceptFullyQualifiedName) {
const template = tokensToUntypedTemplateMark(tokenStream, templateKind);
if (options && options.verbose) {
console.log('===== Untyped TemplateMark ');

Check warning on line 52 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 52 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 52 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement

Check warning on line 52 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 52 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 52 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 52 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 52 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement
console.log(JSON.stringify(template,null,2));

Check warning on line 53 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 53 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 53 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement

Check warning on line 53 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 53 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 53 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 53 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 53 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement
}
const typedTemplate = templateMarkTyping(template, modelManager, templateKind);
const typedTemplate = templateMarkTyping(template, modelManager, templateKind, conceptFullyQualifiedName);
if (options && options.verbose) {
console.log('===== TemplateMark ');

Check warning on line 57 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 57 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 57 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement

Check warning on line 57 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 57 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 57 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 57 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 57 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement
console.log(JSON.stringify(typedTemplate,null,2));

Check warning on line 58 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 58 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 58 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement

Check warning on line 58 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 58 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 58 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 58 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 58 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement
Expand All @@ -66,9 +67,10 @@ class TemplateMarkTransformer {
* @param {string} templateKind - either 'clause' or 'contract'
* @param {object} [options] configuration options
* @param {boolean} [options.verbose] verbose output
* @param {string} [conceptFullyQualifiedName] - the fully qualified name of the template concept
* @returns {object} the result of parsing
*/
fromMarkdownTemplate(templateInput, modelManager, templateKind, options) {
fromMarkdownTemplate(templateInput, modelManager, templateKind, options, conceptFullyQualifiedName) {
if (!modelManager) {
throw new Error('Cannot parse without template model');
}
Expand All @@ -78,7 +80,7 @@ class TemplateMarkTransformer {
console.log('===== MarkdownIt Tokens ');

Check warning on line 80 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 80 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 80 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement

Check warning on line 80 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 80 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 80 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 80 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 80 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement
console.log(JSON.stringify(tokenStream,null,2));

Check warning on line 81 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 81 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 81 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement

Check warning on line 81 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 81 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Unexpected console statement

Check warning on line 81 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Unexpected console statement

Check warning on line 81 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, macOS-latest)

Unexpected console statement

Check warning on line 81 in packages/markdown-template/src/TemplateMarkTransformer.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, macOS-latest)

Unexpected console statement
}
return this.tokensToMarkdownTemplate(tokenStream, modelManager, templateKind, options);
return this.tokensToMarkdownTemplate(tokenStream, modelManager, templateKind, options, conceptFullyQualifiedName);
}

/**
Expand Down
8 changes: 5 additions & 3 deletions packages/markdown-template/src/templatemarkutil.js
Expand Up @@ -56,11 +56,12 @@ const templateMarkManager = mkTemplateMarkManager();
/**
* Returns the concept for the template
* @param {object} introspector - the model introspector for this template
* @param {string} templateKind - either 'clause' or 'contract'
* @param {string} [conceptFullyQualifiedName] - the fully qualified name of the template concept
* @throws {Error} if no template model is found, or multiple template models are found
* @returns {ClassDeclaration} the concept for the template
*/
function findTemplateConcept(introspector, conceptFullyQualifiedName) {
function findTemplateConcept(introspector, templateKind, conceptFullyQualifiedName) {
if(conceptFullyQualifiedName) {
return introspector.getClassDeclaration();
}
Expand Down Expand Up @@ -123,11 +124,12 @@ function templateMarkTypingGen(template,introspector,model,templateKind,options)
* @param {object} template the TemplateMark DOM
* @param {object} modelManager - the modelManager for this template
* @param {string} templateKind - either 'clause' or 'contract'
* @param {string} [conceptFullyQualifiedName] - the fully qualified name of the template concept
* @returns {object} the typed TemplateMark DOM
*/
function templateMarkTyping(template,modelManager,templateKind) {
function templateMarkTyping(template,modelManager,templateKind,conceptFullyQualifiedName) {
const introspector = new Introspector(modelManager);
const model = findTemplateConcept(introspector, templateKind);
const model = findTemplateConcept(introspector, templateKind,conceptFullyQualifiedName);
return templateMarkTypingGen(template,introspector,model,templateKind);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/markdown-transform/src/builtinTransforms.js
Expand Up @@ -39,7 +39,7 @@ const transformationGraph = {
templatemark: async (input, parameters, options) => {
const t = new TemplateMarkTransformer();
const modelManager = await ModelLoader.loadModelManager(parameters.model, options);
return t.tokensToMarkdownTemplate(input, modelManager, parameters.templateKind, options);
return t.tokensToMarkdownTemplate(input, modelManager, parameters.templateKind, options, parameters.conceptFullyQualifiedName);
},
},
templatemark: {
Expand Down

0 comments on commit a2cab30

Please sign in to comment.