From c4814cb75f540748a45282917247e7b1c192165d Mon Sep 17 00:00:00 2001 From: Patrick Harrington Date: Wed, 17 Feb 2016 00:22:46 -0500 Subject: [PATCH] Adds twig functions --- README.md | 14 +++--- kint/KintPlugin.php | 9 +++- kint/twigextensions/KintTwigExtension.php | 54 +++++++++++++++++++++++ releases.json | 10 ++++- 4 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 kint/twigextensions/KintTwigExtension.php diff --git a/README.md b/README.md index 0b4df6a..cfbbbc4 100755 --- a/README.md +++ b/README.md @@ -31,31 +31,31 @@ No configuration required, but you can set the theme that Kint will use within t #### d (dump) -`{{ craft.kint.d(someTwigVariable) }}` +`{{ d(someTwigVariable) }}` or `{{ craft.kint.d(someTwigVariable) }}` This is the simplest usage, and will output an interactive debugger for the variable passed in. #### dd (dump and die) -`{{ craft.kint.dd(someTwigVariable) }}` +`{{ dd(someTwigVariable) }}` or `{{ craft.kint.dd(someTwigVariable) }}` This works the same way as the d (dump) command, except it will cause output to end immediately after the debugger is returned. #### s (simple dump) -`{{ craft.kint.s(someTwigVariable) }}` +`{{ s(someTwigVariable) }}` or `{{ craft.kint.s(someTwigVariable) }}` This works essentially the same way as the built-in Twig dump method, and returns a plain text debugging output. #### sd (simple dump and die) -`{{ craft.kint.sd(someTwigVariable) }}` +`{{ sd(someTwigVariable) }}` or `{{ craft.kint.sd(someTwigVariable) }}` Same as above, but with output ending immediately after the plain text debugging output is returned. #### time (point-in-time memory usage and timestamp) -`{{ craft.kint.time }}` +`{{ time() }}` or `{{ craft.kint.time }}` Basic reporting of memory usage at the time that the command is run, as well as a timestamp. If used multiple times, it will also report the time since it was last called and average duration. @@ -81,6 +81,10 @@ one central object to keep things clean. * Fixed issue where raw JS could be shown on page if script tags with double-quotes were used * Removed reference to Kint's path being included below the debugger +### 1.1.0 -- 2016.02.16 + +* Added Twig functions `d`, `dd`, `s`, `sd`, and `time` for easier usage + ## Credit * Thank you to Rokas Šleinius, the developer of Kint - he welcomes donations at [Kint's website](http://raveren.github.io/kint/) diff --git a/kint/KintPlugin.php b/kint/KintPlugin.php index e65ce4a..150f041 100755 --- a/kint/KintPlugin.php +++ b/kint/KintPlugin.php @@ -8,7 +8,7 @@ * @copyright Copyright (c) 2016 Mildly Geeky * @link http://www.mildlygeeky.com * @package Kint - * @since 1.0.2 + * @since 1.1.0 */ namespace Craft; @@ -44,7 +44,7 @@ public function getReleaseFeedUrl() public function getVersion() { - return '1.0.2'; + return '1.1.0'; } public function getSchemaVersion() @@ -79,5 +79,10 @@ public function getSettingsHtml() )); } + public function addTwigExtension() + { + Craft::import('plugins.kint.twigextensions.KintTwigExtension'); + return new KintTwigExtension(); + } } diff --git a/kint/twigextensions/KintTwigExtension.php b/kint/twigextensions/KintTwigExtension.php new file mode 100644 index 0000000..000e5ed --- /dev/null +++ b/kint/twigextensions/KintTwigExtension.php @@ -0,0 +1,54 @@ + new \Twig_Function_Method($this, 'd'), + 'dd' => new \Twig_Function_Method($this, 'dd'), + 's' => new \Twig_Function_Method($this, 's'), + 'sd' => new \Twig_Function_Method($this, 'sd'), + 'time' => new \Twig_Function_Method($this, 'time') + ); + } + + public function initRuntime(\Twig_Environment $env) + { + $this->env = $env; + } + + public function d($debug) + { + return craft()->kint->d($debug); + } + + public function dd($debug) + { + return craft()->kint->dd($debug); + } + + public function s($debug) + { + return craft()->kint->s($debug); + } + + public function sd($debug) + { + return craft()->kint->sd($debug); + } + + public function time() + { + return craft()->kint->time(); + } + +} \ No newline at end of file diff --git a/releases.json b/releases.json index 55c9972..4b2ede1 100755 --- a/releases.json +++ b/releases.json @@ -16,7 +16,7 @@ "[Improved] Typo in documentation for sd method" ] }, - { + { "version": "1.0.2", "downloadUrl": "https://github.com/mildlygeeky/craft_kint/archive/1.0.2.zip", "date": "2016-02-16T21:55:00.867Z", @@ -24,5 +24,13 @@ "[Fixed] Fixed issue where raw JS code showed on page when script tags used double-quotes (core Kint issue)", "[Improved] Now does not expose path to Kint PHP scripts below debugger" ] + }, + { + "version": "1.1.0", + "downloadUrl": "https://github.com/mildlygeeky/craft_kint/archive/1.1.0.zip", + "date": "2016-02-16T23:55:00.867Z", + "notes": [ + "[Added] Twig functions for easier usage" + ] } ]