removed trim_blocks option

The trim_blocks option has been removed as the rendered output depends on the value of this option.
This is not a problem for HTML output, but it's a big one if you want to output
plain text for instance.

The behavior now is the same as if the trim_blocks option is set to true. It mimicks
the behavior of PHP tags.
This commit is contained in:
Fabien Potencier
2010-11-19 13:04:59 +01:00
parent 15e46e598d
commit 38acf6f134
6 changed files with 8 additions and 29 deletions
+1
View File
@@ -13,6 +13,7 @@ Backward incompatibilities:
(the old behavior is still possible by adding the "only" keyword)
* Moved Exceptions to Twig_Error_* (Twig_SyntaxError/Twig_RuntimeError are now Twig_Error_Syntax/Twig_Error_Runtime)
* removed trim_blocks option
* added support for is*() methods for attributes (foo.bar now looks for foo->getBar() or foo->isBar())
* changed all exceptions to extend Twig_Error
* fixed unary expressions ({{ not(1 or 0) }})
+3 -4
View File
@@ -166,10 +166,9 @@ add information for other template designers or yourself:
Whitespace Control
------------------
In the default configuration whitespace is not further modified by the
template engine, so each whitespace (spaces, tabs, newlines etc.) is returned
unchanged. If the application configures Twig to `trim_blocks` the first
newline after a template tag is removed automatically (like in PHP).
The first newline after a template tag is removed automatically (like in PHP.)
Whitespace is not further modified by the template engine, so each whitespace
(spaces, tabs, newlines etc.) is returned unchanged.
Escaping
--------
-3
View File
@@ -77,9 +77,6 @@ The following options are available:
method that you can use to display the generated nodes (default to
`false`).
* `trim_blocks`: Mimicks the behavior of PHP by removing the newline that
follows instructions if present (default to `false`).
* `charset`: The charset used by the templates (default to `utf-8`).
* `base_template_class`: The base template class to use for generated
-15
View File
@@ -15,7 +15,6 @@ class Twig_Environment
protected $charset;
protected $loader;
protected $trimBlocks;
protected $debug;
protected $autoReload;
protected $cache;
@@ -41,9 +40,6 @@ class Twig_Environment
* method that you can use to display the generated nodes (default to
* false).
*
* * trim_blocks: Mimicks the behavior of PHP by removing the newline that
* follows instructions if present (default to false).
*
* * charset: The charset used by the templates (default to utf-8).
*
* * base_template_class: The base template class to use for generated
@@ -76,7 +72,6 @@ class Twig_Environment
$this->setCompiler(null !== $compiler ? $compiler : new Twig_Compiler());
$this->debug = isset($options['debug']) ? (bool) $options['debug'] : false;
$this->trimBlocks = isset($options['trim_blocks']) ? (bool) $options['trim_blocks'] : false;
$this->charset = isset($options['charset']) ? $options['charset'] : 'UTF-8';
$this->baseTemplateClass = isset($options['base_template_class']) ? $options['base_template_class'] : 'Twig_Template';
$this->autoReload = isset($options['auto_reload']) ? (bool) $options['auto_reload'] : $this->debug;
@@ -157,16 +152,6 @@ class Twig_Environment
return $this->getCache() ? $this->getCache().'/'.$this->getTemplateClass($name).'.php' : false;
}
public function getTrimBlocks()
{
return $this->trimBlocks;
}
public function setTrimBlocks($bool)
{
$this->trimBlocks = (bool) $bool;
}
/**
* Gets the template class associated with the given string.
*
+1 -1
View File
@@ -87,7 +87,7 @@ class Twig_Lexer implements Twig_LexerInterface
mb_internal_encoding($mbEncoding);
}
return new Twig_TokenStream($tokens, $this->filename, $this->env->getTrimBlocks());
return new Twig_TokenStream($tokens, $this->filename);
}
public function setEnvironment(Twig_Environment $env)
+3 -6
View File
@@ -17,15 +17,13 @@ class Twig_TokenStream
protected $eof;
protected $current;
protected $filename;
protected $trimBlocks;
public function __construct(array $tokens, $filename, $trimBlocks = true)
public function __construct(array $tokens, $filename)
{
$this->pushed = array();
$this->originalTokens = $tokens;
$this->tokens = $tokens;
$this->filename = $filename;
$this->trimBlocks = $trimBlocks;
$this->next();
}
@@ -63,9 +61,8 @@ class Twig_TokenStream
throw new Twig_Error_Syntax('Unexpected end of template', -1);
}
// trim blocks
if ($this->trimBlocks &&
$this->current &&
// mimicks the behavior of PHP by removing the newline that follows instructions if present
if ($this->current &&
Twig_Token::BLOCK_END_TYPE === $this->current->getType() &&
Twig_Token::TEXT_TYPE === $token->getType() &&
$token->getValue() &&