Comparing version 0.1.12 to 0.1.13
28
ltl.js
@@ -71,3 +71,3 @@ /** | ||
// Allow users to see what version of ltl they're using. | ||
version: '0.1.12', | ||
version: '0.1.13', | ||
@@ -150,3 +150,4 @@ // Store all of the templates that have been compiled. | ||
var varIndex = 0; | ||
var escapeVar = false; | ||
var escapeHtmlVar = false; | ||
var encodeUriVar = false; | ||
var loopVars = []; | ||
@@ -383,6 +384,6 @@ | ||
/** | ||
* Find ${...} and ={...} and turn them into contextified insertions unless escaped. | ||
* Find ${...}, &{...} and ={...} and turn them into contextified insertions unless escaped. | ||
*/ | ||
function interpolate(code) { | ||
return code.replace(/(\\?)([$=])\{([^\}]+)\}/g, function(match, backslash, symbol, expression) { | ||
return code.replace(/(\\?)([$=&])\{([^\}]+)\}/g, function(match, backslash, symbol, expression) { | ||
if (backslash) { | ||
@@ -392,7 +393,13 @@ return symbol + '{' + expression + '}'; | ||
if (symbol == '$') { | ||
if (!escapeVar) { | ||
escapeVar = vars[varIndex++]; | ||
if (!escapeHtmlVar) { | ||
escapeHtmlVar = vars[varIndex++]; | ||
} | ||
return "'+" + escapeVar + '(' + contextify(expression) + ")+'"; | ||
return "'+" + escapeHtmlVar + '(' + contextify(expression) + ")+'"; | ||
} | ||
else if (symbol == '&') { | ||
if (!encodeUriVar) { | ||
encodeUriVar = vars[varIndex++]; | ||
} | ||
return "'+" + encodeUriVar + '(' + contextify(expression) + ")+'"; | ||
} | ||
else { | ||
@@ -703,5 +710,8 @@ return "'+" + contextify(expression) + "+'"; | ||
// Create the function. | ||
if (escapeVar) { | ||
output = "function " + escapeVar + "(t){return (t==null?'':''+t).replace(/</g,'<')};" + output; | ||
if (escapeHtmlVar) { | ||
output = "function " + escapeHtmlVar + "(t){return (t==null?'':''+t).replace(/</g,'<')};" + output; | ||
} | ||
if (encodeUriVar) { | ||
output = "function " + encodeUriVar + "(t){return (encodeURIComponent||escape)(t==null?'':''+t)};" + output; | ||
} | ||
output = 'function(' + settings.contextVar + (hasGets ? ',' + settings.partsVar : '') + '){' + output + '}'; | ||
@@ -708,0 +718,0 @@ |
@@ -14,3 +14,3 @@ { | ||
], | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"main": "ltl", | ||
@@ -17,0 +17,0 @@ "homepage": "http://lighter.io/ltl", |
@@ -199,3 +199,13 @@ # Ltl | ||
If you'd like your content to skip HTML encoding (because | ||
To encode for a URL rather than HTML, use `&{}`. | ||
Context: `{query: "good brewpubs"}` | ||
```jade | ||
a(href="?q=&{query}") | ||
``` | ||
```html | ||
<a href="?q=good%20brewpubs">good brewpubs</a> | ||
``` | ||
If you'd like your content to skip encoding (because | ||
you want your expression to output raw HTML tags rather | ||
@@ -212,3 +222,3 @@ than safely escaped text), use `={..}`. | ||
If you want to show `${..}` or `={..}` blocks in your output, | ||
If you want to show `${..}`, `&{..}` or `={..}` blocks in your output, | ||
you can escape with a backslash. | ||
@@ -215,0 +225,0 @@ ```jade |
36084
710
346