mirror of
https://github.com/marko-js/marko.git
synced 2026-01-18 14:55:13 +00:00
25 lines
833 B
JavaScript
25 lines
833 B
JavaScript
var nodePath = require('path');
|
|
var fs = require('fs');
|
|
var Module = require('module').Module;
|
|
var compiler = require('../../compiler');
|
|
|
|
function loadSource(templatePath, compiledSrc) {
|
|
var templateModulePath = templatePath + '.js';
|
|
var templateModule = new Module(templateModulePath, module);
|
|
templateModule.paths = Module._nodeModulePaths(nodePath.dirname(templateModulePath));
|
|
templateModule.filename = templateModulePath;
|
|
|
|
templateModule._compile(
|
|
compiledSrc,
|
|
templateModulePath);
|
|
|
|
return templateModule.exports;
|
|
}
|
|
|
|
module.exports = function load(templatePath) {
|
|
var templateSrc = fs.readFileSync(templatePath, {encoding: 'utf8'});
|
|
var compiledSrc = compiler.compile(templateSrc, templatePath);
|
|
return loadSource(templatePath, compiledSrc);
|
|
};
|
|
|
|
module.exports.loadSource = loadSource; |