Allow *.html extension for layouts

Fix for https://github.com/raptorjs/marko-layout/issues/2
This commit is contained in:
Patrick Steele-Idem 2015-07-22 10:04:40 -06:00
parent 11190d3db6
commit b475f15dc3
2 changed files with 12 additions and 5 deletions

View File

@ -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

View File

@ -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 {