From bdfbbd79072d1c7ac6826226d8f1edab7d11f922 Mon Sep 17 00:00:00 2001 From: Marion Newlevant Date: Fri, 17 Jun 2016 09:13:19 -0700 Subject: [PATCH] continue + loop bug fix --- README.md | 8 +++- mntwigperversion/MnTwigPerversionPlugin.php | 4 +- .../twigextensions/Continue_Node.php | 42 ++++++++++--------- releases.json | 10 ++++- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index f7315b2..97697a8 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,10 @@ The test will return false for hexadecimal strings as this will be the default b ### 1.0.1 -- 2016.05.06 -* Added `numeric` test, fixed parse error in `{% return %} +* Added `numeric` test, fixed parse error in `{% return %}` -Brought to you by [Marion Newlevant](http://marion.newlevant.com) \ No newline at end of file +### 1.0.2 -- 2016.06.17 + +* Fixed loop bug in `{% continue %}` + +Brought to you by [Marion Newlevant](http://marion.newlevant.com) diff --git a/mntwigperversion/MnTwigPerversionPlugin.php b/mntwigperversion/MnTwigPerversionPlugin.php index 6bd1af2..e25b1e2 100644 --- a/mntwigperversion/MnTwigPerversionPlugin.php +++ b/mntwigperversion/MnTwigPerversionPlugin.php @@ -68,7 +68,7 @@ public function getReleaseFeedUrl() */ public function getVersion() { - return '1.0.1'; + return '1.0.2'; } /** @@ -125,4 +125,4 @@ public function addTwigExtension() return new MnTwigPerversionTwigExtension(); } -} \ No newline at end of file +} diff --git a/mntwigperversion/twigextensions/Continue_Node.php b/mntwigperversion/twigextensions/Continue_Node.php index b9b5e5a..cce87e5 100644 --- a/mntwigperversion/twigextensions/Continue_Node.php +++ b/mntwigperversion/twigextensions/Continue_Node.php @@ -13,23 +13,27 @@ class Continue_Node extends \Twig_Node { - /** - * Compiles a Continue_Node into PHP. - */ - public function compile(\Twig_Compiler $compiler) - { - $compiler - ->addDebugInfo($this) - ->write("++\$context['loop']['index0'];\n") - ->write("++\$context['loop']['index'];\n") - ->write("\$context['loop']['first'] = false;\n") - ->write("if (isset(\$context['loop']['length'])) {\n") - ->indent() - ->write("--\$context['loop']['revindex0'];\n") - ->write("--\$context['loop']['revindex'];\n") - ->write("\$context['loop']['last'] = 0 === \$context['loop']['revindex0'];\n") - ->outdent() - ->write("}\n") - ->write("continue;\n"); - } + /** + * Compiles a Continue_Node into PHP. + */ + public function compile(\Twig_Compiler $compiler) + { + $compiler + ->addDebugInfo($this) + ->write("if (array_key_exists('loop', \$context)) {\n") + ->indent() + ->write("++\$context['loop']['index0'];\n") + ->write("++\$context['loop']['index'];\n") + ->write("\$context['loop']['first'] = false;\n") + ->write("if (isset(\$context['loop']['length'])) {\n") + ->indent() + ->write("--\$context['loop']['revindex0'];\n") + ->write("--\$context['loop']['revindex'];\n") + ->write("\$context['loop']['last'] = 0 === \$context['loop']['revindex0'];\n") + ->outdent() + ->write("}\n") + ->outdent() + ->write("}\n") + ->write("continue;\n"); + } } diff --git a/releases.json b/releases.json index 5c679c5..97724a8 100644 --- a/releases.json +++ b/releases.json @@ -15,5 +15,13 @@ "[Added] Numeric Test (from https://github.com/GeckoPackages/GeckoTwig)", "[Fixed] Parse error on {% return %}" ] + }, + { + "version": "1.0.2", + "downloadUrl": "https://github.com/marionnewlevant/craft-twig_perversion/archive/v1.0.2.zip", + "date": "2016-06-17T20:37:12.921Z", + "notes": [ + "[Fixed] Loop bug in {% continue %}" + ] } -] \ No newline at end of file +]