From e75839b18596176f7e433cb94365eda32d7c453a Mon Sep 17 00:00:00 2001 From: kpdecker Date: Tue, 1 Oct 2013 21:18:10 -0500 Subject: [PATCH] Break safe string out into standalone module --- lib/handlebars.js | 3 ++- lib/handlebars/safe-string.js | 10 ++++++++++ lib/handlebars/utils.js | 15 ++++----------- 3 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 lib/handlebars/safe-string.js diff --git a/lib/handlebars.js b/lib/handlebars.js index 72b4028e..60ed13c6 100644 --- a/lib/handlebars.js +++ b/lib/handlebars.js @@ -2,8 +2,9 @@ import { HandlebarsEnvironment, createFrame, logger, log } from "./handlebars/ba // Each of these augment the Handlebars object. No need to setup here. // (This is done to easily share code between commonjs and browse envs) +import SafeString from "./handlebars/safe-string"; import Exception from "./handlebars/exception"; -import { SafeString, extend, escapeExpression, isEmpty } from "./handlebars/utils"; +import { extend, escapeExpression, isEmpty } from "./handlebars/utils"; import { compile, precompile } from "./handlebars/compiler/compiler"; import { template } from "./handlebars/runtime"; diff --git a/lib/handlebars/safe-string.js b/lib/handlebars/safe-string.js new file mode 100644 index 00000000..2ae49aa8 --- /dev/null +++ b/lib/handlebars/safe-string.js @@ -0,0 +1,10 @@ +// Build out our basic SafeString type +function SafeString(string) { + this.string = string; +} + +SafeString.prototype.toString = function() { + return "" + this.string; +}; + +export default SafeString; diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js index e3c2160e..8bb28f35 100644 --- a/lib/handlebars/utils.js +++ b/lib/handlebars/utils.js @@ -1,15 +1,8 @@ +import SafeString from "./safe-string"; + var toString = Object.prototype.toString, isArray = Array.isArray; -// Build out our basic SafeString type -export function SafeString(string) { - this.string = string; -}; - -SafeString.prototype.toString = function() { - return "" + this.string; -}; - var escape = { "&": "&", "<": "<", @@ -22,9 +15,9 @@ var escape = { var badChars = /[&<>"'`]/g; var possible = /[&<>"'`]/; -var escapeChar = function(chr) { +function escapeChar(chr) { return escape[chr] || "&"; -}; +} export function extend(obj, value) { for(var key in value) {