Permalink
Browse files

move out filters

  • Loading branch information...
1 parent 5574b04 commit f16161f42bb4815e8e810af12bfa125bf4af1472 @shaunlee committed Apr 29, 2011
Showing with 16 additions and 11 deletions.
  1. +11 −0 lib/filters.js
  2. +5 −11 lib/jst.js
View
@@ -0,0 +1,11 @@
+// filters
+
+const htmlCodes = {'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;'},
+ htmlre = /[&<>"]/g,
+ htmlEscape = function (src) { return htmlCodes[src]; };
+
+// e(src)
+jst_filter_escape = function(src) {
+ return typeof src !== 'string' ? src : src.replace(htmlre, htmlEscape);
+}
+
View
@@ -24,29 +24,23 @@ exports.configure = function(options) {
_options[prop] = options[prop];
}
-// filters
-
-const htmlCodes = {'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;'},
- htmlre = /[&<>"]/g,
- htmlEscape = function (src) { return htmlCodes[src]; };
-
-jst_filter_escape = function(src) {
- return typeof src !== 'string' ? src : src.replace(htmlre, htmlEscape);
-}
-
// compiler
+require('./filters');
+
var compile = exports.compile = function(ctx) {
_options.useIt = /{{ (e\()?it\./.test(ctx);
var code = (_options.useIt ? 'var out = "' : 'var out = ""; with(it) { out += "')
+ ctx.replace(/[\t\r\n]/g, '')
.replace(/"/g, '\\"')
- .replace(/\{\{ (.+?) \}\}/g, '"; out += $1; out += "')
+ .replace(/\{\{ (.+?) \}\}/g, '" + $1 + "')
.replace(/\{% (.+?) %\}/g, '"; $1 out += "')
.replace(/\{#.+?#\}/g, '')
.replace(/ e\(/g, ' jst_filter_escape(')
+ (_options.useIt ? '"; return out;' : '"; } return out;');
+ //console.log(code.replace(' out += "";', ''));
+
return new Function('it', code.replace(' out += "";', ''));
}

0 comments on commit f16161f

Please sign in to comment.