mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Fixes #96 - Allow dynamic relative paths
This commit is contained in:
parent
12204aba75
commit
6de11ddc9f
@ -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 {
|
||||
|
||||
@ -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
|
||||
|
||||
1
test/fixtures/templates/include-dynamic-relative/expected.html
vendored
Normal file
1
test/fixtures/templates/include-dynamic-relative/expected.html
vendored
Normal file
@ -0,0 +1 @@
|
||||
Hello Frank! You have 20 new messages.
|
||||
4
test/fixtures/templates/include-dynamic-relative/include-target.marko
vendored
Normal file
4
test/fixtures/templates/include-dynamic-relative/include-target.marko
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
<var name="name" value="data.name"/>
|
||||
<var name="count" value="data.count"/>
|
||||
|
||||
Hello $name! You have $count new messages.
|
||||
2
test/fixtures/templates/include-dynamic-relative/template.marko
vendored
Normal file
2
test/fixtures/templates/include-dynamic-relative/template.marko
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
<var name="includePath" value="'./include-target.marko'"/>
|
||||
<include template="${includePath}" name="${'Frank'}" count="20"/>
|
||||
1
test/fixtures/templates/include-dynamic-relative/test.js
vendored
Normal file
1
test/fixtures/templates/include-dynamic-relative/test.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
exports.templateData = {};
|
||||
Loading…
x
Reference in New Issue
Block a user