<?php
/**
 * Minify CSS Preprocessor class file
 *
 * @package Holograph
 */

namespace Holograph\Preprocessor\Css;

use Holograph\Preprocessor\PreprocessorAbstract;
use Holograph\FileOps;

/**
 * Class to minify and combine Css files
 *
 * @package Holograph
 * @author Jansen Price <jansen.price@gmail.com>
 * @version $Id$
 */
class Minify extends PreprocessorAbstract
{
    /**
     * Execute preprocessor
     *
     * This will take all CSS files from the source dir, minify each one and 
     * then combine them into one file.
     *
     * @param array $options Options for execution
     * @return void
     */
    public function execute($options = array())
    {
        $cssFiles = FileOps::rglob("*.css", 0, $this->getSourceDir());

        if (empty($cssFiles)) {
            return false;
        }

        FileOps::ensurePathExists($this->getDestinationDir());

        $mainStylesheet = $options['main_stylesheet'];

        $buffer = array();
        foreach ($cssFiles as $file) {
            $content = file_get_contents($file);

            $newContent = \Minify_CSS_Compressor::process($content);

            $newfile = str_replace(
                $this->getSourceDir(),
                $this->getDestinationDir(),
                $file
            );

            $buffer[] = $newContent;
        }

        if ($buffer) {
            file_put_contents($mainStylesheet, implode("\n", $buffer));
        }
    }
}

<?php
/**
 * Minify CSS Preprocessor class file
 *
 * @package Holograph
 */

namespace Holograph\Preprocessor\Css;

use Holograph\Preprocessor\PreprocessorAbstract;
use Holograph\FileOps;

/**
 * Class to minify and combine Css files
 *
 * @package Holograph
 * @author Jansen Price <jansen.price@gmail.com>
 * @version $Id$
 */
class Minify extends PreprocessorAbstract
{
    /**
     * Execute preprocessor
     *
     * This will take all CSS files from the source dir, minify each one and 
     * then combine them into one file.
     *
     * @param array $options Options for execution
     * @return void
     */
    public function execute($options = array())
    {
        $cssFiles = FileOps::rglob("*.css", 0, $this->getSourceDir());

        if (empty($cssFiles)) {
            return false;
        }

        FileOps::ensurePathExists($this->getDestinationDir());

        // Just get the basename of the main style sheet, this will be written 
        // to the destination dir
        $mainStylesheet = basename($options['main_stylesheet']);
        $mainStylesheet = $this->getDestinationDir() . DIRECTORY_SEPARATOR . $mainStylesheet;

        $buffer = array();
        foreach ($cssFiles as $file) {
            $content = file_get_contents($file);

            $newContent = \Minify_CSS_Compressor::process($content);

            $buffer[] = $newContent;
        }

        if ($buffer) {
            file_put_contents($mainStylesheet, implode("\n", $buffer));
        }
    }
}

Update minifier to write to build file more smartly
Update minifier to write to build file more smartly

This handles cases where the main stylesheet is referenced from a
subdir or different directory from the root of index.html, but
still allow the minifier to write to the file using a different path
(for example outside of the webroot).
