Skip to content

Commit

Permalink
Allow implicit iteration over the root context element. Fixes twitter…
Browse files Browse the repository at this point in the history
…#154, matches mustache.js behavior.
  • Loading branch information
Mr0grog committed Apr 17, 2015
1 parent 9417a6f commit 57f3e5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ var Hogan = {};
doModelGet = this.options.modelGet,
cx = null;

if (key === '.' && isArray(ctx[ctx.length - 2])) {
if (key === '.' && (ctx.length === 1 || isArray(ctx[ctx.length - 2]))) {
val = ctx[ctx.length - 1];
} else {
for (var i = 1; i < names.length; i++) {
Expand Down
7 changes: 7 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,13 @@ test("Implicit Iterator", function() {
is(s, " 42 43 44 ", "implicit iterators work");
});

test("Root-level Implicit Iterator", function() {
var text = '{{#.}} {{name}} {{/.}}';
var t = Hogan.compile(text);
var s = t.render([{name:"a"},{name:"b"}]);
is(s, " a b ", "root-level implicit iterators work");
});

test("Partials And Delimiters", function() {
var text = '{{>include}}*\n{{= | | =}}\n*|>include|';
var partialText = ' .{{value}}. ';
Expand Down

0 comments on commit 57f3e5c

Please sign in to comment.