Skip to content

Commit

Permalink
encoder: fixed block mode
Browse files Browse the repository at this point in the history
  • Loading branch information
matej21 committed May 25, 2015
1 parent def434b commit 7a3886e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ function encoder() {
if (options & encoder.BLOCK) {
v = this.encode(v, encoder.BLOCK);
s += (isList ? '-' : this.encode(k) + "" + ':')
+ "" + (v.indexOf("\n") === -1 ? (' ' + "" + v) : "\n\t" + "" + v.replace("\n", "\n\t"))
+ "" + (v.indexOf("\n") === -1 ? (' ' + "" + v) : "\n\t" + "" + v.replace(/\n/g, "\n\t"))
+ "" + "\n";
} else {
s += (isList ? '' : this.encode(k) + "" + ': ') + "" + this.encode(v) + "" + ', ';
}
}
if (options & encoder.BLOCK) {
return s.trim() + "\n";
return s.trim().replace(/^\s*\n/gm, '') + "\n";
} else {
return (isList ? '[' : '{') + "" + s.substr(0, s.length - 2) + "" + (isList ? ']' : '}');
}
Expand Down
7 changes: 7 additions & 0 deletions test/Encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,12 @@ suite('Encoder', function () {
" - 1\n" +
" - 2\n");
});
test('block 6', function () {
assert.strictEqual(neon.encode({a: {foo1: {lorem: 1}, foo2: {lorem: 2}}}, neon.BLOCK), "a:\n" +
" foo1:\n" +
" lorem: 1\n" +
" foo2:\n" +
" lorem: 2\n");
});

});

0 comments on commit 7a3886e

Please sign in to comment.