From 9693695d2b732c5a0298f90db8fabadaee780da6 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Wed, 14 Mar 2012 19:55:26 -0700 Subject: [PATCH 1/4] Fix E_STRICT failure in i18n example. --- examples/i18n/I18n.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/i18n/I18n.php b/examples/i18n/I18n.php index 980e649..7e0fcce 100644 --- a/examples/i18n/I18n.php +++ b/examples/i18n/I18n.php @@ -9,12 +9,12 @@ class I18n extends Mustache { public $__ = array(__CLASS__, '__trans'); // A *very* small i18n dictionary :) - private $dictionary = array( + private static $dictionary = array( 'Hello.' => 'Hola.', 'My name is {{ name }}.' => 'Me llamo {{ name }}.', ); - public function __trans($text) { - return isset($this->dictionary[$text]) ? $this->dictionary[$text] : $text; + public static function __trans($text) { + return isset(self::$dictionary[$text]) ? self::$dictionary[$text] : $text; } -} \ No newline at end of file +} From f6f9d3fe6fa14e7fc9a1e08e6834d768c10b95ff Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Wed, 14 Mar 2012 20:04:55 -0700 Subject: [PATCH 2/4] Allow custom `escape` callbacks. cf. #86 --- Mustache.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Mustache.php b/Mustache.php index c97cd12..5cfe409 100644 --- a/Mustache.php +++ b/Mustache.php @@ -30,6 +30,9 @@ class Mustache { MustacheException::UNKNOWN_PRAGMA => true, ); + // Override the escaper function. Defaults to `htmlspecialchars`. + protected $_escape; + // Override charset passed to htmlentities() and htmlspecialchars(). Defaults to UTF-8. protected $_charset = 'UTF-8'; @@ -84,6 +87,11 @@ class Mustache { * Passing an $options array allows overriding certain Mustache options during instantiation: * * $options = array( + * // `escape` -- custom escaper callback; must be callable. + * 'escape' => function($text) { + * return htmlspecialchars($text, ENT_COMPAT, 'UTF-8'); + * }, + * * // `charset` -- must be supported by `htmlspecialentities()`. defaults to 'UTF-8' * 'charset' => 'ISO-8859-1', * @@ -127,6 +135,13 @@ class Mustache { * @return void */ protected function _setOptions(array $options) { + if (isset($options['escape'])) { + if (!is_callable($options['escape'])) { + throw new InvalidArgumentException('Mustache constructor "escape" option must be callable'); + } + $this->_escape = $options['escape']; + } + if (isset($options['charset'])) { $this->_charset = $options['charset']; } @@ -640,7 +655,13 @@ class Mustache { * @return string */ protected function _renderEscaped($tag_name, $leading, $trailing) { - $rendered = htmlentities($this->_renderUnescaped($tag_name, '', ''), ENT_COMPAT, $this->_charset); + $value = $this->_renderUnescaped($tag_name, '', ''); + if (isset($this->_escape)) { + $rendered = call_user_func($this->_escape, $value); + } else { + $rendered = htmlentities($value, ENT_COMPAT, $this->_charset); + } + return $leading . $rendered . $trailing; } From 4de7f2d23be1d74edf2207ceb3bcf6122c9f7f8e Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 3 Apr 2012 21:56:28 -0700 Subject: [PATCH 3/4] Switch submodule to use git:// repo url. --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 81ca331..1aaa50a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "test/spec"] path = test/spec - url = http://github.com/mustache/spec.git + url = git://github.com/mustache/spec.git From 417b139d8691b56b1d302a43c12d6f42f81e3adc Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Tue, 3 Apr 2012 22:00:01 -0700 Subject: [PATCH 4/4] Version bump (v1.1.0) --- Mustache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mustache.php b/Mustache.php index 5cfe409..18236aa 100644 --- a/Mustache.php +++ b/Mustache.php @@ -14,7 +14,7 @@ */ class Mustache { - const VERSION = '1.0.0'; + const VERSION = '1.1.0'; const SPEC_VERSION = '1.1.2'; /**