Skip to content

Commit

Permalink
Added CoffeeScript nowrap support
Browse files Browse the repository at this point in the history
  • Loading branch information
zerious committed Apr 22, 2014
1 parent bd392ff commit ec04b63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ltl.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ var ltl = (function () {

// Detect the module's API, and filter the text.
if (blockFilter.compile) {
var nowrap = /^[^A-Z]*NOWRAP/.test(text);
text = blockFilter.compile(text);
if (nowrap) {
text = text.replace(/(^\(function\(\) \{\s*|\s*\}\)\.call\(this\);\s*$)/g, '');
}
}
else if (blockFilter.markdown) {
text = blockFilter.markdown.toHTML(text);
Expand Down
9 changes: 9 additions & 0 deletions test/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ describe('Blocks', function () {
var hasVar = /var/.test(result);
assert(hasVar);
});
it('should unwrap CoffeeScript with NOWRAP', function () {
var result = ltl.compile('script:coffee\n # NOWRAP\n a = 1')();
var hasVar = /var/.test(result);
assert(hasVar);
var hasFunction = /function/.test(result);
assert(!hasFunction);
var hasCall = /call/.test(result);
assert(!hasCall);
});
it('should work with text with line breaks', function () {
var result = ltl.compile('p:\n First line.\n Second line.')();
assert.equal(result, '<p>First line.\nSecond line.</p>');
Expand Down

0 comments on commit ec04b63

Please sign in to comment.