Fixes #96 - Allow dynamic relative paths

This commit is contained in:
Patrick Steele-Idem 2015-07-06 10:08:21 -06:00
parent 12204aba75
commit 6de11ddc9f
6 changed files with 15 additions and 1 deletions

View File

@ -117,8 +117,13 @@ module.exports = {
/**
* Loads a template
*/
l: function(path) {
l: function(path, req) {
if (typeof path === 'string') {
if (path.charAt(0) === '.') { // Check if the path is relative
// The path is relative so use require.resolve to fully resolve the path
path = req.resolve(path);
}
if (markoRegExp.test(path)) {
return runtime.load(path);
} else {

View File

@ -398,6 +398,7 @@ module.exports = function transform(node, compiler, template) {
attr,
'string',
attrDef) +
', require' + // Include the "require" variable to allow relative paths to be resolved
')');
} else {
// Resolve the static string to a full path only once

View File

@ -0,0 +1 @@
Hello Frank! You have 20 new messages.

View File

@ -0,0 +1,4 @@
<var name="name" value="data.name"/>
<var name="count" value="data.count"/>
Hello $name! You have $count new messages.

View File

@ -0,0 +1,2 @@
<var name="includePath" value="'./include-target.marko'"/>
<include template="${includePath}" name="${'Frank'}" count="20"/>

View File

@ -0,0 +1 @@
exports.templateData = {};