peteboere / css-crush

CSS preprocessor.
http://the-echoplex.net/csscrush
MIT License
537 stars 51 forks source link

Add a new method inline #18

Closed AnonSphere closed 12 years ago

AnonSphere commented 12 years ago

Beside file and tag there should be an option for inline display, as page speed and yslow recommend it for smaller css files:

/**
 * Process host CSS file and return the compiled css
 *
 * @param string $file  Absolute or relative path to the host CSS file
 * @param mixed $options  An array of options or null
 * @param array $attributes  An array of HTML attributes
 * @return string  HTML stylesheet or error message inside HTML comment
 */
public static function inline ( $file, $options = null, $attributes = array() ) {
    $config = self::$config;
    $file = self::file( $file, $options );
    if ( !empty( $file ) ) {
        // On success return the complete stylesheet
        $attr_string = '';
        foreach ( $attributes as $name => $value ) {
            $value = htmlspecialchars( $value, ENT_COMPAT, 'UTF-8', false );
            $attr_string .= " $name=\"$value\"";
        }
        return "<style$attr_string>" . file_get_contents( "$config->baseDir/" . self::$compileName ) . "</style>\n";
    }
    else {
        // Return an HTML comment with message on failure
        $class = __CLASS__;
        return "<!-- $class: File $file not found -->\n";
    }
}
peteboere commented 12 years ago

Good idea, thanks.

Will include in next release.