MDL-53457 lib: Upgrade Mustache to 2.10.0

This commit is contained in:
Adrian Greeve 2016-03-15 12:09:00 +08:00
parent fed66ad9e2
commit f9c2f88e39
6 changed files with 46 additions and 11 deletions

View File

@ -10,6 +10,8 @@ Delete phpunit.xml.dist
Delete hidden files ".*"
Delete hidden directories ".git"
Delete folder "bin"
Delete folder "vendor"
@ -17,3 +19,7 @@ Delete folder "vendor"
Delete composer.json
Copy into this folder, and update this readme to cover any changes.
== 3.1 ==
Update from version 2.9.0 to 2.10.0

View File

@ -328,7 +328,7 @@ class Mustache_Compiler
$buffer = \'\';
if (%s) {
$source = %s;
$result = call_user_func($value, $source, $this->lambdaHelper);
$result = call_user_func($value, $source, %s);
if (strpos($result, \'{{\') === false) {
$buffer .= $result;
} else {
@ -370,15 +370,18 @@ class Mustache_Compiler
$callable = $this->getCallable();
if ($otag !== '{{' || $ctag !== '}}') {
$delims = ', ' . var_export(sprintf('{{= %s %s =}}', $otag, $ctag), true);
$delimTag = var_export(sprintf('{{= %s %s =}}', $otag, $ctag), true);
$helper = sprintf('$this->lambdaHelper->withDelimiters(%s)', $delimTag);
$delims = ', ' . $delimTag;
} else {
$helper = '$this->lambdaHelper';
$delims = '';
}
$key = ucfirst(md5($delims . "\n" . $source));
if (!isset($this->sections[$key])) {
$this->sections[$key] = sprintf($this->prepare(self::SECTION), $key, $callable, $source, $delims, $this->walk($nodes, 2));
$this->sections[$key] = sprintf($this->prepare(self::SECTION), $key, $callable, $source, $helper, $delims, $this->walk($nodes, 2));
}
if ($arg === true) {
@ -495,7 +498,7 @@ class Mustache_Compiler
}
const VARIABLE = '
$value = $this->resolveValue($context->%s(%s), $context, $indent);%s
$value = $this->resolveValue($context->%s(%s), $context);%s
$buffer .= %s%s;
';

View File

@ -23,7 +23,7 @@
*/
class Mustache_Engine
{
const VERSION = '2.9.0';
const VERSION = '2.10.0';
const SPEC_VERSION = '1.1.2';
const PRAGMA_FILTERS = 'FILTERS';

View File

@ -20,17 +20,20 @@ class Mustache_LambdaHelper
{
private $mustache;
private $context;
private $delims;
/**
* Mustache Lambda Helper constructor.
*
* @param Mustache_Engine $mustache Mustache engine instance.
* @param Mustache_Context $context Rendering context.
* @param string $delims Optional custom delimiters, in the format `{{= <% %> =}}`. (default: null)
*/
public function __construct(Mustache_Engine $mustache, Mustache_Context $context)
public function __construct(Mustache_Engine $mustache, Mustache_Context $context, $delims = null)
{
$this->mustache = $mustache;
$this->context = $context;
$this->delims = $delims;
}
/**
@ -43,7 +46,31 @@ class Mustache_LambdaHelper
public function render($string)
{
return $this->mustache
->loadLambda((string) $string)
->loadLambda((string) $string, $this->delims)
->renderInternal($this->context);
}
/**
* Render a string as a Mustache template with the current rendering context.
*
* @param string $string
*
* @return string Rendered template
*/
public function __invoke($string)
{
return $this->render($string);
}
/**
* Get a Lambda Helper with custom delimiters.
*
* @param string $delims Custom delimiters, in the format `{{= <% %> =}}`.
*
* @return Mustache_LambdaHelper
*/
public function withDelimiters($delims)
{
return new self($this->mustache, $this->context, $delims);
}
}

View File

@ -164,16 +164,15 @@ abstract class Mustache_Template
*
* @param mixed $value
* @param Mustache_Context $context
* @param string $indent
*
* @return string
*/
protected function resolveValue($value, Mustache_Context $context, $indent = '')
protected function resolveValue($value, Mustache_Context $context)
{
if (($this->strictCallables ? is_object($value) : !is_string($value)) && is_callable($value)) {
return $this->mustache
->loadLambda((string) call_user_func($value))
->renderInternal($context, $indent);
->renderInternal($context);
}
return $value;

View File

@ -262,7 +262,7 @@
<location>mustache</location>
<name>Mustache</name>
<license>MIT</license>
<version>2.9.0</version>
<version>2.10.0</version>
</library>
<library>
<location>amd/src/mustache.js</location>