From 1d6dfad4f55c721ec7b6e674ef225b8442bce896 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 21 Dec 2011 19:34:14 +0100 Subject: [PATCH] added a flush tag --- CHANGELOG | 1 + lib/Twig/Extension/Core.php | 1 + lib/Twig/Node/Flush.php | 37 +++++++++++++++++++++++++++++++++++ lib/Twig/TokenParser/Flush.php | 42 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 0 deletions(-) create mode 100644 lib/Twig/Node/Flush.php create mode 100644 lib/Twig/TokenParser/Flush.php diff --git a/CHANGELOG b/CHANGELOG index 192dca8..0a07631 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.5.0 + * added a flash tag * added support for dynamically named filters and functions * added a dump function to help debugging templates * added a nl2br filter diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 78f0660..f60d705 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -56,6 +56,7 @@ class Twig_Extension_Core extends Twig_Extension new Twig_TokenParser_From(), new Twig_TokenParser_Set(), new Twig_TokenParser_Spaceless(), + new Twig_TokenParser_Flush(), ); } diff --git a/lib/Twig/Node/Flush.php b/lib/Twig/Node/Flush.php new file mode 100644 index 0000000..8f2ab9d --- /dev/null +++ b/lib/Twig/Node/Flush.php @@ -0,0 +1,37 @@ + + */ +class Twig_Node_Flush extends Twig_Node +{ + public function __construct($lineno, $tag) + { + parent::__construct(array(), array(), $lineno, $tag); + } + + /** + * Compiles the node to PHP. + * + * @param Twig_Compiler A Twig_Compiler instance + */ + public function compile(Twig_Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write("flush();\n") + ; + } +} diff --git a/lib/Twig/TokenParser/Flush.php b/lib/Twig/TokenParser/Flush.php new file mode 100644 index 0000000..4cf488c --- /dev/null +++ b/lib/Twig/TokenParser/Flush.php @@ -0,0 +1,42 @@ +parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + + return new Twig_Node_Flush($token->getLine(), $this->getTag()); + } + + /** + * Gets the tag name associated with this token parser. + * + * @param string The tag name + */ + public function getTag() + { + return 'flush'; + } +} -- 1.7.2.5