Skip to content

Commit

Permalink
continue + loop bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
marionnewlevant committed Jun 17, 2016
1 parent 283bc9c commit bdfbbd7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
### 1.0.2 -- 2016.06.17

* Fixed loop bug in `{% continue %}`

Brought to you by [Marion Newlevant](http://marion.newlevant.com)
4 changes: 2 additions & 2 deletions mntwigperversion/MnTwigPerversionPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getReleaseFeedUrl()
*/
public function getVersion()
{
return '1.0.1';
return '1.0.2';
}

/**
Expand Down Expand Up @@ -125,4 +125,4 @@ public function addTwigExtension()

return new MnTwigPerversionTwigExtension();
}
}
}
42 changes: 23 additions & 19 deletions mntwigperversion/twigextensions/Continue_Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
10 changes: 9 additions & 1 deletion releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}"
]
}
]
]

0 comments on commit bdfbbd7

Please sign in to comment.