diff --git a/composer.json b/composer.json index 8132c16..b82cdab 100644 --- a/composer.json +++ b/composer.json @@ -18,14 +18,11 @@ } ], "require": { - "leafo/scssphp": "dev-master", - "leafo/scssphp-compass": "dev-master", - "leafo/lessphp": "0.4.0", - "coffeescript/coffeescript": "dev-master", "chh/shellwords": "0.1.0", "symfony/finder": "2.3.*", "symfony/filesystem": "2.3.*", - "symfony/http-foundation": "2.3.*" + "symfony/http-foundation": "2.3.*", + "symfony/process": "2.3.*" }, "require-dev": { "phpunit/phpunit": "3.7.*", diff --git a/composer.lock b/composer.lock index 0ef7114..366d6f3 100644 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "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": "6e6cd622d66ff2d395522703399acad2", + "hash": "7e7d07a885b62baa940ef9fadbbe4814", "packages": [ { "name": "chh/shellwords", @@ -35,174 +35,6 @@ "description": "Lame port of Ruby's Shellwords.rb", "time": "2012-12-28 15:47:39" }, - { - "name": "coffeescript/coffeescript", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/alxlit/coffeescript-php.git", - "reference": "30c22332f0514f466638eb71e3219526790c1b93" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/alxlit/coffeescript-php/zipball/30c22332f0514f466638eb71e3219526790c1b93", - "reference": "30c22332f0514f466638eb71e3219526790c1b93", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "autoload": { - "psr-0": { - "CoffeeScript": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Alex Little", - "email": "alxlit@gmail.com", - "homepage": "http://alxlit.name" - } - ], - "description": "A port of the CoffeeScript compiler to PHP.", - "homepage": "http://github.com/alxlit/coffeescript-php", - "keywords": [ - "JS", - "coffee", - "coffeescript", - "javascript" - ], - "time": "2012-12-18 03:52:51" - }, - { - "name": "leafo/lessphp", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/leafo/lessphp.git", - "reference": "c6cd043c94ba2a94ae3eeedc7a4c925302b61252" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/leafo/lessphp/zipball/c6cd043c94ba2a94ae3eeedc7a4c925302b61252", - "reference": "c6cd043c94ba2a94ae3eeedc7a4c925302b61252", - "shasum": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.4.x-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-10-04 15:40:57" - }, - { - "name": "leafo/scssphp", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/leafo/scssphp.git", - "reference": "bc9d6341855877b57741ebdfce7fa5a19ac593f5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/leafo/scssphp/zipball/bc9d6341855877b57741ebdfce7fa5a19ac593f5", - "reference": "bc9d6341855877b57741ebdfce7fa5a19ac593f5", - "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-10-07 18:28:57" - }, - { - "name": "leafo/scssphp-compass", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/afroald/scssphp-compass.git", - "reference": "faf85eb41d240b45acc16db8ce7f8ffb1f6084d8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/afroald/scssphp-compass/zipball/faf85eb41d240b45acc16db8ce7f8ffb1f6084d8", - "reference": "faf85eb41d240b45acc16db8ce7f8ffb1f6084d8", - "shasum": "" - }, - "require": { - "leafo/scssphp": "dev-master" - }, - "type": "library", - "autoload": { - "classmap": [ - "compass.inc.php" - ] - }, - "authors": [ - { - "name": "Leaf Corcoran", - "email": "leafot@gmail.com", - "homepage": "http://leafo.net" - } - ], - "description": "Compass for scssphp", - "homepage": "http://leafo.net/scssphp/", - "support": { - "source": "https://github.com/afroald/scssphp-compass/tree/master" - }, - "time": "2013-09-15 10:52:54" - }, { "name": "symfony/filesystem", "version": "v2.3.6", @@ -346,6 +178,53 @@ "description": "Symfony HttpFoundation Component", "homepage": "http://symfony.com", "time": "2013-09-29 19:41:41" + }, + { + "name": "symfony/process", + "version": "v2.3.6", + "target-dir": "Symfony/Component/Process", + "source": { + "type": "git", + "url": "https://github.com/symfony/Process.git", + "reference": "81191e354fe9dad0451036ccf0fdf283649d3f1e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Process/zipball/81191e354fe9dad0451036ccf0fdf283649d3f1e", + "reference": "81191e354fe9dad0451036ccf0fdf283649d3f1e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Process\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "http://symfony.com", + "time": "2013-10-09 21:17:57" } ], "packages-dev": [ @@ -701,16 +580,16 @@ }, { "name": "phpunit/phpunit", - "version": "3.7.27", + "version": "3.7.28", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "4b024e753e3421837afbcca962c8724c58b39376" + "reference": "3b97c8492bcafbabe6b6fbd2ab35f2f04d932a8d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/4b024e753e3421837afbcca962c8724c58b39376", - "reference": "4b024e753e3421837afbcca962c8724c58b39376", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3b97c8492bcafbabe6b6fbd2ab35f2f04d932a8d", + "reference": "3b97c8492bcafbabe6b6fbd2ab35f2f04d932a8d", "shasum": "" }, "require": { @@ -771,7 +650,7 @@ "testing", "xunit" ], - "time": "2013-09-16 03:09:52" + "time": "2013-10-17 07:27:40" }, { "name": "phpunit/phpunit-mock-objects", @@ -930,12 +809,9 @@ ], "minimum-stability": "stable", - "stability-flags": { - "leafo/scssphp": 20, - "leafo/scssphp-compass": 20, - "leafo/lessphp": 20, - "coffeescript/coffeescript": 20 - }, + "stability-flags": [ + + ], "platform": [ ], diff --git a/src/Sprockets/Asset.php b/src/Sprockets/Asset.php index 3330040..fd171fb 100644 --- a/src/Sprockets/Asset.php +++ b/src/Sprockets/Asset.php @@ -90,12 +90,12 @@ public function logicalPathname() public function path() { - return $this->source->getPath(); + return $this->source->getPathInfo()->getRealPath(); } public function pathname() { - return $this->source->getPathname(); + return $this->source->getRealPath(); } /** @@ -235,12 +235,10 @@ protected function process() // We want to run all the processors on the file without the directives included. $content = $this->directiveProcessor()->body(); - // Run pre-processors - // Run engines foreach ($this->extensions() as $extension) { - $engine = $this->pipeline->engine($extension); + $engine = $this->pipeline->filters->engine($extension); if ($engine) { @@ -248,8 +246,6 @@ protected function process() } } - // Run post-processors - $this->processedContent = $content; } @@ -281,6 +277,8 @@ protected function bundle() $content.= $this->body(); } + // Run compressors + $this->bundledContent = $content; } } \ No newline at end of file diff --git a/src/Sprockets/Engine/CoffeeScriptEngine.php b/src/Sprockets/Engine/CoffeeScriptEngine.php deleted file mode 100644 index 771ed6e..0000000 --- a/src/Sprockets/Engine/CoffeeScriptEngine.php +++ /dev/null @@ -1,15 +0,0 @@ - 'asset pipeline', - 'header' => false - )); - } -} \ No newline at end of file diff --git a/src/Sprockets/Engine/LessEngine.php b/src/Sprockets/Engine/LessEngine.php deleted file mode 100644 index 17b2490..0000000 --- a/src/Sprockets/Engine/LessEngine.php +++ /dev/null @@ -1,14 +0,0 @@ -addImportDir($asset->path()); - - return $compiler->compile($content); - } -} \ No newline at end of file diff --git a/src/Sprockets/Engine/ScssEngine.php b/src/Sprockets/Engine/ScssEngine.php deleted file mode 100644 index 4542014..0000000 --- a/src/Sprockets/Engine/ScssEngine.php +++ /dev/null @@ -1,14 +0,0 @@ -compile($content); - } -} \ No newline at end of file diff --git a/src/Sprockets/Filter/BaseProcessFilter.php b/src/Sprockets/Filter/BaseProcessFilter.php new file mode 100644 index 0000000..3982c0b --- /dev/null +++ b/src/Sprockets/Filter/BaseProcessFilter.php @@ -0,0 +1,27 @@ +put($content); + + $builder = new ProcessBuilder($this->command($asset, $tmpFile)); + $process = $builder->getProcess(); + $process->run(); + + if (!$process->isSuccessful()) + { + throw new RuntimeException($process->getErrorOutput()); + } + + return $process->getOutput(); + } + +} \ No newline at end of file diff --git a/src/Sprockets/Filter/CoffeeScriptFilter.php b/src/Sprockets/Filter/CoffeeScriptFilter.php new file mode 100644 index 0000000..8ca7d26 --- /dev/null +++ b/src/Sprockets/Filter/CoffeeScriptFilter.php @@ -0,0 +1,10 @@ +getRealPath()); + } + +} \ No newline at end of file diff --git a/src/Sprockets/Filter/FilterInterface.php b/src/Sprockets/Filter/FilterInterface.php new file mode 100644 index 0000000..a8c70ac --- /dev/null +++ b/src/Sprockets/Filter/FilterInterface.php @@ -0,0 +1,7 @@ +path}", + "--include-path={$asset->path}", + $tmpFile->getRealPath() + ); + } + +} \ No newline at end of file diff --git a/src/Sprockets/Filter/ScssFilter.php b/src/Sprockets/Filter/ScssFilter.php new file mode 100644 index 0000000..5f43d72 --- /dev/null +++ b/src/Sprockets/Filter/ScssFilter.php @@ -0,0 +1,20 @@ +path, + $tmpFile->getRealPath() + ); + } + +} \ No newline at end of file diff --git a/src/Sprockets/FilterManager.php b/src/Sprockets/FilterManager.php new file mode 100644 index 0000000..49e8227 --- /dev/null +++ b/src/Sprockets/FilterManager.php @@ -0,0 +1,83 @@ +engineCreators[$extension]; + $engine = is_callable($creator) ? $creator() : $creator; + + if ($engine) + { + $this->engines[$extension] = $engine; + } + } + + public function registerEngine($extension, $creator) + { + $this->engineCreators[$extension] = $creator; + } + + public function hasEngine($extension) + { + return array_key_exists($extension, $this->engineCreators); + } + + public function engine($extension) + { + if (!$this->hasEngine($extension)) + { + return null; + } + + if (!array_key_exists($extension, $this->engines)) + { + $this->createEngine($extension); + } + + return $this->engines[$extension]; + } + + protected function createCompressor($mimeType) + { + $creator = $this->engineCreators[$mimeType]; + + $compressor = is_callable($creator) ? $creator() : $creator; + + if ($compressor) + { + $this->compressors[$mimeType] = $compressor; + } + } + + public function registerCompressor($mimeType, $creator) + { + $this->compressorCreators[$mimeType] = $creator; + } + + public function hasCompressor($mimeType) + { + return array_key_exists($mimeType, $this->compressorCreators); + } + + public function compressor($mimeType) + { + if (!$this->hasCompressor($mimeType)) + { + return null; + } + + if (!array_key_exists($mimeType, $this->compressors)) + { + $this->createCompressor($mimeType); + } + + return $this->compressors[$mimeType]; + } + +} \ No newline at end of file diff --git a/src/Sprockets/Pipeline.php b/src/Sprockets/Pipeline.php index 0f870ff..e588c4b 100644 --- a/src/Sprockets/Pipeline.php +++ b/src/Sprockets/Pipeline.php @@ -1,11 +1,12 @@ 'text/css', 'js' => 'application/javascript', - 'eot' => 'application/vnd.ms-fontobject', - 'ttf' => 'application/octet-stream', + 'ttf' => 'application/x-font-ttf', + 'otf' => 'application/font-otf', + 'eot' => 'application/octet-stream', 'woff' => 'application/font-woff' ); - protected $preProcessors = array(); - protected $postProcessors = array(); - protected $engines = array(); - protected $compressors = array(); - protected $assets = array(); public function __construct(array $loadPaths, $cachePath = null) @@ -32,10 +29,9 @@ public function __construct(array $loadPaths, $cachePath = null) $this->finder = new Finder($loadPaths); $this->assetCache = new Asset\Cache($cachePath); + $this->filters = new FilterManager; - $this->registerEngine('coffee', new Engine\CoffeeScriptEngine($this)); - $this->registerEngine('scss', new Engine\ScssEngine($this)); - $this->registerEngine('less', new Engine\LessEngine($this)); + $this->registerDefaultFilters(); } public function asset($logicalPath, $type = null) @@ -93,24 +89,24 @@ public function guessMimeType(Asset $asset) public function canProcess(Asset $asset) { - $engineKeys = array_merge(array_keys($this->engines), array('js', 'css')); + if (count(array_intersect(array('js', 'css'), $asset->extensions())) > 0) + { + return true; + } - return count(array_intersect($engineKeys, $asset->extensions())) > 0; - } + $filters = $this->filters; - public function mimeTypes() - { - return $this->mimeTypes; - } + $assetFilters = array_filter($asset->extensions(), function($extension) use ($filters) + { + return $filters->hasEngine($extension) || $filters->hasCompressor($extension); + }); - public function engine($extension) - { - return array_key_exists($extension, $this->engines) ? $this->engines[$extension] : null; + return count($assetFilters) > 0; } - public function engines() + public function mimeTypes() { - return $this->engines; + return $this->mimeTypes; } public function registerMimeType($mimeType, $extension) @@ -118,33 +114,10 @@ public function registerMimeType($mimeType, $extension) $this->mimeTypes[$extension] = $mimeType; } - public function registerPreProcessor($mimeType, $class) - { - if (!array_key_exists($mimeType, $this->preProcessors) or !is_array($this->preProcessors[$mimeType])) - { - $this->preProcessors[$mimeType] = array(); - } - - $this->preProcessors[$mimeType][] = $class; - } - - public function registerPostProcessor($mimeType, $class) - { - - } - - public function registerEngine($extension, $class) - { - $this->engines[$extension] = $class; - } - - public function registerCompressor($mimeType, $id, $class) + protected function registerDefaultFilters() { - if (!array_key_exists($mimeType, $this->compressors) or !is_array($this->compressors[$mimeType])) - { - $this->compressors[$mimeType] = array(); - } - - $this->compressors[$mimeType][$id] = $class; + $this->filters->registerEngine('coffee', new Filter\CoffeeScriptFilter()); + $this->filters->registerEngine('scss', new Filter\ScssFilter()); + $this->filters->registerEngine('less', new Filter\LessFilter()); } } \ No newline at end of file diff --git a/src/Sprockets/Processor.php b/src/Sprockets/Processor.php deleted file mode 100644 index ce0eaa3..0000000 --- a/src/Sprockets/Processor.php +++ /dev/null @@ -1,15 +0,0 @@ -pipeline = $pipeline; - } - - public function process(Asset $asset, $content) - { - return $content; - } -} \ No newline at end of file diff --git a/src/Sprockets/ProcessorInterface.php b/src/Sprockets/ProcessorInterface.php deleted file mode 100644 index c64122f..0000000 --- a/src/Sprockets/ProcessorInterface.php +++ /dev/null @@ -1,5 +0,0 @@ -isFile()) { + unlink($this->getRealPath()); + } + } +} \ No newline at end of file