Skip to content

Commit

Permalink
Added to the View class support for disable_escape.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjerdonek committed Dec 19, 2011
1 parent 120d422 commit 1726741
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pystache/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ def repl(match):

return re.sub('[A-Z]', repl, template_name)[1:]

def render(self, encoding=None):
def render(self, encoding=None, disable_escape=False):
"""
Return the view rendered using the current context.
"""
template = Template(self.get_template(), self.load_template, output_encoding=encoding)
template = Template(self.get_template(), self.load_template, output_encoding=encoding,
disable_escape=disable_escape)
return template.render(self.context)

def get(self, key, default=None):
Expand Down
3 changes: 3 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def test_unicode_input(self):
def test_escaped(self):
self.assertEquals(Escaped().render(), "<h1>Bear &gt; Shark</h1>")

def test_escaped_disabling(self):
self.assertEquals(Escaped().render(disable_escape=True), "<h1>Bear > Shark</h1>")

def test_unescaped(self):
self.assertEquals(Unescaped().render(), "<h1>Bear > Shark</h1>")

Expand Down

0 comments on commit 1726741

Please sign in to comment.