mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Allow *.html extension for layouts
Fix for https://github.com/raptorjs/marko-layout/issues/2
This commit is contained in:
parent
11190d3db6
commit
b475f15dc3
@ -6,10 +6,17 @@ var extend = require('raptor-util/extend');
|
||||
var attr = require('raptor-util/attr');
|
||||
var attrs = require('raptor-util/attrs');
|
||||
var forEach = require('raptor-util/forEach');
|
||||
var markoRegExp = /\.marko(.xml|.html)?$/;
|
||||
var markoRegExp = /.html|\.marko(.xml|.html)?$/;
|
||||
var arrayFromArguments = require('raptor-util/arrayFromArguments');
|
||||
var logger = require('raptor-logging').logger(module);
|
||||
|
||||
var viewEngine;
|
||||
var req = require;
|
||||
|
||||
try {
|
||||
viewEngine = req('view-engine');
|
||||
} catch(e) {}
|
||||
|
||||
function notEmpty(o) {
|
||||
if (o == null) {
|
||||
return false;
|
||||
@ -118,15 +125,15 @@ module.exports = {
|
||||
*/
|
||||
l: function(path, req) {
|
||||
if (typeof path === 'string') {
|
||||
if (path.charAt(0) === '.') { // Check if the path is relative
|
||||
if (path.charAt(0) === '.' && req.resolve) { // 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)) {
|
||||
if (!viewEngine || markoRegExp.test(path)) {
|
||||
return runtime.load(path);
|
||||
} else {
|
||||
return req('view-engine').load(path);
|
||||
return viewEngine.load(path);
|
||||
}
|
||||
} else if (path.render) {
|
||||
// Assume it is already a pre-loaded template
|
||||
|
||||
@ -402,7 +402,7 @@ module.exports = function transform(node, compiler, template) {
|
||||
')');
|
||||
} else {
|
||||
// Resolve the static string to a full path only once
|
||||
templateVar = template.addStaticVar(attr.value, '__loadTemplate(require.resolve(' + compiler.convertType(attr.value, 'string', true) + '))');
|
||||
templateVar = template.addStaticVar(attr.value, '__loadTemplate(require.resolve(' + compiler.convertType(attr.value, 'string', true) + '), require)');
|
||||
value = compiler.makeExpression(templateVar);
|
||||
}
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user