Skip to content

Commit 5deb491

Browse files
committed
feat(util) : allow the concept for a template to be passed explicitly
Signed-off-by: Dan Selman <[email protected]>
1 parent 3e8a3d8 commit 5deb491

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

packages/markdown-template/src/templatemarkutil.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,27 @@ function mkTemplateMarkManager(options) {
5454
const templateMarkManager = mkTemplateMarkManager();
5555

5656
/**
57-
* Returns the template model for the template
57+
* Returns the concept for the template
5858
* @param {object} introspector - the model introspector for this template
59-
* @param {string} templateKind - either 'clause' or 'contract'
59+
* @param {string} [conceptFullyQualifiedName] - the fully qualified name of the template concept
6060
* @throws {Error} if no template model is found, or multiple template models are found
61-
* @returns {ClassDeclaration} the template model for the template
61+
* @returns {ClassDeclaration} the concept for the template
6262
*/
63-
function findTemplateModel(introspector, templateKind) {
64-
const templateModels = introspector.getClassDeclarations().filter((item) => {
65-
return !item.isAbstract() && item.getDecorator('template');
66-
});
67-
68-
if (templateModels.length > 1) {
69-
throw new Error('Found multiple concepts with @template decorator. The model for the template must contain a single concept with the @template decorator.');
70-
} else if (templateModels.length === 0) {
71-
throw new Error('Failed to find a concept with the @template decorator. The model for the template must contain a single concept with the @template decoratpr.');
72-
} else {
73-
return templateModels[0];
63+
function findTemplateConcept(introspector, conceptFullyQualifiedName) {
64+
if(conceptFullyQualifiedName) {
65+
return introspector.getClassDeclaration();
66+
}
67+
else {
68+
const templateModels = introspector.getClassDeclarations().filter((item) => {
69+
return !item.isAbstract() && item.getDecorator('template');
70+
});
71+
if (templateModels.length > 1) {
72+
throw new Error('Found multiple concepts with @template decorator. The model for the template must contain a single concept with the @template decorator.');
73+
} else if (templateModels.length === 0) {
74+
throw new Error('Failed to find a concept with the @template decorator. The model for the template must contain a single concept with the @template decoratpr.');
75+
} else {
76+
return templateModels[0];
77+
}
7478
}
7579
}
7680

@@ -123,7 +127,7 @@ function templateMarkTypingGen(template,introspector,model,templateKind,options)
123127
*/
124128
function templateMarkTyping(template,modelManager,templateKind) {
125129
const introspector = new Introspector(modelManager);
126-
const model = findTemplateModel(introspector, templateKind);
130+
const model = findTemplateConcept(introspector, templateKind);
127131
return templateMarkTypingGen(template,introspector,model,templateKind);
128132
}
129133

@@ -225,7 +229,7 @@ function tokensToUntypedTemplateMarkFragment(tokenStream) {
225229
};
226230
}
227231

228-
module.exports.findTemplateModel = findTemplateModel;
232+
module.exports.findTemplateConcept = findTemplateConcept;
229233
module.exports.templateMarkManager = templateMarkManager;
230234

231235
module.exports.templateToTokens = templateToTokens;

0 commit comments

Comments
 (0)