Skip to content

Commit

Permalink
Added tests for interpolated text and fixed a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bminer committed May 17, 2012
1 parent 7a5fe17 commit 2ca801a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/util.js
Expand Up @@ -13,8 +13,8 @@ double quoted string with double quotes escaped.
Usage: interpolate(JSON.stringify(some_string) )
*/
exports.interpolate = function interpolate(str) {
return str.replace(/(\\)?#{(.*)}/g, function(match, escaped, code) {
return escaped ? str : "\"+((__.z=" + code.replace(/\\"/g, '"') +
return str.replace(/(\\)?#{([^}]*)}/g, function(match, escaped, code) {
return escaped ? match : "\"+((__.z=" + code.replace(/\\"/g, '"') +
") == null ? '' : __.z)+\"";
});
};
Expand Down
5 changes: 5 additions & 0 deletions test/output/interpolate.html
@@ -0,0 +1,5 @@
<p>The author of Blade is Blake Miner</p><p>But no one really cares much
I dunno because Jade is cool, too. I don't hate.
Jade is cool, too. I don't hate.
and because \#{escaped}
and because TJ is the freakin' man, and everyone should know it</p>
6 changes: 6 additions & 0 deletions test/templates/interpolate.blade
@@ -0,0 +1,6 @@
p The author of Blade is #{author}
p But no one really cares much
| I dunno #{why} #{Jade}
| #{Jade}
| and because \#{escaped}
| and because TJ is #{TJ}

0 comments on commit 2ca801a

Please sign in to comment.