Просмотр исходного кода

First value in the pipe should be interpolated first.

Justin Hileman 13 лет назад
Родитель
Сommit
1cf44d5de9
2 измененных файлов с 12 добавлено и 2 удалено
  1. 2 2
      src/Mustache/Compiler.php
  2. 10 0
      test/Mustache/Test/FiveThree/Functional/FiltersTest.php

+ 2 - 2
src/Mustache/Compiler.php

@@ -264,12 +264,12 @@ class Mustache_Compiler
     }
 
     const VARIABLE = '
-        $value = $context->%s(%s);%s
+        $value = $context->%s(%s);
         if (!is_string($value) && is_callable($value)) {
             $value = $this->mustache
                 ->loadLambda((string) call_user_func($value))
                 ->renderInternal($context, $indent);
-        }
+        }%s
         $buffer .= %s%s;
     ';
 

+ 10 - 0
test/Mustache/Test/FiveThree/Functional/FiltersTest.php

@@ -72,4 +72,14 @@ class Mustache_Test_FiveThree_Functional_FiltersTest extends PHPUnit_Framework_T
             'baz' => function($value) { return 'BAZ'; },
         )));
     }
+
+    public function testInterpolateFirst() {
+        $tpl = $this->mustache->loadTemplate('{{% FILTERS }}{{ foo | bar }}');
+        $this->assertEquals('win!', $tpl->render(array(
+            'foo' => 'FOO',
+            'bar' => function($value) {
+                return ($value === 'FOO') ? 'win!' : 'fail :(';
+            },
+        )));
+    }
 }