|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of HtmlCompress. |
|
5
|
|
|
* |
|
6
|
|
|
** (c) 2014 Cees-Jan Kiewiet |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
namespace WyriHaximus\HtmlCompress\Integrations\Sculpin; |
|
12
|
|
|
|
|
13
|
|
|
use Sculpin\Core\Event\SourceSetEvent; |
|
14
|
|
|
use WyriHaximus\HtmlCompress\Factory; |
|
15
|
|
|
use WyriHaximus\HtmlCompress\Parser; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class Listener |
|
19
|
|
|
* @package WyriHaximus\HtmlCompress\Integrations\Sculpin |
|
20
|
|
|
*/ |
|
21
|
|
|
class Listener |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @param SourceSetEvent $event |
|
25
|
|
|
*/ |
|
26
|
1 |
|
public function onAfterFormatFastest(SourceSetEvent $event) |
|
27
|
|
|
{ |
|
28
|
1 |
|
$parser = Factory::constructFastest(); |
|
29
|
1 |
|
$this->compress($parser, $event); |
|
30
|
1 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param SourceSetEvent $event |
|
34
|
|
|
*/ |
|
35
|
1 |
|
public function onAfterFormat(SourceSetEvent $event) |
|
36
|
|
|
{ |
|
37
|
1 |
|
$parser = Factory::construct(); |
|
38
|
1 |
|
$this->compress($parser, $event); |
|
39
|
1 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param SourceSetEvent $event |
|
43
|
|
|
*/ |
|
44
|
2 |
|
public function onAfterFormatSmallest(SourceSetEvent $event) |
|
45
|
|
|
{ |
|
46
|
2 |
|
$parser = Factory::constructSmallest(); |
|
47
|
2 |
|
$this->compress($parser, $event); |
|
48
|
2 |
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param Parser $parser |
|
52
|
|
|
* @param SourceSetEvent $event |
|
53
|
|
|
*/ |
|
54
|
1 |
|
protected function compress(Parser $parser, SourceSetEvent $event) |
|
55
|
|
|
{ |
|
56
|
1 |
|
foreach ($event->allSources() as $source) { |
|
57
|
1 |
|
$ext = explode('.', $source->filename()); |
|
58
|
1 |
|
$ext = $ext[(count($ext) - 1)]; |
|
59
|
1 |
|
if (in_array( |
|
60
|
1 |
|
$ext, |
|
61
|
|
|
[ |
|
62
|
1 |
|
'html', |
|
63
|
|
|
'md', |
|
64
|
|
|
'markdown', |
|
65
|
|
|
] |
|
66
|
|
|
)) { |
|
67
|
1 |
|
$source->setFormattedContent($parser->compress($source->formattedContent())); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
1 |
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|