From: Fabien Potencier Date: Fri, 19 Nov 2010 12:04:59 +0000 (+0100) Subject: removed trim_blocks option X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=38acf6f134554b5deff354fc205096b60a851ecf;p=web%2Fkonrad%2Ftwig.git 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. --- diff --git a/CHANGELOG b/CHANGELOG index 8fa845e..4401c17 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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) }}) diff --git a/doc/02-Twig-for-Template-Designers.markdown b/doc/02-Twig-for-Template-Designers.markdown index bf603d2..341dee7 100644 --- a/doc/02-Twig-for-Template-Designers.markdown +++ b/doc/02-Twig-for-Template-Designers.markdown @@ -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 -------- diff --git a/doc/03-Twig-for-Developers.markdown b/doc/03-Twig-for-Developers.markdown index 2d825fd..6cca0dc 100644 --- a/doc/03-Twig-for-Developers.markdown +++ b/doc/03-Twig-for-Developers.markdown @@ -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 diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index c0d94c2..b8b6a9c 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -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. * diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index c3a2bcf..4dd18b5 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -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) diff --git a/lib/Twig/TokenStream.php b/lib/Twig/TokenStream.php index fa32497..65da651 100644 --- a/lib/Twig/TokenStream.php +++ b/lib/Twig/TokenStream.php @@ -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() &&