Created
August 13, 2012 15:34
-
-
Save richthegeek/3341930 to your computer and use it in GitHub Desktop.
Automatic SASS/SCSS compilation with PHPSass and Apache2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Action compile-sass /git/phpsass/compile-apache.php | |
AddHandler compile-sass .sass .scss |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
These two files can be used to automatically compile files using PHPSass; It assumes that you place compile-apache.php in the same dir as SassParser.php (the root of PHPSass) and that PHPSass lives in /WEBROOT/git/phpsass. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-type: text/css'); | |
require_once './SassParser.php'; | |
function warn($text, $context) { | |
print "/** WARN: $text, on line {$context->node->token->line} of {$context->node->token->filename} **/\n"; | |
} | |
function debug($text, $context) { | |
print "/** DEBUG: $text, on line {$context->node->token->line} of {$context->node->token->filename} **/\n"; | |
} | |
$file = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['PATH_INFO']; | |
$syntax = substr($file, -4, 4); | |
$options = array( | |
'style' => 'expanded', | |
'cache' => FALSE, | |
'syntax' => $syntax, | |
'debug' => FALSE, | |
'callbacks' => array( | |
'warn' => 'warn', | |
'debug' => 'debug' | |
), | |
); | |
// Execute the compiler. | |
$parser = new SassParser($options); | |
try { | |
print "\n\n" . $parser->toCss($file); | |
} catch (Exception $e) { | |
print $e->getMessage(); | |
} |
Getting "The requested URL /lib/phpsass/compile-apache.php/api/ajax/css/main.scss was not found on this server.". Note that I put my files in WEBROOT/lib , not WEBROOT/git. SCSS file is in WEBROOT/api/ajax/css/main.scss. Accessing by http://domain/api/ajax/css/main.scss. If I turn off the handler I see the raw SCSS file. Any ideas?
hmm this don't work for me its all activated and got the right paths but it does not compiling :/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forgot to mention, you need mod_actions for this to work:
sudo a2enmod actions && sudo service apache2 restart