* added the autoescape option to enable/disable autoescaping
* removed the newline after a comment (mimicks PHP behavior)
* added a syntax error exception when parent block is used on a template that does not extend another one
- * made the Escaper and Optimizer extensions enabled by default
+ * made the Escaper extension enabled by default
* fixed sandbox extension when used with auto output escaping
* fixed escaper when wrapping a Twig_Node_Print (the original class must be preserved)
- * added an Optimizer extension
+ * added an Optimizer extension (enabled by default; optimizes "for" loops and "raw" filters)
* added priority to node visitors
* 0.9.9 (2010-11-28)
*/
class Twig_NodeVisitor_Optimizer implements Twig_NodeVisitorInterface
{
- const OPTIMIZE_ALL = -1;
- const OPTIMIZE_NONE = 0;
- const OPTIMIZE_FOR = 2;
+ const OPTIMIZE_ALL = -1;
+ const OPTIMIZE_NONE = 0;
+ const OPTIMIZE_FOR = 2;
+ const OPTIMIZE_RAW_FILTER = 4;
protected $loops = array();
protected $optimizers;
$this->leaveOptimizeFor($node, $env);
}
+ if (self::OPTIMIZE_RAW_FILTER === (self::OPTIMIZE_RAW_FILTER & $this->optimizers)) {
+ $node = $this->optimizeRawFilter($node, $env);
+ }
+
+ return $node;
+ }
+
+ /**
+ * Removes "raw" filters.
+ *
+ * @param Twig_NodeInterface $node A Node
+ * @param Twig_Environment $env The current Twig environment
+ */
+ protected function optimizeRawFilter($node, $env)
+ {
+ if ($node instanceof Twig_Node_Expression_Filter && 'raw' == $node->getNode('filter')->getAttribute('value')) {
+ return $node->getNode('node');
+ }
+
return $node;
}