Simplified checkUpToDate() and added getLastModified()

This commit is contained in:
Patrick Steele-Idem 2014-09-12 17:02:01 -06:00
parent 2843f29c81
commit e49d0f31cb
3 changed files with 49 additions and 14 deletions

View File

@ -30,6 +30,7 @@ var ElementNode = require('./ElementNode');
var TextNode = require('./TextNode');
var TagHandlerNode = require('../taglibs/core/TagHandlerNode');
var raptorModulesResolver = require('raptor-modules/resolver');
var fs = require('fs');
function TemplateCompiler(path, options) {
this.dirname = nodePath.dirname(path);
@ -239,13 +240,37 @@ TemplateCompiler.prototype = {
return new TextNode(text, escapeXml);
},
checkUpToDate: function(sourceFile, targetFile) {
getLastModified: function() {
var sourceFile = this.path;
var statSource = fs.statSync(sourceFile);
var lastModifiedTime = statSource.mtime.getTime();
var taglibFiles = this.taglibs.getInputFiles();
var len = taglibFiles.length;
for (var i=0; i<len; i++) {
var taglibFileStat;
var taglibFile = taglibFiles[i];
try {
taglibFileStat = fs.statSync(taglibFile);
} catch(e) {
continue;
}
lastModifiedTime = Math.max(lastModifiedTime, taglibFileStat.mtime.getTime());
}
return lastModifiedTime;
},
checkUpToDate: function(targetFile) {
if (this.options.checkUpToDate === false) {
return false;
}
var fs = require('fs');
var sourceFile = this.path;
var statTarget;

View File

@ -84,6 +84,16 @@ extend(exports, {
});
},
getLastModified: function(path, options, callback) {
if (typeof options === 'function') {
callback = options;
options = null;
}
var compiler = this.createCompiler(path, options);
callback(null, compiler.getLastModified());
},
Node: require('./Node'),
ElementNode: require('./ElementNode'),
TextNode: require('./TextNode'),

View File

@ -24,7 +24,7 @@ module.exports = function load(templatePath) {
var targetFile = templatePath + '.js';
var compiler = raptorTemplatesCompiler.createCompiler(templatePath);
var isUpToDate = compiler.checkUpToDate(templatePath, targetFile);
var isUpToDate = compiler.checkUpToDate(targetFile);
if (isUpToDate) {
return require(targetFile);
}