Comparing version 0.5.6 to 0.5.7
@@ -9,9 +9,13 @@ var BUFFER_LENGTH = 1024 * 8; | ||
function render(tokens, context, partials, stream, callback) { | ||
if (!Array.isArray(context)) { | ||
context = [context]; | ||
} | ||
return _render(tokens, context, partials, stream, callback); | ||
} | ||
function _render(tokens, context, partials, stream, callback) { | ||
if (tokens[0] !== 'multi') { | ||
throw new Error('Mu - WTF did you give me? I expected mustache tokens.'); | ||
} | ||
//if (!Array.isArray(context)) { | ||
// context = [context]; | ||
//} | ||
@@ -97,6 +101,6 @@ var i = 1; | ||
function normalize(context, name, body) { | ||
var val = context[name]; | ||
var val = walkToFind(context, name); | ||
if (typeof(val) === 'function') { | ||
val = context[name](body); | ||
val = val.call(smashContext(context), body); | ||
} | ||
@@ -107,9 +111,30 @@ | ||
function section(view, name, val, tokens, partials, stream, callback) { | ||
// var val = normalize(view, name, body); | ||
// if (typeof val === 'boolean') { | ||
// return val ? render(tokens, view, partials, stream, callback) : callback(); | ||
// } | ||
function walkToFind(context, name) { | ||
var i = context.length; | ||
while (i--) { | ||
if (name in context[i]) { | ||
return context[i][name]; | ||
} | ||
} | ||
return undefined; | ||
} | ||
// TODO: if Proxy, make more efficient | ||
// TODO: cache? | ||
function smashContext(context) { | ||
var obj = {}; | ||
for (var i = 0; i < context.length; i++) { | ||
var level = context[i]; | ||
for (var k in level) { | ||
obj[k] = level[k]; | ||
} | ||
} | ||
return obj; | ||
} | ||
function section(context, name, val, tokens, partials, stream, callback) { | ||
if (val instanceof Array) { | ||
@@ -122,9 +147,7 @@ var i = 0; | ||
if (item) { | ||
//view.push(item); | ||
var proto = insertProto(item, view); | ||
render(tokens, item, partials, stream, function () { | ||
proto.__proto__ = baseProto; | ||
context.push(item); | ||
_render(tokens, context, partials, stream, function () { | ||
context.pop(); | ||
next(); | ||
}); | ||
//view.pop(); | ||
} else { | ||
@@ -140,7 +163,5 @@ callback(); | ||
if (typeof val === 'object') { | ||
//view.push(val); | ||
var proto = insertProto(val, view); | ||
render(tokens, val, partials, stream, callback); | ||
proto.__proto__ = baseProto; | ||
//view.pop(); | ||
context.push(val); | ||
_render(tokens, context, partials, stream, callback); | ||
context.pop(); | ||
return; | ||
@@ -150,3 +171,3 @@ } | ||
if (val) { | ||
return render(tokens, view, partials, stream, callback); | ||
return _render(tokens, context, partials, stream, callback); | ||
} | ||
@@ -153,0 +174,0 @@ |
{ "name": "mu2" | ||
, "description": "A Mustache template engine for Node.js" | ||
, "keywords": ["template", "mustache"] | ||
, "version" : "0.5.6" | ||
, "version" : "0.5.7" | ||
, "homepage": "http://github.com/raycmorgan/mu" | ||
@@ -6,0 +6,0 @@ , "author" : "RayMorgan <ray@rumgr.com>" |
@@ -9,6 +9,6 @@ var assert = require('assert'), | ||
[ | ||
'boolean', | ||
'comments', | ||
'complex', | ||
'deep_partial', | ||
'boolean', | ||
'comments', | ||
'complex', | ||
'deep_partial', | ||
// 'delimiters', | ||
@@ -23,2 +23,3 @@ 'error_not_found', | ||
'simple', | ||
'twice', | ||
'two_in_a_row', | ||
@@ -33,9 +34,10 @@ 'unescaped', | ||
var buffer = ''; | ||
mu.compileAndRender(name + '.html', js) | ||
.on('data', function (c) { buffer += c.toString(); }) | ||
.on('end', function () { | ||
console.log("Testing: " + name); | ||
assert.equal(buffer, text); | ||
console.log(name + ' passed'); | ||
}) | ||
console.log(name + ' passed\n'); | ||
}); | ||
@@ -42,0 +44,0 @@ /* |
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
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
23708
60
744