Skip to content

Commit

Permalink
Add escape()
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhaveri committed Jan 7, 2012
1 parent 49e0161 commit 8149458
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/UtilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,14 @@ public function testTemplate() {
$result = $mustache(array('planet'=>'World'));
$this->assertEquals('Hello World!', $result);
}

public function testEscape() {
// from js
$this->assertEquals('Curly & Moe', __::escape('Curly & Moe'));
$this->assertEquals('Curly & Moe', __::escape('Curly & Moe'));

// extra
$this->assertEquals('Curly & Moe', __('Curly & Moe')->escape());
$this->assertEquals('Curly & Moe', __('Curly & Moe')->escape());
}
}
7 changes: 7 additions & 0 deletions underscore.php
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,13 @@ public function template($code=null, $context=null) {
return self::_wrap(((isset($this) && isset($this->_wrapped) && $this->_wrapped) || !is_null($context)) ? $return($context) : $return);
}

// Escape
public function escape($item=null) {
list($item) = self::_wrapArgs(func_get_args(), 1);

return self::_wrap(htmlentities($item));
}


// Memoizes a function by caching the computed result.
public $_memoized = array();
Expand Down

0 comments on commit 8149458

Please sign in to comment.