Skip to content

Commit d57f30e

Browse files
committed
Initial commit
0 parents  commit d57f30e

File tree

16 files changed

+1419
-0
lines changed

16 files changed

+1419
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# ToolMate Changelog
2+
3+
## 1.0.0 - 2020-05-09
4+
5+
### Added
6+
- Initial public release

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Værsågod
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
ToolMate plugin for Craft CMS
2+
===
3+
4+
Is that a tool in your pocket, or are you just happy to see me, mate!
5+
6+
![Screenshot](resources/plugin_logo.png)
7+
8+
## Requirements
9+
10+
This plugin requires Craft CMS 3.0.0 or later.
11+
12+
## Installation
13+
14+
To install the plugin, either install it from the plugin store, or follow these instructions:
15+
16+
1. Install with composer via `composer require vaersaagod/toolmate` from your project directory.
17+
2. Install the plugin in the Craft Control Panel under Settings → Plugins, or from the command line via `./craft install/plugin toolmate`.
18+
19+
---
20+
21+
## Configuring
22+
23+
ToolMate can be configured by creating a file named `toolmate.php` in your Craft config folder,
24+
and overriding settings as needed.
25+
26+
### publicRoot [string]
27+
*Default: `null`*
28+
29+
Sets the public webroot that is used by inline and stamp on servers
30+
where `$_SERVER['DOCUMENT_ROOT']` and `@webroot` is incorrect.
31+
32+
### enableMinify [bool]
33+
*Default: `true`*
34+
35+
Enables/disables all minifying.
36+
37+
---
38+
39+
## Template variables
40+
41+
### craft.toolmate.inline(filename [, remote=false])
42+
43+
```
44+
{{ craft.toolmate.inline('/assets/critical.css') }}
45+
```
46+
47+
### craft.toolmate.stamp(filename [, mode = 'file', type = 'ts'])
48+
49+
```
50+
{# /assets/bundle.1522425799.js #}
51+
{{ craft.tool.stamp('/assets/bundle.js') }}
52+
53+
{# /assets/1522425799/bundle.js #}
54+
{{ craft.tool.stamp('/assets/bundle.js', 'folder') }}
55+
56+
{# /assets/5140247221/bundle.js #}
57+
{{ craft.tool.stamp('/assets/bundle.js', 'folder', 'hash') }}
58+
59+
{# /assets/bundle.js?ts=1522425799 #}
60+
{{ craft.tool.stamp('/assets/bundle.js', 'query') }}
61+
62+
{# 1522425799 #}
63+
{{ craft.tool.stamp('/assets/bundle.js', 'tsonly') }}
64+
65+
```
66+
67+
### craft.toolmate.setCookie(params [, secure = false])
68+
69+
```
70+
{% do craft.toolmate.setCookie({ name: 'testing', value: 'Just testing!' }) %}
71+
{% do craft.toolmate.setCookie({ name: 'testingsecure', value: { lorem: 'ipsum', dolor: 'sit amet' } }, true) %}
72+
73+
{% set params = {
74+
name: 'cookiename',
75+
value: 'thevalue',
76+
expire: 0,
77+
path: '/',
78+
domain: '',
79+
secure: false,
80+
httpOnly: false,
81+
sameSite: null,
82+
} %}
83+
84+
{% do craft.toolmate.setCookie(params) %}
85+
```
86+
87+
### craft.toolmate.getCookie(name [, secure = false])
88+
89+
```
90+
{{ craft.toolmate.getCookie('testing') }}
91+
{{ dump(craft.toolmate.getCookie('testingsecure', true)) }}
92+
```
93+
94+
### craft.toolmate.getVideoEmbed(url [, params = []])
95+
96+
```
97+
{% set videoEmbed = craft.toolmate.getVideoEmbed(videoUrl, {
98+
youtube_enablejsapi: 1,
99+
youtube_rel: 0,
100+
youtube_showinfo: 0,
101+
youtube_controls: 1,
102+
youtube_autoplay: 0,
103+
youtube_modestbranding: 1,
104+
youtube_playsinline: 0,
105+
vimeo_byline: 0,
106+
vimeo_title: 0,
107+
vimeo_autoplay: 0,
108+
vimeo_portrait: 0
109+
}) %}
110+
```
111+
112+
---
113+
114+
## Twig tags
115+
116+
### minify
117+
118+
```
119+
<style>
120+
{% minify css %}
121+
.lorem {
122+
width: 200px;
123+
}
124+
.ipsum {
125+
padding: 0px;
126+
}
127+
{% endminify %}
128+
</style>
129+
130+
<script>
131+
{% minify js %}
132+
var myFunction = function () {
133+
console.log('Some inline JS');
134+
}
135+
{% endminify %}
136+
</script>
137+
138+
{% minify html %}
139+
<div>
140+
<p>Some html</p>
141+
</div>
142+
{% endminify %}
143+
```
144+
145+
---
146+
147+
## Twig functions
148+
149+
### inline(filename [, remote=false])
150+
151+
See `craft.toolmate.inline`.
152+
153+
### stamp(filename [, mode = 'file', type = 'ts'])
154+
155+
See `craft.toolmate.stamp`.
156+
157+
### setCookie(params [, secure = false])
158+
159+
See `craft.toolmate.setCookie`.
160+
161+
### getCookie(name [, secure = false])
162+
163+
See `craft.toolmate.getCookie`.
164+
165+
### getVideoEmbed(url [, params = []])
166+
167+
See `craft.toolmate.getCookie`.
168+
169+
170+
---
171+
172+
## Price, license and support
173+
174+
The plugin is released under the MIT license. It's made for Værsågod and friends, and no support
175+
is given. Submitted issues are resolved if it scratches an itch.
176+
177+
## Changelog
178+
179+
See [CHANGELOG.MD](https://raw.githubusercontent.com/vaersaagod/toolmate/master/CHANGELOG.md).
180+
181+
## Credits
182+
183+
Brought to you by [Værsågod](https://www.vaersaagod.no)
184+
185+
Icon designed by [Freepik from Flaticon](https://www.flaticon.com/authors/freepik).

composer.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "vaersaagod/toolmate",
3+
"description": "Is that a tool in your pocket, or are you just happy to see me, mate?",
4+
"type": "craft-plugin",
5+
"version": "1.0.0",
6+
"keywords": [
7+
"craft",
8+
"cms",
9+
"craftcms",
10+
"craft-plugin",
11+
"mate",
12+
"inline",
13+
"timestamp",
14+
"cookies",
15+
"minify",
16+
"workflow"
17+
],
18+
"support": {
19+
"docs": "https://github.com/vaersaagod/toolmate/blob/master/README.md",
20+
"issues": "https://github.com/vaersaagod/toolmate/issues"
21+
},
22+
"license": "MIT",
23+
"authors": [
24+
{
25+
"name": "Værsågod",
26+
"homepage": "https://www.vaersaagod.no/"
27+
}
28+
],
29+
"require": {
30+
"craftcms/cms": "^3.1.0",
31+
"matthiasmullie/minify": "^1.3.0",
32+
"voku/html-min": "^4.4.0"
33+
},
34+
"autoload": {
35+
"psr-4": {
36+
"vaersaagod\\toolmate\\": "src/"
37+
}
38+
},
39+
"extra": {
40+
"name": "ToolMate",
41+
"handle": "toolmate",
42+
"hasCpSettings": false,
43+
"hasCpSection": false,
44+
"changelogUrl": "https://raw.githubusercontent.com/vaersaagod/toolmate/master/CHANGELOG.md",
45+
"components": {},
46+
"class": "vaersaagod\\toolmate\\ToolMate"
47+
}
48+
}

resources/plugin_logo.png

17.6 KB
Loading

src/ToolMate.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
namespace vaersaagod\toolmate;
4+
5+
use Craft;
6+
use craft\base\Plugin;
7+
use craft\web\twig\variables\CraftVariable;
8+
9+
use vaersaagod\toolmate\services\EmbedService;
10+
use vaersaagod\toolmate\services\MinifyService;
11+
use vaersaagod\toolmate\services\ToolService;
12+
use vaersaagod\toolmate\variables\ToolMateVariable;
13+
use vaersaagod\toolmate\twigextensions\ToolMateTwigExtension;
14+
use vaersaagod\toolmate\models\Settings;
15+
16+
use yii\base\Event;
17+
18+
/**
19+
* @author Værsågod
20+
* @package PluginMate
21+
* @since 1.0.0
22+
*
23+
* @property EmbedService $embed
24+
* @property ToolService $tool
25+
* @property Settings $settings
26+
* @method Settings getSettings()
27+
*/
28+
class ToolMate extends Plugin
29+
{
30+
// Static Properties
31+
// =========================================================================
32+
33+
/**
34+
* @var ToolMate
35+
*/
36+
public static $plugin;
37+
38+
// Public Properties
39+
// =========================================================================
40+
41+
/**
42+
* @var string
43+
*/
44+
public $schemaVersion = '1.0.0';
45+
46+
// Public Methods
47+
// =========================================================================
48+
49+
public function init()
50+
{
51+
parent::init();
52+
53+
self::$plugin = $this;
54+
55+
// Register services
56+
$this->setComponents([
57+
'embed' => EmbedService::class,
58+
'tool' => ToolService::class,
59+
'minify' => MinifyService::class,
60+
]);
61+
62+
// Register tamplate variables
63+
Event::on(
64+
CraftVariable::class,
65+
CraftVariable::EVENT_INIT,
66+
static function (Event $event) {
67+
/** @var CraftVariable $variable */
68+
$variable = $event->sender;
69+
$variable->set('toolmate', ToolMateVariable::class);
70+
$variable->set('tool', ToolMateVariable::class);
71+
}
72+
);
73+
74+
// Add in our Twig extensions
75+
Craft::$app->view->registerTwigExtension(new ToolMateTwigExtension());
76+
}
77+
78+
// Protected Methods
79+
// =========================================================================
80+
81+
/**
82+
* Creates and returns the model used to store the plugin’s settings.
83+
*
84+
* @return \craft\base\Model|null
85+
*/
86+
protected function createSettingsModel()
87+
{
88+
return new Settings();
89+
}
90+
}

0 commit comments

Comments
 (0)