From efa214bbbc271e5fb19542ac2aeab28fb81116e9 Mon Sep 17 00:00:00 2001 From: Marion Newlevant Date: Fri, 8 Jul 2016 14:54:52 -0700 Subject: [PATCH] added json_decode filter --- README.md | 9 +++++++++ mntwigperversion/MnTwigPerversionPlugin.php | 5 ++++- .../twigextensions/MnTwigPerversionTwigExtension.php | 9 +++++++++ releases.json | 8 ++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d80357e..c0bc69f 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Making twig do things it really shouldn't. Twig is not intended to be a gene - {% break %}, {% continue %}, and {% return %} tags - `is numeric` test +- `json_decode` filter ## Installation @@ -73,6 +74,10 @@ The test will return false for hexadecimal strings as this will be the default b ``` +### Filters +- **json_decode** + Decode json string, returning php associative arrays. Uses the PHP [json_decode](http://php.net/manual/en/function.json-decode.php) function + ## MN Twig Perversion Changelog ### 1.0.0 -- 2016.04.17 @@ -91,4 +96,8 @@ The test will return false for hexadecimal strings as this will be the default b * Possibility of `{% return %}` with no value +### 1.1.0 -- 2016.07.08 + +* Added json_decode + Brought to you by [Marion Newlevant](http://marion.newlevant.com) diff --git a/mntwigperversion/MnTwigPerversionPlugin.php b/mntwigperversion/MnTwigPerversionPlugin.php index d4285c2..c661d11 100755 --- a/mntwigperversion/MnTwigPerversionPlugin.php +++ b/mntwigperversion/MnTwigPerversionPlugin.php @@ -68,7 +68,7 @@ public function getReleaseFeedUrl() */ public function getVersion() { - return '1.0.3'; + return '1.1.0'; } /** @@ -122,10 +122,13 @@ public function hasCpSection() public function addTwigExtension() { Craft::import('plugins.mntwigperversion.twigextensions.MnTwigPerversionTwigExtension'); + Craft::import('plugins.mntwigperversion.twigextensions.MnTwigPerversion_Break_Node'); Craft::import('plugins.mntwigperversion.twigextensions.MnTwigPerversion_Break_TokenParser'); + Craft::import('plugins.mntwigperversion.twigextensions.MnTwigPerversion_Continue_Node'); Craft::import('plugins.mntwigperversion.twigextensions.MnTwigPerversion_Continue_TokenParser'); + Craft::import('plugins.mntwigperversion.twigextensions.MnTwigPerversion_Return_Node'); Craft::import('plugins.mntwigperversion.twigextensions.MnTwigPerversion_Return_TokenParser'); // Craft::import('plugins.mntwigperversion.twigextensions.NumericTest'); diff --git a/mntwigperversion/twigextensions/MnTwigPerversionTwigExtension.php b/mntwigperversion/twigextensions/MnTwigPerversionTwigExtension.php index d5e54d2..7a0091e 100755 --- a/mntwigperversion/twigextensions/MnTwigPerversionTwigExtension.php +++ b/mntwigperversion/twigextensions/MnTwigPerversionTwigExtension.php @@ -46,4 +46,13 @@ public function getTests() ); } + public function getFilters() { + return array( + 'json_decode' => new \Twig_Filter_Method($this, 'jsonDecode'), + ); + } + + public function jsonDecode($str) { + return json_decode($str, true); // return assoc arrays (more twig-like) + } } diff --git a/releases.json b/releases.json index 29a04b7..2b28629 100644 --- a/releases.json +++ b/releases.json @@ -32,5 +32,13 @@ "[Added] {% return %} does not require a value to return", "[Fixed] Renamed classes to prevent possible name conflicts" ] + }, + { + "version": "1.1.0", + "downloadUrl": "https://github.com/marionnewlevant/craft-twig_perversion/archive/v1.1.0.zip", + "date": "2016-07-08T20:37:12.921Z", + "notes": [ + "[Added] new filter json_decode" + ] } ]