Skip to content
Browse files

Fixed Minify namespacing. Moved generic utils into new ns.

  • Loading branch information...
1 parent 1e2685e commit 57ddfff30c370e41fe78e8483457bfdde886918e @warmans committed Feb 17, 2012
View
51 application/Bootstrap.php
@@ -26,6 +26,7 @@ public function _initErrors(){
public function _initNamespaces(){
Yaf_Loader::getInstance()->registerLocalNameSpace(array("Zend"));
+ Yaf_Loader::getInstance()->registerLocalNameSpace(array("Eyaf"));
}
public function _initRoutes(){
@@ -65,65 +66,19 @@ public function _initLayout(Yaf_Dispatcher $dispatcher){
}
public function _initCssMinifier(){
- $minifier = new Minify(new Minify_Strategy_Css());
+ $minifier = new Eyaf_Minify(new Eyaf_Minify_Strategy_Css());
$minifier->minifyDir(
$this->_config->static->css->sourceDir,
$this->_config->static->css->minDir
);
}
public function _initJsMinifier(){
- $minifier = new Minify(new Minify_Strategy_Js());
+ $minifier = new Eyaf_Minify(new Eyaf_Minify_Strategy_Js());
$minifier->minifyDir(
$this->_config->static->js->sourceDir,
$this->_config->static->js->minDir
);
}
- /*
- private function _minifyStatic($inDir, $outDir, $minifierStrategy){
-
- $buildFileLocation = $outDir.'build.last';
- $lastModified = 0;
- $buildTime = (is_file($buildFileLocation)) ? file_get_contents($buildFileLocation) : 0;
-
- //get dir handle
- $cssFiles = new RecursiveIteratorIterator(
- new RecursiveDirectoryIterator($inDir, FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS),
- RecursiveIteratorIterator::CHILD_FIRST
- );
-
- //stat files (once every 10 seconds max)
- if($buildTime > 0 && $buildTime < time()-10){
- foreach($cssFiles as $fileInfo):
- $lastModified = ($fileInfo->getMTime() > $lastModified)
- ? $fileInfo->getMTime()
- : $lastModified;
- endforeach;
- }
-
- //rebuild required?
- if($lastModified > $buildTime || ($lastModified === 0 && $buildTime === 0)){
- $minifier = new Minify($minifierStrategy);
-
- //re-create private folder structure and files
- foreach($cssFiles as $fileInfo):
-
- $itemPath = $outDir.$fileInfo->getFilename();
-
- switch (TRUE):
- case $fileInfo->isFile():
- $minifier->loadFile($fileInfo->getRealPath());
- file_put_contents($itemPath, $minifier->minify());
- break;
- case $fileInfo->isDir():
- mkdir($itemPath);
- break;
- endswitch;
- endforeach;
-
- //update last build time
- file_put_contents($buildFileLocation, time());
- }
- }*/
}
View
4 library/Minify.php → library/Eyaf/Minify.php
@@ -1,9 +1,9 @@
<?php
-class Minify {
+class Eyaf_Minify {
private $_strategy;
- public function __construct(Minify_Strategy_Abstract $strategy) {
+ public function __construct(Eyaf_Minify_Strategy_Abstract $strategy) {
$this->_strategy = $strategy;
}
View
6 library/Eyaf/Minify/Strategy/Abstract.php
@@ -0,0 +1,6 @@
+<?php
+abstract class Eyaf_Minify_Strategy_Abstract {
+
+ abstract public function minify($content);
+
+}
View
12 library/Eyaf/Minify/Strategy/Css.php
@@ -0,0 +1,12 @@
+<?php
+class Eyaf_Minify_Strategy_Css extends Eyaf_Minify_Strategy_Abstract {
+
+ public function minify($content){
+
+ $content = Eyaf_Minify_Util_Comments::stripBlockComments($content);
+ $content = Eyaf_Minify_Util_Whitespace::stripAll($content);
+ return $content;
+
+ }
+
+}
View
2 library/Minify/Strategy/Js.php → library/Eyaf/Minify/Strategy/Js.php
@@ -1,5 +1,5 @@
<?php
-class Minify_Strategy_Js extends Minify_Strategy_Abstract {
+class Eyaf_Minify_Strategy_Js extends Eyaf_Minify_Strategy_Abstract {
public function minify($content){
return $content;
View
11 library/Eyaf/Minify/Util/Comments.php
@@ -0,0 +1,11 @@
+<?php
+abstract class Eyaf_Minify_Util_Comments {
+
+ public static function stripSlashComments($content){
+ return preg_replace('#\/\/.*?\n#is', '', $content);
+ }
+
+ public static function stripBlockComments($content){
+ return preg_replace('#\/\*.*?\*\/#is', '', $content);
+ }
+}
View
16 library/Eyaf/Minify/Util/Whitespace.php
@@ -0,0 +1,16 @@
+<?php
+abstract class Eyaf_Minify_Util_Whitespace {
+
+ public static function stripAll($content){
+ //standardise line endings
+ $content = str_replace("\n\r", "\n", $content);
+ //replace tabs with nothing
+ $content = preg_replace('#\t#', '', $content);
+ //replace newlines with spaces
+ $content = preg_replace('#\n#', ' ', $content);
+ //collapse spaces to one space
+ $content = preg_replace('#\s+#', ' ', $content);
+ return $content;
+ }
+
+}
View
26 library/Minify/Strategy/Abstract.php
@@ -1,26 +0,0 @@
-<?php
-abstract class Minify_Strategy_Abstract {
-
- protected $_content;
-
- abstract public function minify($content);
-
- protected function _stripComments($content){
- //block comments
- $content = preg_replace('#\/\*.*?\*\/#is', '', $content);
- //slash comments
- $content = preg_replace('#\/\/.*?\n#is', '', $content);
-
- return $content;
- }
-
- protected function _stripWhitespace($content){
- //replace tabs with nothing
- $content = preg_replace('#\t#', '', $content);
- //replace newlines with spaces
- $content = preg_replace('#\n#', ' ', $content);
- //collapse spaces to one space
- $content = preg_replace('#\s+#', ' ', $content);
- return $content;
- }
-}
View
10 library/Minify/Strategy/Css.php
@@ -1,10 +0,0 @@
-<?php
-class Minify_Strategy_Css extends Minify_Strategy_Abstract {
-
- public function minify($content){
- $content = $this->_stripComments($content);
- $content = $this->_stripWhitespace($content);
- return $content;
- }
-
-}
View
2 public/static/min/css/build.last
@@ -1 +1 @@
-1329436390
+1329505445
View
2 public/static/min/css/screen.css
@@ -1 +1 @@
-@import 'something.css'; h1,h2, h3 { color : #00f; } p { letter-spacing : 2px; }
+ @import 'something.css'; h1,h2, h3 { color : #00f; } p { letter-spacing : 2px; }
View
10 public/static/source/css/screen.css
@@ -1,3 +1,5 @@
+/*css title*/
+
@import 'something.css';
/*headings*/
@@ -8,10 +10,4 @@ h1,h2, h3 {
/*paragraphs*/
p {
letter-spacing : 2px;
-}
-
-/*
-a {
- text-decoration: none;
-}
-*/
+}

0 comments on commit 57ddfff

Please sign in to comment.
Something went wrong with that request. Please try again.