mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Marko v3: Added methods for resolving templates and paths
This commit is contained in:
parent
7fd574deb4
commit
87ed39139b
@ -617,6 +617,14 @@ class Generator {
|
||||
onDone(listenerFunc) {
|
||||
this._doneListeners.push(listenerFunc);
|
||||
}
|
||||
|
||||
getRequirePath(targetFilename) {
|
||||
return this.context.getRequirePath(targetFilename);
|
||||
}
|
||||
|
||||
resolvePath(pathExpression) {
|
||||
return this.context.resolvePath(pathExpression);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Generator;
|
||||
@ -375,6 +375,34 @@ class CompileContext {
|
||||
createWalker(options) {
|
||||
return new Walker(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Statically resolves a path if it is a literal string. Otherwise, it returns the input expression.
|
||||
*/
|
||||
resolvePath(pathExpression) {
|
||||
ok(pathExpression, '"pathExpression" is required');
|
||||
|
||||
if (pathExpression.type === 'Literal') {
|
||||
let path = pathExpression.value;
|
||||
if (typeof path === 'string') {
|
||||
return this.addStaticVar(path, this.builder.requireResolve(pathExpression));
|
||||
}
|
||||
}
|
||||
return pathExpression;
|
||||
}
|
||||
|
||||
resolveTemplate(pathExpression) {
|
||||
ok(pathExpression, '"pathExpression" is required');
|
||||
|
||||
if (pathExpression.type === 'Literal') {
|
||||
let path = pathExpression.value;
|
||||
if (typeof path === 'string') {
|
||||
return this.importTemplate(path);
|
||||
}
|
||||
}
|
||||
|
||||
return pathExpression;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CompileContext;
|
||||
Loading…
x
Reference in New Issue
Block a user