From 5e41f829857a053695d8498c53732750dddcca49 Mon Sep 17 00:00:00 2001 From: Danny Greg & Nathan Sobo Date: Thu, 19 Jan 2012 16:46:32 -0800 Subject: [PATCH] Add a raw call to builder. --- spec/stdlib/template/builder-spec.coffee | 5 +++++ src/stdlib/template/builder.coffee | 3 +++ src/stdlib/template/text.coffee | 17 ++++++++++------- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/spec/stdlib/template/builder-spec.coffee b/spec/stdlib/template/builder-spec.coffee index 5e182cdb0..b3cc0d5d3 100644 --- a/spec/stdlib/template/builder-spec.coffee +++ b/spec/stdlib/template/builder-spec.coffee @@ -44,6 +44,11 @@ describe "Builder", -> builder.tag 'br', id: 'foo' expect(builder.toHtml()).toBe '
' + describe ".raw(text)", -> + it "does not escape html entities", -> + builder.raw ' ' + expect(builder.toHtml()).toBe ' ' + describe ".subview(name, template, attrs)", -> template = null diff --git a/src/stdlib/template/builder.coffee b/src/stdlib/template/builder.coffee index 2e50e678f..026da38a6 100644 --- a/src/stdlib/template/builder.coffee +++ b/src/stdlib/template/builder.coffee @@ -65,6 +65,9 @@ class Builder text: (string) -> @document.push(new Text(string)) + raw: (string) -> + @document.push(new Text(string, true)) + wireOutlets: (view) -> view.find('[outlet]').each -> elt = $(this) diff --git a/src/stdlib/template/text.coffee b/src/stdlib/template/text.coffee index de8b25e3a..1270086f8 100644 --- a/src/stdlib/template/text.coffee +++ b/src/stdlib/template/text.coffee @@ -1,12 +1,15 @@ module.exports = class Text - constructor: (@string) -> + constructor: (@string, @raw=false) -> toHtml: -> - @string - .replace(/&/g, '&') - .replace(/"/g, '"') - .replace(/'/g, ''') - .replace(//g, '>') + if @raw + @string + else + @string + .replace(/&/g, '&') + .replace(/"/g, '"') + .replace(/'/g, ''') + .replace(//g, '>')