Permalink
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents 6b121a1 + 7a2e0b4 commit 5a0dc9741b71110d4612dd721d37edc57fe8ef03 Anthony Short committed Jul 8, 2010
Showing with 216 additions and 10 deletions.
  1. +114 −0 extensions/Sass/Sass.php
  2. +85 −0 extensions/Template/Template.php
  3. +17 −10 lib/Scaffold/Cache/File.php
View
@@ -0,0 +1,114 @@
+<?php
+/**
+ * Scaffold_Extension_Sass
+ *
+ * Rewrites all URL's in the CSS to absolute paths.
+ *
+ * @package Scaffold
+ * @author Anthony Short <anthonyshort@me.com>
+ * @copyright 2009-2010 Anthony Short. All rights reserved.
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @link https://github.com/anthonyshort/csscaffold/master
+ */
+class Scaffold_Extension_Sass extends Scaffold_Extension
+{
+ /**
+ * Default settings which are used if the configuration
+ * settings from the file aren't set.
+ * @var array
+ */
+ public $_defaults = array(
+
+ 'params' => array(
+
+ // Use the CSS-superset SCSS syntax.
+ 'scss' => true,
+
+ // Output style. Can be nested (default), compact, compressed, or expanded.
+ 'style' => 'expanded',
+
+ // Don't cache to sassc files.
+ 'no-cache' => true,
+
+ // The path to put cached Sass files. Defaults to .sass-cache.
+ 'cache-location' => false,
+
+ // Add a sass import path.
+ 'load-path' => false,
+
+ // Emit extra information in the generated CSS that can be used by the FireSass Firebug plugin.
+ 'debug-info' => false,
+
+ // Emit comments in the generated CSS indicating the corresponding sass line.
+ 'line-numbers' => false
+ ),
+ 'command' => 'sass'
+ );
+
+ /**
+ * Parse the string through the sass command line tool
+ * @author Anthony Short
+ * @param $source
+ * @return string
+ */
+ public function process($source)
+ {
+ $error = array();
+
+ // The path to the cache file we'll use to temporary store the files
+ $path = $this->scaffold->cache->set('sass/'.$source->id,$source->contents,null,false);
+
+ // Temporary file to store the sass output
+ $temp = $this->scaffold->cache->find('sass_cache');
+
+ // Sass will output the final file to the cache
+ $cmd = $this->config['command'].' '.$this->_build_sass_params($this->config['params']) . ' ' . escapeshellcmd($path) . ' '.$temp.' 2>&1';
+ exec($cmd,$output,$return);
+
+ // There's an error
+ if($output !== array())
+ {
+ throw new Scaffold_Extension_Exception('Sass Error',$output[0]);
+ }
+
+ $sass = file_get_contents($temp);
+
+ // Delete the temporary directory contents
+ $this->scaffold->cache->delete('/sass');
+
+ // Set the contents to the source! We're all done!
+ $source->set($sass);
+ }
+
+ /**
+ * Builds the params for the Sass cmd using an array
+ * - true = sets the key. eg 'sass' => true will become --sass
+ * - false = It's ignored
+ * - Any value = Sets the key and value. eg. 'style' => 'nested' will become '--style nested'
+ * @access private
+ * @param $params
+ * @return string
+ */
+ private function _build_sass_params($params)
+ {
+ $return = '';
+
+ foreach($params as $key => $value)
+ {
+ if($value === false)
+ {
+ continue;
+ }
+ elseif($value === true)
+ {
+ $return .= '--'.$key.' ';
+ }
+ else
+ {
+ $return .= '--'.$key.' '.$value.' ';
+ }
+ }
+
+ return $return;
+ }
+}
@@ -0,0 +1,85 @@
+<?php
+/**
+ * Scaffold_Extension_Template
+ *
+ * Make a copy of this file and directory for your own extensions
+ *
+ * @package Scaffold
+ * @author Anthony Short <anthonyshort@me.com>
+ * @copyright 2009-2010 Anthony Short. All rights reserved.
+ * @license http://opensource.org/licenses/bsd-license.php New BSD License
+ * @link https://github.com/anthonyshort/csscaffold/master
+ */
+class Scaffold_Extension_Template extends Scaffold_Extension
+{
+ /**
+ * Default settings which are used if the configuration
+ * settings from the file aren't set.
+ * @var array
+ */
+ public $_defaults = array();
+
+ // =========================================
+ // = Scaffold Hooks [Not all are required] =
+ // =========================================
+
+ /**
+ * @access public
+ * @param $source
+ * @return string
+ */
+ public function initialize($source)
+ {
+
+ }
+
+ /**
+ * @access public
+ * @param $source
+ * @return string
+ */
+ public function pre_format($source)
+ {
+
+ }
+
+ /**
+ * @access public
+ * @param $source
+ * @return string
+ */
+ public function pre_process($source)
+ {
+
+ }
+
+ /**
+ * @access public
+ * @param $source
+ * @return string
+ */
+ public function process($source)
+ {
+
+ }
+
+ /**
+ * @access public
+ * @param $source
+ * @return string
+ */
+ public function post_process($source)
+ {
+
+ }
+
+ /**
+ * @access public
+ * @param $source
+ * @return string
+ */
+ public function post_format($source)
+ {
+
+ }
+}
@@ -83,7 +83,7 @@ public function get($id, $relative_time = false, $default = false)
* @return boolean
* @access public
*/
- public function set($id,$data,$last_modified = null)
+ public function set($id,$data,$last_modified = null,$encode = true)
{
$target = $this->directory.$id;
@@ -92,14 +92,19 @@ public function set($id,$data,$last_modified = null)
$this->create(dirname($id));
}
- # Serialize the data
- $data = json_encode((object) array(
- 'contents' => (is_array($data)) ? serialize($data) : $data,
- 'last_modified' => (isset($last_modified)) ? $last_modified : time(),
- 'expires' => time() + $this->max_age,
- ));
-
- return file_put_contents($target,$data);
+ if($encode === true)
+ {
+ # Serialize the data
+ $data = json_encode((object) array(
+ 'contents' => (is_array($data)) ? serialize($data) : $data,
+ 'last_modified' => (isset($last_modified)) ? $last_modified : time(),
+ 'expires' => time() + $this->max_age,
+ ));
+ }
+
+ file_put_contents($target,$data);
+
+ return $target;
}
/**
@@ -198,7 +203,9 @@ public function find($id)
*/
public function create($path)
{
- // Create the directories inside the cache folder
+ if(is_dir($path))
+ return;
+
$next = "";
foreach(explode('/',$path) as $dir)

0 comments on commit 5a0dc97

Please sign in to comment.