scssphp is a compiler for SCSS written in PHP.
SCSS is a CSS preprocessor that adds many features like variables, mixins, imports, color manipulation, functions, and tons of other powerful features.
The entire compiler comes in a single class file ready for including in any kind of project in addition to a command line tool for running the compiler from the terminal.
scssphp implements SCSS (3.2.12). It does not implement the SASS syntax, only the SCSS syntax.
Follow the author on twitter: @moonscript.
You can always download the latest version here:
scssphp-0.0.12.tar.gz
You can also find the latest source online:
https://github.com/leafo/scssphp/
If you use Packagist for installing packages, then you can update your composer.json
like so:
{
"require": {
"leafo/scssphp": "0.0.12"
}
}
For a complete guide to the syntax of SCSS, consult the official documentation.
Complete documentation for scssphp is located at http://leafo.net/scssphp/docs/.
If you just want to start serving compiled scss
files as quick as possible
then start here.
scssphp comes with a easy to use class that automatically compiles modified
scss
files and serves them from a directory you specify.
Create a file, like style.php
:
<?php
$directory = "stylesheets";
require "scssphp/scss.inc.php";
scss_server::serveFrom($directory);
Create the directory set in the script alongside the script, then add your
scss
files to it.
If we've got a file in there called style.scss
, then we just need to hit the
url: example.com/style.php/style.scss
to get the compiled css.
If there is an error compiling, the url will result in a 500
error with the
error message. If the file can’t be found, then a friendly 404
is returned.
scssphp will automatically create a scss_cache
directory inside the
stylesheets directory where it will cache the compiled output. This way it can
quickly serve the files if no modifications have been made. Your PHP script
must have permission to write in scss_cache
.
If you're interested in directly using the compiler, then all you need to do is
require scss.inc.php
and invoke the scss
class:
<?php
require "scssphp/scss.inc.php";
$scss = new scssc();
echo $scss->compile('
$color: #abc;
div { color: lighten($color, 20%); }
');
The compile
method takes SCSS
as a string, and returns the CSS
. If there
is an error when compiling then an exception is thrown with an appropriate
message.
For a more detailed guide consult http://leafo.net/scssphp/docs/.
Find any issues? I'd love to fix them for you, post about them on the issues tracker.
@media
(Anthon Pang)@extends
(Anthon Pang)null
(Anthon Pang)ie_hex_str
, abs
, min
, max
functions (Martin Hasoň)calc()
(Martin Hasoň)@content
support.