Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the workflow for using scssphp?

Tags:

php

sass

I'm trying to migrate my css over to scss for a PHP application, but I'm confused about the proper workflow for generating css files. I'm using scssphp, which is a compiler for scss written in PHP.

In all my pages, I use the following stylesheet: css/mycss.css. I've put the scss version of the stylesheet in css/scss/mycss.scss. When I make changes to the scss file, I compile it locally by entering into my browser:

localhost/mywebsite/style.php/mycss.scss

The style.php file is as follows:

require "vendor/leafo/scssphp/scss.inc.php";
$scss = new scssc();
$directory = "css/scss";
$server = new scss_server($directory,null,$scss);
$server->serve();

This compiles the scss file and writes it to the css/scss/scss_cache folder. The filename is some hash. Here is my resulting directory structure:

style.php
-css
 mycss.css
    -scss
     mycss.scss
        -scss_cache
         4edf7f7bf9238jdsk9281sjkj32.css

Now ideally, I would like for the compiler to overwrite the css/mycss.css file. Is there a way to do this, or what's a proper workflow for replacing the original css file with the newly compiled css? I could always just copy and paste every time, but that doesn't seem very efficient.

like image 479
shimizu Avatar asked Jan 24 '15 18:01

shimizu


1 Answers

scssphp is meant to be used to serve the stylesheets directly. But if you'd like to just use the compiler functionality, you can do that:

require "vendor/leafo/scssphp/scss.inc.php";
$scss = new scssc();

$scssIn = file_get_contents(__DIR__ . '/css/scss/mycss.scss');
$cssOut = $scss->compile($scssIn);
file_put_contents(__DIR__ . '/css/mycss.css', $cssOut);

See http://leafo.net/scssphp/.

like image 72
Jeremiah Winsley Avatar answered Sep 21 '22 22:09

Jeremiah Winsley