From e5a79218c349cbc03dc99004fbad938c7b82391f Mon Sep 17 00:00:00 2001 From: Anthon Pang Date: Fri, 24 May 2013 10:03:41 -0400 Subject: [PATCH] Updating changelog and phpdocs (refs #83) --- scss.inc.php | 101 +++++++++++++++++++++++++++++++++++++++++--------- site/index.md | 15 ++++++++ 2 files changed, 99 insertions(+), 17 deletions(-) diff --git a/scss.inc.php b/scss.inc.php index 01b875ea..ff0493a7 100644 --- a/scss.inc.php +++ b/scss.inc.php @@ -43,7 +43,7 @@ * @author Leaf Corcoran */ class scssc { - static public $VERSION = "v0.0.5"; + static public $VERSION = "v0.0.7"; static protected $operatorNames = array( '+' => "add", @@ -4174,36 +4174,80 @@ public function indentStr($n = 0) { * @author Leaf Corcoran */ class scss_server { - + /** + * Join path components + * + * @param string $left Path component, left of the directory separator + * @param string $right Path component, right of the directory separator + * + * @return string + */ protected function join($left, $right) { - return rtrim($left, "/") . "/" . ltrim($right, "/"); + return rtrim($left, '/\\') . DIRECTORY_SEPARATOR . ltrim($right, '/\\'); } + /** + * Get name of requested .scss file + * + * @return string|null + */ protected function inputName() { - if (isset($_GET["p"])) return $_GET["p"]; - - if (isset($_SERVER["PATH_INFO"])) return $_SERVER["PATH_INFO"]; - if (isset($_SERVER["DOCUMENT_URI"])) { - return substr($_SERVER["DOCUMENT_URI"], strlen($_SERVER["SCRIPT_NAME"])); + switch (true) { + case isset($_GET['p']): + return $_GET['p']; + case isset($_SERVER['PATH_INFO']): + return $_SERVER['PATH_INFO']; + case isset($_SERVER['DOCUMENT_URI']): + return substr($_SERVER['DOCUMENT_URI'], strlen($_SERVER['SCRIPT_NAME'])); } } + /** + * Get path to requested .scss file + * + * @return string + */ protected function findInput() { - if ($input = $this->inputName()) { + if ($input = $this->inputName() + && strpos($input, '..') === false + && substr($input, -5) === '.scss' + ) { $name = $this->join($this->dir, $input); - if (is_readable($name)) return $name; + + if (is_file($name) && is_readable($name)) { + return $name; + } } + return false; } + /** + * Get path to cached .css file + * + * @return string + */ protected function cacheName($fname) { - return $this->join($this->cacheDir, md5($fname) . ".css"); + return $this->join($this->cacheDir, md5($fname) . '.css'); } + /** + * Get path to cached imports + * + * @return string + */ protected function importsCacheName($out) { - return $out . ".imports"; + return $out . '.imports'; } + /** + * Determine whether .scss file needs to be re-compiled. + * + * @param string $in Input path + * @param string $out Output path + * + * @return boolean True if compile required. + */ protected function needsCompile($in, $out) { if (!is_file($out)) return true; @@ -4221,13 +4265,21 @@ protected function needsCompile($in, $out) { return false; } + /** + * Compile .scss file + * + * @param string $in Input path (.scss) + * @param string $out Output path (.css) + * + * @return string + */ protected function compile($in, $out) { $start = microtime(true); $css = $this->scss->compile(file_get_contents($in), $in); $elapsed = round((microtime(true) - $start), 4); $v = scssc::$VERSION; - $t = date("r"); + $t = date('r'); $css = "/* compiled by scssphp $v on $t (${elapsed}s) */\n\n" . $css; file_put_contents($out, $css); @@ -4236,17 +4288,20 @@ protected function compile($in, $out) { return $css; } + /** + * Compile requested scss and serve css. Outputs HTTP response. + */ public function serve() { if ($input = $this->findInput()) { $output = $this->cacheName($input); - header("Content-type: text/css"); + header('Content-type: text/css'); if ($this->needsCompile($input, $output)) { try { echo $this->compile($input, $output); } catch (Exception $e) { header('HTTP/1.1 500 Internal Server Error'); - echo "Parse error: " . $e->getMessage() . "\n"; + echo 'Parse error: ' . $e->getMessage() . "\n"; } } else { header('X-SCSS-Cache: true'); @@ -4257,16 +4312,23 @@ public function serve() { } header('HTTP/1.0 404 Not Found'); - header("Content-type: text"); + header('Content-type: text'); $v = scssc::$VERSION; echo "/* INPUT NOT FOUND scss $v */\n"; } + /** + * Constructor + * + * @param string $dir Root directory to .scss files + * @param string $cacheDir Cache directory + * @param \scssc|null $scss SCSS compiler instance + */ public function __construct($dir, $cacheDir=null, $scss=null) { $this->dir = $dir; if (is_null($cacheDir)) { - $cacheDir = $this->join($dir, "scss_cache"); + $cacheDir = $this->join($dir, 'scss_cache'); } $this->cacheDir = $cacheDir; @@ -4279,6 +4341,11 @@ public function __construct($dir, $cacheDir=null, $scss=null) { $this->scss = $scss; } + /** + * Helper method to serve compiled scss + * + * @param string $path Root path + */ static public function serveFrom($path) { $server = new self($path); $server->serve(); diff --git a/site/index.md b/site/index.md index 847c1fb4..0ecd1008 100644 --- a/site/index.md +++ b/site/index.md @@ -104,6 +104,21 @@ Find any issues? I'd love to fix them for you, post about them on [the issues tr ## Changelog +* **0.0.7** + * Forgot to bump the version number. Re-tagged as v0.0.7. + +* **0.0.6** + * Port various fixes from leafo/lessphp. + * Improve filter precision. + * Parsing large image data-urls does not work. + * Add == and != ops for colors. + * @if and @while directives should treat null like false. + * Add pscss as bin in composer.json (Christian Lück). + * Fix !default bug (James Shannon, Alberto Aldegheri). + * Fix mixin content includes (James Shannon, Christian Brandt). + * Fix passing of varargs to another mixin. + * Fix interpolation bug in expToString() (Matti Jarvinen). + * **0.0.5** -- March 11, 2013 * Better compile time errors * Fix top level properties inside of a nested `@media` (Anthon Pang)