Skip to content

Commit

Permalink
Merge branch 'release/1.0.0' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Apr 7, 2018
2 parents 3671c1b + 6534514 commit 05bf0b8
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 123 deletions.
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

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

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 1.0.0 - 2018-04-06
## 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 @@ -61,7 +61,7 @@ Reload your page, and then click on the **Time** section of the Debug Toolbar, a

The **Duration** column shows how long it took to execute the chunk of code inside of the `{% profile %}` block.

The **Category** column shows the type of the profile sample, which will always been **Twig Profiler** for profile data collected by Twig Profiler.
The **Category** column shows the type of the profile sample, which will always been **Twig Profiler** along with the name of the template, for profile data collected by Twig Profiler.

The **Info** column shows the unique identifier we passed in.

Expand Down
Binary file modified resources/img/plugin-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/screenshots/debug-toolbar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/screenshots/enable-debug-toolbar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/screenshots/performance-profiling.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified resources/screenshots/performance-timeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 26 additions & 1 deletion src/TwigProfiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@

namespace nystudio107\twigprofiler;

use nystudio107\twigprofiler\models\Settings;
use nystudio107\twigprofiler\services\Profile as ProfileService;
use nystudio107\twigprofiler\twigextensions\ProfilerTwigExtension;
use nystudio107\twigprofiler\models\Settings;

use Craft;
use craft\base\Plugin;
use craft\events\TemplateEvent;
use craft\web\View;

use yii\base\Event;

/**
* Class TwigProfiler
Expand All @@ -37,6 +41,11 @@ class TwigProfiler extends Plugin
*/
public static $plugin;

/**
* @var string The name of the rendering template
*/
public static $renderingTemplate = '';

// Public Properties
// =========================================================================

Expand All @@ -56,8 +65,24 @@ public function init()
parent::init();
self::$plugin = $this;

$settings = $this->getSettings();
Craft::$app->view->registerTwigExtension(new ProfilerTwigExtension());

if ($settings->appendTemplateName) {
// Handler: View::EVENT_BEFORE_RENDER_TEMPLATE
Event::on(
View::class,
View::EVENT_BEFORE_RENDER_TEMPLATE,
function (TemplateEvent $event) {
Craft::debug(
'View::EVENT_BEFORE_RENDER_TEMPLATE',
__METHOD__
);
self::$renderingTemplate = ' - '.$event->template;
}
);
}

Craft::info(
Craft::t(
'twig-profiler',
Expand Down
12 changes: 6 additions & 6 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/**
* Twig Profiler plugin for Craft CMS 3.x
*
* Twig Profiler allows you to profile sections of your Twig templates, and see the resulting timings in the Yii2 Debug Toolbar
* Twig Profiler allows you to profile sections of your Twig templates, and see
* the resulting timings in the Yii2 Debug Toolbar
*
* @link https://nystudio107.com/
* @copyright Copyright (c) 2018 nystudio107
Expand All @@ -18,13 +19,12 @@
* and make your changes there to override default settings.
*
* Once copied to 'craft/config', this file will be multi-environment aware as
* well, so you can have different settings groups for each environment, just as
* you do for 'general.php'
* well, so you can have different settings groups for each environment, just
* as you do for 'general.php'
*/

return [

// This controls blah blah blah
"someAttribute" => true,

// Controls whether to append the template name to the profile category
'appendTemplateName' => true,
];
52 changes: 0 additions & 52 deletions src/icon-mask.svg

This file was deleted.

63 changes: 16 additions & 47 deletions src/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 7 additions & 6 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/**
* Twig Profiler plugin for Craft CMS 3.x
*
* Twig Profiler allows you to profile sections of your Twig templates, and see the resulting timings in the Yii2 Debug Toolbar
* Twig Profiler allows you to profile sections of your Twig templates, and see
* the resulting timings in the Yii2 Debug Toolbar
*
* @link https://nystudio107.com/
* @copyright Copyright (c) 2018 nystudio107
Expand All @@ -26,21 +27,21 @@ class Settings extends Model
// =========================================================================

/**
* @var string
* @var bool Controls whether to append the template name to the profile
* category
*/
public $someAttribute = 'Some Default';
public $appendTemplateName = true;

// Public Methods
// =========================================================================

/**
* @inheritdoc
*/
public function rules()
public function rules(): array
{
return [
['someAttribute', 'string'],
['someAttribute', 'default', 'value' => 'Some Default'],
['appendTemplateName', 'boolean'],
];
}
}
21 changes: 18 additions & 3 deletions src/services/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/**
* Twig Profiler plugin for Craft CMS 3.x
*
* Twig Profiler allows you to profile sections of your Twig templates, and see the resulting timings in the Yii2 Debug Toolbar
* Twig Profiler allows you to profile sections of your Twig templates, and see
* the resulting timings in the Yii2 Debug Toolbar
*
* @link https://nystudio107.com/
* @copyright Copyright (c) 2018 nystudio107
Expand All @@ -12,6 +13,7 @@

use Craft;
use craft\base\Component;
use nystudio107\twigprofiler\TwigProfiler;

/**
* @author nystudio107
Expand All @@ -20,6 +22,11 @@
*/
class Profile extends Component
{
// Constants
// =========================================================================

const CATEGORY_PREFIX = 'Twig Profiler';

// Public Methods
// =========================================================================

Expand All @@ -30,7 +37,11 @@ class Profile extends Component
*/
public function begin(string $profile)
{
Craft::beginProfile($profile, 'Twig Profiler');
Craft::beginProfile(
$profile,
Craft::t('twig-profiler', self::CATEGORY_PREFIX)
.TwigProfiler::$renderingTemplate
);
}

/**
Expand All @@ -40,6 +51,10 @@ public function begin(string $profile)
*/
public function end(string $profile)
{
Craft::endProfile($profile, 'Twig Profiler');
Craft::endProfile(
$profile,
Craft::t('twig-profiler', self::CATEGORY_PREFIX)
.TwigProfiler::$renderingTemplate
);
}
}
6 changes: 4 additions & 2 deletions src/translations/en/twig-profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/**
* Twig Profiler plugin for Craft CMS 3.x
*
* Twig Profiler allows you to profile sections of your Twig templates, and see the resulting timings in the Yii2 Debug Toolbar
* Twig Profiler allows you to profile sections of your Twig templates, and see
* the resulting timings in the Yii2 Debug Toolbar
*
* @link https://nystudio107.com/
* @copyright Copyright (c) 2018 nystudio107
Expand All @@ -14,5 +15,6 @@
* @since 1.0.0
*/
return [
'Twig Profiler plugin loaded' => 'Twig Profiler plugin loaded',
'{name} plugin loaded' => '{name} plugin loaded',
'Twig Profiler' => 'Twig Profiler',
];
4 changes: 3 additions & 1 deletion src/twigextensions/ProfilerNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/**
* Twig Profiler plugin for Craft CMS 3.x
*
* Twig Profiler allows you to profile sections of your Twig templates, and see the resulting timings in the Yii2 Debug Toolbar
* Twig Profiler allows you to profile sections of your Twig templates, and see
* the resulting timings in the Yii2 Debug Toolbar
*
* @link https://nystudio107.com/
* @copyright Copyright (c) 2018 nystudio107
Expand All @@ -14,6 +15,7 @@

/**
* Class ProfilerTokenParser
*
* @author nystudio107
* @package TwigProfiler
* @since 1.0.0
Expand Down
5 changes: 4 additions & 1 deletion src/twigextensions/ProfilerTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/**
* Twig Profiler plugin for Craft CMS 3.x
*
* Twig Profiler allows you to profile sections of your Twig templates, and see the resulting timings in the Yii2 Debug Toolbar
* Twig Profiler allows you to profile sections of your Twig templates, and see
* the resulting timings in the Yii2 Debug Toolbar
*
* @link https://nystudio107.com/
* @copyright Copyright (c) 2018 nystudio107
Expand All @@ -12,6 +13,7 @@

/**
* Class ProfilerTokenParser
*
* @author nystudio107
* @package TwigProfiler
* @since 1.0.0
Expand Down Expand Up @@ -49,6 +51,7 @@ public function parse(\Twig_Token $token)

/**
* @param \Twig_Token $token
*
* @return bool
*/
public function decideProfilerEnd(\Twig_Token $token): bool
Expand Down

0 comments on commit 05bf0b8

Please sign in to comment.