Skip to content

Commit

Permalink
Merge branch 'release/1.0.1' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Jun 12, 2019
2 parents 8ba0af5 + fbb342e commit 154a916
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 35 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## 1.0.1 - 2018-06-12
### Added
* Fixed an issue where profiling blocks couldn't be nested
* Greatly simplified the compiled code
* Matched the new Twig namespacing

## 1.0.0 - 2018-04-07
### Added
- Initial release
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ To install the plugin, follow these instructions.

3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Twig Profiler.

Or you can install the plugin via the **Plugin Store** in the Craft CMS 3 AdminCP.
Or you can install the plugin via the **Plugin Store** in the Craft CMS 3 Control Panel.

## Twig Profiler Overview

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nystudio107/craft-twigprofiler",
"description": "Twig Profiler allows you to profile sections of your Twig templates, and see the resulting timings in the Yii2 Debug Toolbar",
"type": "craft-plugin",
"version": "1.0.0",
"version": "1.0.1",
"keywords": [
"craft",
"cms",
Expand Down
41 changes: 19 additions & 22 deletions src/twigextensions/ProfilerNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,38 @@

use nystudio107\twigprofiler\TwigProfiler;

use Twig\Compiler;
use Twig\Node\Node;

/**
* Class ProfilerTokenParser
*
* @author nystudio107
* @package TwigProfiler
* @since 1.0.0
* @since 1.0.1
*/
class ProfilerNode extends \Twig_Node
class ProfilerNode extends Node
{
// Public Methods
// =========================================================================

/**
* @inheritdoc
*/
public function compile(\Twig_Compiler $compiler)
public function compile(Compiler $compiler)
{
$compiler
->addDebugInfo($this)
->write('$_profile = ')
->subcompile($this->getNode('profile'))
->raw(";\n")
->write("if (\$_profile) {\n")
->indent()
->write(TwigProfiler::class."::\$plugin->profile->begin(\$_profile);\n")
->outdent()
->write("}\n")
->indent()
->subcompile($this->getNode('body'))
->outdent()
->write("if (\$_profile) {\n")
->indent()
->write(TwigProfiler::class."::\$plugin->profile->end(\$_profile);\n")
->outdent()
->write("}\n")
->write("unset(\$_profile);\n");
$profileName = $this->getNode('profile');
if ($profileName !== null) {
$profileName = $profileName->attributes['value'] ?? '';
if (!empty($profileName)) {
$compiler
->addDebugInfo($this)
->write(TwigProfiler::class."::\$plugin->profile->begin('".$profileName."');\n")
->indent()
->subcompile($this->getNode('body'))
->outdent()
->write(TwigProfiler::class."::\$plugin->profile->end('".$profileName."');\n");
}
}
}
}
19 changes: 11 additions & 8 deletions src/twigextensions/ProfilerTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,53 @@

namespace nystudio107\twigprofiler\twigextensions;

use Twig\Token;
use Twig\TokenParser\AbstractTokenParser;

/**
* Class ProfilerTokenParser
*
* @author nystudio107
* @package TwigProfiler
* @since 1.0.0
* @since 1.0.1
*/
class ProfilerTokenParser extends \Twig_TokenParser
class ProfilerTokenParser extends AbstractTokenParser
{
// Public Methods
// =========================================================================

/**
* @inheritdoc
*/
public function getTag()
public function getTag(): string
{
return 'profile';
}

/**
* @inheritdoc
*/
public function parse(\Twig_Token $token)
public function parse(Token $token)
{
$lineno = $token->getLine();
$stream = $this->parser->getStream();
$nodes = [
'profile' => $this->parser->getExpressionParser()->parseExpression(),
];
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
$stream->expect(Token::BLOCK_END_TYPE);
$nodes['body'] = $this->parser->subparse([$this, 'decideProfilerEnd'], true);
$stream->expect(\Twig_Token::BLOCK_END_TYPE);
$stream->expect(Token::BLOCK_END_TYPE);

return new ProfilerNode($nodes, [], $lineno, $this->getTag());
}


/**
* @param \Twig_Token $token
* @param Token $token
*
* @return bool
*/
public function decideProfilerEnd(\Twig_Token $token): bool
public function decideProfilerEnd(Token $token): bool
{
return $token->test('endprofile');
}
Expand Down
8 changes: 5 additions & 3 deletions src/twigextensions/ProfilerTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@

namespace nystudio107\twigprofiler\twigextensions;

use Twig\Extension\AbstractExtension;

/**
* Class ProfilerTwigExtension
*
* @author nystudio107
* @package TwigProfiler
* @since 1.0.0
* @since 1.0.1
*/
class ProfilerTwigExtension extends \Twig_Extension
class ProfilerTwigExtension extends AbstractExtension
{
// Public Methods
// =========================================================================

/**
* @inheritdoc
*/
public function getName()
public function getName(): string
{
return 'twig-profiler';
}
Expand Down

0 comments on commit 154a916

Please sign in to comment.