forked from janmarek/WebLoader
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CssMinFilter, JsMinFilter, updated LessFilter + tests
- Loading branch information
Showing
12 changed files
with
208 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WebLoader\Filter; | ||
|
||
use tubalmartin\CssMin\Minifier; | ||
use WebLoader\Compiler; | ||
|
||
class CssMinFilter | ||
{ | ||
|
||
/** | ||
* Minify code | ||
*/ | ||
public function __invoke(string $code, Compiler $compiler, string $file = ''): string | ||
{ | ||
$minifier = new Minifier; | ||
return $minifier->run($code); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WebLoader\Filter; | ||
|
||
use JShrink\Minifier; | ||
use WebLoader\Compiler; | ||
|
||
class JsMinFilter | ||
{ | ||
public function __invoke(string $code, Compiler $compiler, string $file = ''): ?string | ||
{ | ||
$result = Minifier::minify($code); | ||
|
||
if (!$result) { | ||
return null; | ||
} else { | ||
return (string) $result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WebLoader\Test\Filter; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use WebLoader\Compiler; | ||
use WebLoader\DefaultOutputNamingConvention; | ||
use WebLoader\FileCollection; | ||
use WebLoader\Filter\CssMinFilter; | ||
|
||
class CssMinFilterTest extends TestCase | ||
{ | ||
/** @var CssMinFilter */ | ||
private $filter; | ||
|
||
/** @var Compiler */ | ||
private $compiler; | ||
|
||
|
||
protected function setUp(): void | ||
{ | ||
$this->filter = new CssMinFilter(); | ||
|
||
$files = new FileCollection(__DIR__ . '/../fixtures'); | ||
@mkdir($outputDir = __DIR__ . '/../temp/'); | ||
$this->compiler = new Compiler($files, new DefaultOutputNamingConvention(), $outputDir); | ||
} | ||
|
||
|
||
public function testMinify(): void | ||
{ | ||
$file = __DIR__ . '/../fixtures/cssmin.css'; | ||
$minified = $this->filter->__invoke( | ||
(string) file_get_contents($file), | ||
$this->compiler, | ||
$file | ||
); | ||
$this->assertSame(file_get_contents(__DIR__ . '/../fixtures/cssmin.css.expected'), $minified); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WebLoader\Test\Filter; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use WebLoader\Compiler; | ||
use WebLoader\DefaultOutputNamingConvention; | ||
use WebLoader\FileCollection; | ||
use WebLoader\Filter\JsMinFilter; | ||
|
||
class JsMinFilterTest extends TestCase | ||
{ | ||
/** @var JsMinFilter */ | ||
private $filter; | ||
|
||
/** @var Compiler */ | ||
private $compiler; | ||
|
||
|
||
protected function setUp(): void | ||
{ | ||
$this->filter = new JsMinFilter(); | ||
|
||
$files = new FileCollection(__DIR__ . '/../fixtures'); | ||
@mkdir($outputDir = __DIR__ . '/../temp/'); | ||
$this->compiler = new Compiler($files, new DefaultOutputNamingConvention(), $outputDir); | ||
} | ||
|
||
|
||
public function testMinify(): void | ||
{ | ||
$file = __DIR__ . '/../fixtures/jsmin.js'; | ||
$minified = $this->filter->__invoke( | ||
(string) file_get_contents($file), | ||
$this->compiler, | ||
$file | ||
); | ||
$this->assertSame(file_get_contents(__DIR__ . '/../fixtures/jsmin.js.expected'), $minified); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
.clearFix { | ||
display: block; | ||
zoom: 1; | ||
} | ||
.clearFix:after { | ||
content: " "; | ||
display: block; | ||
font-size: 0; | ||
height: 0; | ||
clear: both; | ||
visibility: hidden; | ||
} | ||
div.banners { | ||
display: block; | ||
zoom: 1; | ||
padding: 0 0 20px; | ||
margin: 0 10px; | ||
border-bottom: #f4f4f4 1px solid; | ||
} | ||
div.banners:after { | ||
content: " "; | ||
display: block; | ||
font-size: 0; | ||
height: 0; | ||
clear: both; | ||
visibility: hidden; | ||
} | ||
div.banners > div { | ||
float: left; | ||
width: 610px; | ||
height: 194px; | ||
background: #f9f2e8; | ||
margin: 20px 0 0 20px; | ||
position: relative; | ||
} | ||
div.banners > div h3 { | ||
width: auto; | ||
color: #be2025; | ||
font-weight: 600; | ||
padding: 10px 20px; | ||
margin: 10px 10px 0 10px; | ||
text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); | ||
display: inline-block; | ||
font-size: 24px; | ||
} | ||
div.banners > div h3, | ||
div.banners > div p { | ||
color: #ffffff; | ||
} | ||
div.banners > div p { | ||
font-size: 13px; | ||
max-width: 360px; | ||
padding: 10px; | ||
} | ||
div.banners > div p strong { | ||
font-weight: 600; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.clearFix{display:block;zoom:1}.clearFix:after{content:" ";display:block;font-size:0;height:0;clear:both;visibility:hidden}div.banners{display:block;zoom:1;padding:0 0 20px;margin:0 10px;border-bottom:#f4f4f4 1px solid}div.banners:after{content:" ";display:block;font-size:0;height:0;clear:both;visibility:hidden}div.banners>div{float:left;width:610px;height:194px;background:#f9f2e8;margin:20px 0 0 20px;position:relative}div.banners>div h3{width:auto;color:#be2025;font-weight:600;padding:10px 20px;margin:10px 10px 0;text-shadow:0 2px 0 rgba(0,0,0,.3);display:inline-block;font-size:24px}div.banners>div h3,div.banners>div p{color:#fff}div.banners>div p{font-size:13px;max-width:360px;padding:10px}div.banners>div p strong{font-weight:600} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
;(function() { | ||
window.alert('Hello World!'); | ||
|
||
if (true === false) { | ||
window.alert('Paradox'); | ||
} else { | ||
window.alert('All is well.'); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
;(function(){window.alert('Hello World!');if(true===false){window.alert('Paradox');}else{window.alert('All is well.');}})(); |