Skip to content

Commit

Permalink
Adds twig functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mildlygeeky committed Feb 17, 2016
1 parent 1a4baeb commit c4814cb
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 8 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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/)
Expand Down
9 changes: 7 additions & 2 deletions kint/KintPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,7 +44,7 @@ public function getReleaseFeedUrl()

public function getVersion()
{
return '1.0.2';
return '1.1.0';
}

public function getSchemaVersion()
Expand Down Expand Up @@ -79,5 +79,10 @@ public function getSettingsHtml()
));
}

public function addTwigExtension()
{
Craft::import('plugins.kint.twigextensions.KintTwigExtension');
return new KintTwigExtension();
}

}
54 changes: 54 additions & 0 deletions kint/twigextensions/KintTwigExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
namespace Craft;

class KintTwigExtension extends \Twig_Extension
{
protected $env;

public function getName()
{
return 'Kint Twig Extension';
}

public function getFunctions()
{
return array(
'd' => 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();
}

}
10 changes: 9 additions & 1 deletion releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@
"[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",
"notes": [
"[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"
]
}
]

0 comments on commit c4814cb

Please # to comment.