fixed filter tag

This commit is contained in:
Fabien Potencier
2011-02-05 23:57:22 +01:00
parent 7a7c23f197
commit 4501984e5d
4 changed files with 16 additions and 4 deletions
+1 -1
View File
@@ -245,7 +245,7 @@ class Twig_ExpressionParser
}
if ('block' === $node->getAttribute('name')) {
return new Twig_Node_Expression_BlockReference($args->getNode(0), $node->getLine());
return new Twig_Node_Expression_BlockReference($args->getNode(0), false, $node->getLine());
}
if (null !== $alias = $this->parser->getImportedFunction($node->getAttribute('name'))) {
+6 -2
View File
@@ -18,9 +18,9 @@
*/
class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
{
public function __construct(Twig_NodeInterface $name, $lineno, $tag = null)
public function __construct(Twig_NodeInterface $name, $asString = false, $lineno, $tag = null)
{
parent::__construct(array('name' => $name), array(), $lineno, $tag);
parent::__construct(array('name' => $name), array('as_string' => $asString), $lineno, $tag);
}
/**
@@ -30,6 +30,10 @@ class Twig_Node_Expression_BlockReference extends Twig_Node_Expression
*/
public function compile(Twig_Compiler $compiler)
{
if ($this->getAttribute('as_string')) {
$compiler->raw('(string) ');
}
$compiler
->raw("\$this->renderBlock(")
->subcompile($this->getNode('name'))
+1 -1
View File
@@ -20,7 +20,7 @@ class Twig_TokenParser_Filter extends Twig_TokenParser
public function parse(Twig_Token $token)
{
$name = $this->parser->getVarName();
$ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), $token->getLine(), $this->getTag());
$ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), true, $token->getLine(), $this->getTag());
$filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag());
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
@@ -0,0 +1,8 @@
--TEST--
"filter" tag applies a filter on its children
--TEMPLATE--
{% filter json_encode|raw %}test{% endfilter %}
--DATA--
return array()
--EXPECT--
"test"