From 17752f71b37cc9b92a7d5d9db25fc478fc378a17 Mon Sep 17 00:00:00 2001 From: Joshua Sherman Date: Thu, 2 Jan 2014 22:39:19 -0500 Subject: [PATCH] More composer stuff, updated compile / minify logic Now using composer installed apps for less and scss files. --- classes/Dynamic.php | 48 +++++++++---------- composer.json | 4 +- composer.lock | 89 ++++++++++++++++++++++++++++++++++- tests/classes/DynamicTest.php | 13 ----- 4 files changed, 113 insertions(+), 41 deletions(-) diff --git a/classes/Dynamic.php b/classes/Dynamic.php index 98f0a24..42453d7 100644 --- a/classes/Dynamic.php +++ b/classes/Dynamic.php @@ -150,37 +150,33 @@ class Dynamic extends Object { $reference = $original_reference; - // @todo LESS and SASS compiling should happen regardless of minification - if ($this->config->pickles['minify'] === true) + // Compiles LESS & SASS to CSS before minifying + if ($less || $sass) { - // Compiles LESS & SASS to CSS before minifying - if ($less || $sass) + $compiled_filename = str_replace('.min', '', $minified_filename); + + require_once $this->config->pickles['path'] . '.composer/autoload.php'; + + if ($less) { - $compiled_filename = str_replace('.min', '', $minified_filename); + $less = new lessc(); + $less->compileFile($original_filename, $compiled_filename); + } + elseif ($sass) + { + $scss = new scssc(); - if ($less) - { - // I couldn't get getenv() to give me the PATH value... so yeah, there's that. - exec('echo $PATH', $path); - putenv('PATH=' . $path[0] . PATH_SEPARATOR . '/usr/local/bin'); - - $command = 'lessc ' . $original_filename . ' > ' . $compiled_filename; - } - elseif ($sass) - { - $command = 'sass ' . $original_filename . ':' . $compiled_filename; - } - - exec($command, $output, $return); - - if ($return !== 0) - { - throw new Exception('There was an error executing `' . $command . '` it returned exit code ' . $return); - } - - $original_filename = $compiled_filename; + file_put_contents( + $compiled_filename, + $scss->compile(file_get_contents($original_filename)) + ); } + $original_filename = $compiled_filename; + } + + if ($this->config->pickles['minify'] === true) + { // Minifies CSS with a few basic character replacements. $stylesheet = file_get_contents($original_filename); $stylesheet = str_replace(array("\t", "\n", ', ', ' {', ': ', ';}', '{ ', '; '), array('', '', ',', '{', ':', '}', '{', ';'), $stylesheet); diff --git a/composer.json b/composer.json index 7c45ec0..73adf8a 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,8 @@ "vendor-dir": ".composer" }, "require": { - "mikey179/vfsStream": "1.2.0" + "mikey179/vfsStream": "1.2.0", + "leafo/lessphp": "0.4.0", + "leafo/scssphp": "0.0.9" } } diff --git a/composer.lock b/composer.lock index 510f2e3..5481bb9 100644 --- a/composer.lock +++ b/composer.lock @@ -3,8 +3,95 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "43a9d6fa1fc1d241f48c50222da238c8", + "hash": "9a22b4eaac6e820d8603b95b9f21c33a", "packages": [ + { + "name": "leafo/lessphp", + "version": "v0.4.0", + "source": { + "type": "git", + "url": "https://github.com/leafo/lessphp.git", + "reference": "51f3f06f0fe78a722dabfd14578444bdd078d9de" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/leafo/lessphp/zipball/51f3f06f0fe78a722dabfd14578444bdd078d9de", + "reference": "51f3f06f0fe78a722dabfd14578444bdd078d9de", + "shasum": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.3-dev" + } + }, + "autoload": { + "classmap": [ + "lessc.inc.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT", + "GPL-3.0" + ], + "authors": [ + { + "name": "Leaf Corcoran", + "email": "leafot@gmail.com", + "homepage": "http://leafo.net" + } + ], + "description": "lessphp is a compiler for LESS written in PHP.", + "homepage": "http://leafo.net/lessphp/", + "time": "2013-08-09 17:09:19" + }, + { + "name": "leafo/scssphp", + "version": "v0.0.9", + "source": { + "type": "git", + "url": "https://github.com/leafo/scssphp.git", + "reference": "a06d702ebf9fabb22542bbb27cc12a905813bb6d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/leafo/scssphp/zipball/a06d702ebf9fabb22542bbb27cc12a905813bb6d", + "reference": "a06d702ebf9fabb22542bbb27cc12a905813bb6d", + "shasum": "" + }, + "require": { + "php": ">=5.2.0" + }, + "require-dev": { + "php": ">=5.3.0", + "phpunit/phpunit": "3.7.*" + }, + "bin": [ + "pscss" + ], + "type": "library", + "autoload": { + "classmap": [ + "scss.inc.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT", + "GPL-3.0" + ], + "authors": [ + { + "name": "Leaf Corcoran", + "email": "leafot@gmail.com", + "homepage": "http://leafo.net" + } + ], + "description": "scssphp is a compiler for SCSS written in PHP.", + "homepage": "http://leafo.net/scssphp/", + "time": "2013-12-23 23:28:02" + }, { "name": "mikey179/vfsStream", "version": "v1.2.0", diff --git a/tests/classes/DynamicTest.php b/tests/classes/DynamicTest.php index 6ec87cc..273b572 100644 --- a/tests/classes/DynamicTest.php +++ b/tests/classes/DynamicTest.php @@ -104,19 +104,6 @@ CSS; $this->dynamic->css('/css/invalid'); } - // TODO May not be able to do these two as it would require lessc and sass to not be installed - // TODO Good chance will also fail on Travis due to missing dependencies, will need to work through that - // TODO will probably want to move to the composer available versions of these - public function testCSSCommandErrorLESS() - { - - } - - public function testCSSCommandErrorSASS() - { - - } - public function testCSSWithoutMinify() { $config = Config::getInstance();