Comparing version 0.5.3 to 0.5.4
@@ -133,3 +133,41 @@ var sys = require('sys'), | ||
/** | ||
* Clears all of the cache or a specific template. | ||
* | ||
* @param templateName String If provided only that template is removed from | ||
* the cache, else everything is. | ||
*/ | ||
mu.clearCache = function (templateName) { | ||
if (name) { | ||
delete mu.cache[templateName]; | ||
} else { | ||
mu.cache = {}; | ||
} | ||
}; | ||
/** | ||
* Compiles the template and then renders it. Uses the cache if it | ||
* is available. | ||
* | ||
* @param templateName String The name of the template to render | ||
* @param view Object The view object to inject into the template upon render | ||
* @returns Stream THe output stream | ||
*/ | ||
mu.compileAndRender = function (templateName, view) { | ||
var stream = new Stream(); | ||
var parsed = mu.cache[templateName]; | ||
if (parsed) { | ||
beginRenderWithStream(parsed[0].tokens, view, mu.cache, stream); | ||
} else { | ||
mu.compile(templateName, function (err, parsed) { | ||
if (err) return stream.emit('error', err); | ||
beginRenderWithStream(parsed[0].tokens, view, mu.cache, stream); | ||
}); | ||
} | ||
return stream; | ||
}; | ||
/// Private API | ||
@@ -139,4 +177,10 @@ | ||
function beginRender(tokens, view, partials) { | ||
var stream = new Stream(); | ||
beginRenderWithStream(tokens, view, partials, stream); | ||
return stream; | ||
} | ||
function beginRenderWithStream(tokens, view, partials, stream) { | ||
var count = 0; | ||
@@ -153,4 +197,2 @@ | ||
}); | ||
return stream; | ||
} | ||
@@ -157,0 +199,0 @@ |
{ "name": "mu2" | ||
, "description": "A Mustache template engine for Node.js" | ||
, "keywords": ["template", "mustache"] | ||
, "version" : "0.5.3" | ||
, "version" : "0.5.4" | ||
, "homepage": "http://github.com/raycmorgan/mu" | ||
, "author" : "RayMorgan <ray@simple-apps.com>" | ||
, "author" : "RayMorgan <ray@rumgr.com>" | ||
, "main" : "lib/mu" | ||
} |
@@ -25,3 +25,17 @@ var assert = require('assert'), | ||
].forEach(function (name) { | ||
var js = fs.readFileSync(path.join(mu.root, name + '.js')).toString(), | ||
text = fs.readFileSync(path.join(mu.root, name + '.txt')).toString(); | ||
js = eval('(' + js + ')'); | ||
var buffer = ''; | ||
mu.compileAndRender(name + '.html', js) | ||
.on('data', function (c) { buffer += c.toString(); }) | ||
.on('end', function () { | ||
assert.equal(buffer, text); | ||
console.log(name + ' passed'); | ||
}) | ||
/* | ||
var js = fs.readFileSync(path.join(mu.root, name + '.js')).toString(), | ||
@@ -49,2 +63,3 @@ text = fs.readFileSync(path.join(mu.root, name + '.txt')).toString(); | ||
}); | ||
*/ | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
23264
721
0
4