Parses {@link http://sass-lang.com/ Sass} files.
Ejemplo n.º 1
0
 protected function runSassTest($input, $output = FALSE, $settings = array())
 {
     $name = $input;
     $path = $this->css_tests_path;
     $output = $path . '/' . ($output ? $output : preg_replace('/\\..+$/', '.css', $input));
     $input = $path . '/' . $input;
     if (!file_exists($input)) {
         return $this->fail('Input file not found - ' . $input);
     }
     if (!file_exists($output)) {
         return $this->fail('Comparison file not found - ' . $output);
     }
     $syntax = explode('.', $input);
     $syntax = array_pop($syntax);
     $settings = $settings + array('style' => 'nested', 'cache' => FALSE, 'syntax' => $syntax, 'debug' => FALSE, 'debug_info' => FALSE, 'callbacks' => array('debug' => array($this, 'sassParserDebug'), 'warn' => array($this, 'sassParserWarning')));
     $parser = new SassParser($settings);
     $result = $parser->toCss($input);
     $compare = file_get_contents($output);
     if ($compare === FALSE) {
         $this->fail('Unable to load comparison file - ' . $compare);
     }
     $_result = $this->trimResult($result);
     $_compare = $this->trimResult($compare);
     $this->assertEquals($_result, $_compare, 'Result for ' . $name . ' did not match comparison file');
 }
Ejemplo n.º 2
0
 /**
  * Run the filter
  * @param string text to filter
  * @return string filtered text
  */
 public function run($text)
 {
     $sass = new SassParser();
     $css = new HamlCssFilter();
     $css->init();
     return $css->run($sass->toCss(preg_replace(HamlParser::MATCH_INTERPOLATION, '<?php echo \\1; ?>', $text), false));
 }
Ejemplo n.º 3
0
function __parse($src, $syntax, $style = 'nested')
{
    $options = array('style' => $style, 'cache' => FALSE, 'syntax' => $syntax, 'debug' => FALSE, 'callbacks' => array('warn' => 'cb_warn', 'debug' => 'cb_debug'));
    // Execute the compiler.
    $parser = new SassParser($options);
    return $parser->toCss($src, false);
}
 /**
  * Parse Sass code
  *
  * @param string Source
  * @param array Array of constants
  * @return string
  */
 public static function sass($source, array $constants = array())
 {
     if (!self::$instance instanceof SassParser) {
         self::$instance = new SassParser();
     }
     return self::$instance->setSource($source)->render();
 }
Ejemplo n.º 5
0
 private function _compile_stylesheet($file)
 {
     PerchUtil::debug('Compiling SASS file: ' . $file, 'notice');
     if (!$this->_site_path) {
         $login_path_parts = explode('/', PERCH_LOGINPATH);
         $path_parts = explode(DIRECTORY_SEPARATOR, PERCH_PATH);
         foreach ($login_path_parts as $part) {
             if ($part != '') {
                 array_pop($path_parts);
             }
         }
         $path = implode(DIRECTORY_SEPARATOR, $path_parts);
         $this->_site_path = $path;
     }
     $compiled_name = PerchUtil::file_path(PERCH_RESFILEPATH . '/' . $this->_get_compiled_name($file));
     include_once 'SassParser.php';
     $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 {
         file_put_contents($compiled_name, $parser->toCss(PerchUtil::file_path($this->_site_path . $file)));
     } catch (Exception $e) {
         PerchUtil::debug($e->getMessage(), 'error');
     }
 }
Ejemplo n.º 6
0
 /**
  * Compile the site's CSS.
  */
 public function compile()
 {
     $minify = $this->config->minify;
     $style = $minify ? 'compressed' : 'nested';
     $parser = new \SassParser(['style' => $style]);
     // If we are concatenating files, then open a file pointer
     if ($concatenate = $this->config->concatenate) {
         $output = fopen($this->dest . '/' . $this->config->output, 'w');
     }
     // Loop through each of the input files
     foreach ($this->files as $file) {
         // Get the contents of the file
         $sass = file_get_contents($file);
         $css = $parser->toCss($file);
         // Minify if necessary
         if ($minify) {
             $css = $this->minify($css);
         }
         // If concatenating, write to the file pointer
         if ($concatenate) {
             fwrite($output, $css);
             continue;
         }
         // Replace the file extension
         $file = basename(str_replace('.sass', '.css', $file));
         // Write a new file to the output directory
         file_put_contents($this->dest . '/' . $file, $css);
     }
     // Close the file pointer
     if ($concatenate) {
         fclose($output);
     }
 }
Ejemplo n.º 7
0
 public function compile($file)
 {
     $contents = read_file($file);
     require 'phamlp/sass/SassParser.php';
     $sass = new SassParser(array('style' => 'expanded', 'cache_location' => './assets/.sass-cache', 'extensions' => array('Compass' => array())));
     header('Content-Type: text/css');
     echo $sass->toCss($file);
 }
Ejemplo n.º 8
0
 /**
  * Filters an asset after it has been loaded.
  *
  * @param  \Assetic\Asset\AssetInterface  $asset
  * @return void
  */
 public function filterLoad(AssetInterface $asset)
 {
     $root = $asset->getSourceRoot();
     $path = $asset->getSourcePath();
     $compiler = new \SassParser($this->presets);
     if ($root and $path) {
         $compiler->load_paths = array_merge($compiler->load_paths, array($root . '/' . $path));
     }
     $compiler->load_paths = array_merge($compiler->load_paths, $this->importPaths);
     $asset->setContent($compiler->toCss($asset->getContent(), false));
 }
Ejemplo n.º 9
0
 /**
  * Process asset content
  *
  * @param   string  $content
  * @param   Asset   $asset
  * @return  string
  */
 public static function process($content, Asset $asset)
 {
     // Set error reporting
     $old = error_reporting(E_ALL & ~(E_NOTICE | E_DEPRECATED | E_STRICT));
     // Set SASS
     $sass = new SassParser();
     // Set content
     $content = $sass->toCss($content, false);
     // Set error reporting
     error_reporting($old);
     return $content;
 }
Ejemplo n.º 10
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $in = $this->normalizePath($input->getArgument('fileIn'));
     $out = $this->normalizePath($input->getArgument('fileOut'));
     $sass = new \SassParser();
     try {
         $css = $sass->toCss($in);
         file_put_contents($out, $css);
     } catch (\Exception $e) {
         $output->writeln("<error>fatal error: {$e->getMessage()}</error>");
     }
 }
Ejemplo n.º 11
0
 /**
  * Process asset content
  *
  * @param   string  $content
  * @param   Asset   $asset
  * @return  string
  */
 public static function process($content, Asset $asset)
 {
     // Set error reporting
     $old = error_reporting(E_ALL & ~(E_NOTICE | E_DEPRECATED | E_STRICT));
     // Include the engine
     include_once Kohana::find_file('vendor/PHamlP/sass', 'SassParser');
     // Set SASS
     $sass = new SassParser(array());
     // Set content
     $content = $sass->toCss($content, false);
     // Set error reporting
     error_reporting($old);
     return $content;
 }
Ejemplo n.º 12
0
 /**
  * Returns the parse tree for a file.
  * If caching is enabled a cached version will be used if possible; if not the
  * parsed file will be cached.
  * @param string filename to parse
  * @param array parse options
  * @return SassRootNode
  */
 public static function getTree($filename, $options)
 {
     if ($options['cache']) {
         $cached = self::getCachedFile($filename, $options);
         if ($cached !== false) {
             return $cached;
         }
     }
     $parser = new SassParser($options);
     $tree = $parser->parse($filename);
     if ($options['cache']) {
         self::setCachedFile($tree, $filename, $options);
     }
     return $tree;
 }
Ejemplo n.º 13
0
 /**
  * Returns the parse tree for a file.
  * If caching is enabled a cached version will be used if possible; if not the
  * parsed file will be cached.
  * @param string filename to parse
  * @param SassParser Sass parser
  * @return SassRootNode
  */
 public static function getTree($filename, $parser)
 {
     if ($parser->cache) {
         $cached = self::getCachedFile($filename, $parser->cache_location);
         if ($cached !== false) {
             return $cached;
         }
     }
     $sassParser = new SassParser(array_merge($parser->options, array('line' => 1)));
     $tree = $sassParser->parse($filename);
     if ($parser->cache) {
         self::setCachedFile($tree, $filename, $parser->cache_location);
     }
     return $tree;
 }
Ejemplo n.º 14
0
    public function filter(\Nette\Latte\MacroNode $node, \Nette\Latte\PhpWriter $writer)
    {
        $path = $node->tokenizer->fetchWord();
        $params = $writer->formatArray();
        $path = $this->moduleHelpers->expandPath($path, 'Resources/public');
        if (!$this->debugMode) {
            $sass = new \SassParser();
            $file = new \SplFileInfo($path);
            $targetFile = $file->getBasename() . '-' . md5($path . filemtime($path)) . '.css';
            $targetDir = $this->wwwCacheDir . '/sass';
            $target = $targetDir . '/' . $targetFile;
            $targetUrl = substr($target, strlen($this->wwwDir));
            if (!file_exists($targetDir)) {
                umask(00);
                mkdir($targetDir, 0777, true);
            }
            $css = $sass->toCss($path);
            file_put_contents($target, $css);
            return '$control->getPresenter()->getContext()->getService("assets.assetManager")->addStylesheet("' . $targetUrl . '", ' . $params . '); ';
        } else {
            return '
				$_sass_file = new \\SplFileInfo("' . $path . '");
				$_sass_targetFile = $_sass_file->getBasename() .  \'-\' . md5(\'' . $path . '\') . \'-\' . md5(\'' . $path . '\' . filemtime("' . $path . '")) . \'.css\';
				$_sass_targetDir = \'' . $this->wwwCacheDir . '/sass\';
				$_sass_target = $_sass_targetDir  . \'/\' . $_sass_targetFile;
				$_sass_targetUrl = substr($_sass_target, strlen(\'' . $this->wwwDir . '\'));

				if (!file_exists($_sass_target)) {
					$_sass = new \\SassParser();
					if (!file_exists($_sass_targetDir)) {
						umask(0000);
						mkdir($_sass_targetDir, 0777, true);
					}

					// Remove old files
					foreach (\\Nette\\Utils\\Finder::findFiles($_sass_file->getBasename() . \'-\' . md5(\'' . $path . '\') . \'-*\')->from($_sass_targetDir) as $_sass_old) {
						unlink($_sass_old->getPathname());
					}

					$_sass_css = $_sass->toCss(\'' . $path . '\', $_sass_target);
					file_put_contents($_sass_target, $_sass_css);	
				}

				$control->getPresenter()->getContext()->getService("assets.assetManager")->addStylesheet($_sass_targetUrl, ' . $params . ');
			';
        }
    }
 /**
  * Compiles the $uncompiledFile into CSS
  */
 public function compile()
 {
     if (MetaLanguages::within_modification_tolerance($this->uncompiledFile, $this->getCompiledPath())) {
         return;
     }
     $path = $this->getCompiledPath();
     $parser = new SassParser();
     $sass = $parser->toCss(BASE_PATH . "/" . $this->uncompiledFile);
     if (file_exists($path) && !is_writable($this->getCompiledPath())) {
         user_error("SCSS compiling error: {$path} is not writable.", E_USER_ERROR);
     } elseif (!is_writable(BASE_PATH . "/" . $path)) {
         user_error("SCSS compiling error: {$path} is not writable.", E_USER_ERROR);
     }
     $file = fopen(BASE_PATH . "/" . $path, "w");
     fwrite($file, $sass);
     fclose($file);
 }
Ejemplo n.º 16
0
 static function render($file)
 {
     $ext = pathinfo($file, PATHINFO_EXTENSION);
     $bn = basename($file);
     if ($bn[0] == '_') {
         return '';
     }
     // Importable packages
     global $BASEPATH;
     $sass_path = $BASEPATH . '/static/img/sprites/';
     $options = array('style' => 'nested', 'cache' => false, 'syntax' => $ext, 'debug' => false, 'load_paths' => array($sass_path), 'functions' => self::getFunctions(array('Compass', 'Own')), 'extensions' => array('Compass', 'Own'));
     if (\Radical\Core\Server::isProduction()) {
         $options['style'] = 'compressed';
     }
     // Execute the compiler.
     $parser = new \SassParser($options);
     return $parser->toCss($file);
 }
Ejemplo n.º 17
0
 /**
  * Returns the parse tree for a file.
  * @param string filename to parse
  * @param SassParser Sass parser
  * @return SassRootNode
  */
 public static function get_tree($filename, &$parser)
 {
     $contents = self::get_file_contents($filename, $parser);
     $options = array_merge($parser->options, array('line' => 1));
     # attempt at cross-syntax imports.
     $ext = substr($filename, strrpos($filename, '.') + 1);
     if ($ext == self::SASS || $ext == self::SCSS) {
         $options['syntax'] = $ext;
     }
     $dirname = dirname($filename);
     $options['load_paths'][] = $dirname;
     if (!in_array($dirname, $parser->load_paths)) {
         $parser->load_paths[] = dirname($filename);
     }
     $sassParser = new SassParser($options);
     $tree = $sassParser->parse($contents, FALSE);
     return $tree;
 }
Ejemplo n.º 18
0
 private function update($skin = false, $custom = false, $editor = false)
 {
     global $thesis;
     $skin = $skin ? stripslashes($skin) : '';
     $custom = $custom ? stripslashes($custom) : '';
     $css = apply_filters('thesis_css', $this->reset() . $skin, $this->reset(), $skin) . (!empty($custom) ? "\n{$custom}" : '');
     if (empty($css)) {
         return '';
     }
     $return = '';
     $clearfix = array();
     if (in_array($this->preprocessor, array(false, 'thesis'))) {
         extract($this->packages->css($css));
     }
     $css = $this->vars->css($css);
     if ($editor) {
         $css = preg_replace('/url\\(\\s*(\'|")(images|fonts)\\/([\\w-\\.]+)(\'|")\\s*\\)/', 'url(${1}' . THESIS_USER_SKIN_URL . '/${2}/${3}${1})', $css);
     }
     $css = $css . (!empty($clearfix) ? $this->clearfix($clearfix) : '');
     if ($this->preprocessor === 'less') {
         require_once THESIS_CSS . '/lessc.inc.php';
         $less = new lessc();
         try {
             $css = $less->compile($css);
         } catch (Exception $e) {
             print_r($e->getMessage());
             die;
         }
     } elseif (in_array($this->preprocessor, array('sass', 'scss'))) {
         require_once THESIS_CSS . '/sass/SassParser.php';
         $options = array('style' => 'nested', 'cache' => false, 'syntax' => $this->preprocessor, 'debug' => false);
         try {
             $sass = new SassParser($options);
             $css = $sass->toCss($css, false);
         } catch (Exception $e) {
             return false;
         }
     }
     return $css;
 }
Ejemplo n.º 19
0
 /**
  * Parse a Sass file to CSS
  * @param string path to file
  * @return string CSS
  */
 public function parse($file)
 {
     return $this->sass->toCss($file);
 }
Ejemplo n.º 20
0
 public function __parse($file, $syntax, $style = 'nested', $load_path = array())
 {
     $options = array('style' => $style, 'cache' => FALSE, 'syntax' => $syntax, 'debug' => FALSE, 'callbacks' => array('warn' => array($this, 'cb_warn'), 'debug' => array($this, 'cb_debug')), 'load_paths' => $load_path);
     // Execute the compiler.
     $parser = new SassParser($options);
     return $parser->toCss($file);
 }
<?php

if (!defined('CAKE_CORE_INCLUDE_PATH')) {
    header('HTTP/1.1 404 Not Found');
    exit('File Not Found');
}
/**
 * SASS CSS FILTER
 * 
 * create corresponding .sass file in webroot/css/
 * done.
 */
header("Content-Type: text/css");
if (preg_match('|\\.\\.|', $url) || !preg_match('|^ccss/(.+)$|i', $url, $regs)) {
    die('Wrong file name.');
}
$filepath = CSS . $regs[1];
$sassFile = r('.css', '.sass', $filepath);
if (!file_exists($sassFile)) {
    die('/*SASS file not found.*/');
}
// RENDER AND CACHE
App::import('Vendor', 'SassParser', array('file' => 'sass' . DS . 'SassParser.class.php'));
$renderer = SassRenderer::COMPACT;
$parser = new SassParser(CSS, TMP . 'sass', $renderer);
// OUTPUT
echo "/* SASS - " . $parser->getRenderer() . " */\n\n";
echo $parser->fetch($sassFile, $renderer);
Ejemplo n.º 22
0
$file = $_GET['file'];

if (!$file)
{
  exit();
}
else
{
  if (file_exists($file))
  {
    // If you're going to leave .htaccess at your root, assets folder or any 
    // other directory that will keep it separeted from the libraries, don't
    // forget to change URL/access to parser.php on .htaccess

    require 'phamlp/sass/SassParser.php';

    $sass = new SassParser();

    header('Content-Type: text/css');
    //header('Last-Modified: '.gmdate('D, d M Y H:i:s', $requested_mod_time).' GMT');
    echo $sass->toCss($file);
  }
  else
    return header("HTTP/1.0 404 Not Found");


}

?>
Ejemplo n.º 23
0
 /**
  * Constructor.
  * Sets parser options
  * @param array $options
  * @return SassParser
  */
 public function __construct($options = array())
 {
     if (!is_array($options)) {
         if (isset($options['debug']) && $options['debug']) {
             throw new SassException('Options must be an array');
         }
         $options = count((array) $options) ? (array) $options : array();
     }
     unset($options['language']);
     $basepath = $_SERVER['PHP_SELF'];
     $basepath = substr($basepath, 0, strrpos($basepath, '/') + 1);
     $defaultOptions = array('basepath' => $basepath, 'debug_info' => FALSE, 'filename' => array('dirname' => '', 'basename' => ''), 'functions' => array(), 'load_paths' => array(), 'load_path_functions' => array(), 'line' => 1, 'line_numbers' => FALSE, 'style' => SassRenderer::STYLE_NESTED, 'syntax' => SassFile::SASS, 'debug' => FALSE, 'quiet' => FALSE, 'callbacks' => array('warn' => FALSE, 'debug' => FALSE));
     if (isset(self::$instance)) {
         $defaultOptions['load_paths'] = self::$instance->load_paths;
     }
     $options = array_merge($defaultOptions, $options);
     // We don't want to allow setting of internal only property syntax value
     if (isset($options["property_syntax"]) && $options["property_syntax"] == "scss") {
         unset($options["property_syntax"]);
     }
     self::$instance = $this;
     self::$functions = $options['functions'];
     unset($options['functions']);
     foreach ($options as $name => $value) {
         $this->{$name} = $value;
     }
     if (!$this->property_syntax && $this->syntax == SassFile::SCSS) {
         $this->property_syntax = "scss";
     }
     $GLOBALS['SassParser_debug'] = $this->debug;
 }
Ejemplo n.º 24
0
<?php

/**
 * This file is intended to be used in conjunction with Apache2's mod_actions,
 * wherein you can have a .htaccess file like so for automatic compilation:
 *     Action compile-sass /git/phpsass/compile-apache.php
 *     AddHandler compile-sass .sass .scss
 */
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();
}
Ejemplo n.º 25
0
 protected function compileInternal($parameters)
 {
     global $wgAutoloadClasses, $IP;
     $wgAutoloadClasses['SassParser'] = $IP . '/lib/phpsass/SassParser.php';
     // make sure SassParser-related classes are loaded
     require_once $wgAutoloadClasses['SassParser'];
     // process source sass file
     $options = array('style' => SassRenderer::STYLE_COMPACT, 'syntax' => SassFile::SCSS, 'filename' => $this->fileName, 'load_paths' => array($IP), 'functions' => array('get_command_line_param' => function ($name, $default) use($parameters) {
         return array_key_exists($name, $parameters) && $parameters[$name] !== '' ? $parameters[$name] : $default;
     }));
     $context = new SassContext();
     $parser = new SassParser($options);
     $startTime = microtime(true);
     $tree = $parser->parse($this->fileName, true);
     $midTime = microtime(true);
     $contents = $tree->render($context);
     $endTime = microtime(true);
     $contents = sprintf("/* phpsass: parse/render: %.5f / %.5f */\n\n", $midTime - $startTime, $endTime - $midTime) . $contents;
     return $contents;
 }
Ejemplo n.º 26
0
Archivo: sacy.php Proyecto: fjg/sacy
 function getOutput($work_unit)
 {
     $debug = $this->getConfig()->getDebugMode() == 3;
     if ($work_unit['file']) {
         $css = @file_get_contents($work_unit['file']);
         if (!$css) {
             return "/* error accessing file */";
         }
         $source_file = $work_unit['file'];
     } else {
         $css = $work_unit['content'];
         $source_file = $this->getSourceFile();
     }
     if (ExternalProcessorRegistry::typeIsSupported($work_unit['type'])) {
         $opts = array();
         if ($work_unit['paths']) {
             $opts['library_path'] = $work_unit['paths'];
         }
         $css = ExternalProcessorRegistry::getTransformerForType($work_unit['type'])->transform($css, $source_file, $opts);
     } else {
         if ($work_unit['type'] == 'text/x-less') {
             $less = new \lessc();
             $less->importDir = dirname($source_file) . '/';
             #lessphp concatenates without a /
             $css = $less->parse($css);
         }
         if (PhpSassSacy::isAvailable() && $work_unit['type'] == 'text/x-scss') {
             $css = PhpSassSacy::compile($source_file, $work_unit['paths'] ?: array(dirname($source_file)));
         } elseif (in_array($work_unit['type'], array('text/x-scss', 'text/x-sass'))) {
             $config = array('cache' => false, 'debug_info' => $debug, 'line' => $debug, 'load_paths' => $work_unit['paths'] ?: array(dirname($source_file)), 'filename' => $source_file, 'quiet' => true, 'style' => $debug ? 'nested' : 'compressed');
             $sass = new \SassParser($config);
             $css = $sass->toCss($css, false);
             // isFile?
         }
     }
     if ($debug) {
         return \Minify_CSS_UriRewriter::rewrite($css, dirname($source_file), $this->getConfig()->getDocumentRoot(), array());
     } else {
         return \Minify_CSS::minify($css, array('currentDir' => dirname($source_file), 'docRoot' => $this->getConfig()->getDocumentRoot()));
     }
 }
Ejemplo n.º 27
0
 public function add_saas($sSaasRelPath)
 {
     $sSaasPath = APPROOT . $sSaasRelPath;
     $sCssRelPath = preg_replace('/\\.scss$/', '.css', $sSaasRelPath);
     $sCssPath = APPROOT . $sCssRelPath;
     clearstatcache();
     if (!file_exists($sCssPath) || is_writable($sCssPath) && filemtime($sCssPath) < filemtime($sSaasPath)) {
         // Rebuild the CSS file from the Saas file
         if (file_exists(APPROOT . 'lib/sass/sass/SassParser.php')) {
             require_once APPROOT . 'lib/sass/sass/SassParser.php';
             //including Sass libary (Syntactically Awesome Stylesheets)
             $oParser = new SassParser(array('style' => 'expanded'));
             $sCss = $oParser->toCss($sSaasPath);
             file_put_contents($sCssPath, $sCss);
         }
     }
     $sRootUrl = utils::GetAbsoluteUrlAppRoot();
     if ($sRootUrl === '') {
         // We're running the setup of the first install...
         $sRootUrl = '../';
     }
     $sCSSUrl = $sRootUrl . $sCssRelPath;
     $this->add_linked_stylesheet($sCSSUrl);
 }
Ejemplo n.º 28
0
	die('Wrong file name.');
}

$cssFile = CSS . $regs[1];
$sassFile = str_replace('.css', '.scss', $cssFile);

// Parse the Sass file if there is one
if (file_exists($sassFile)) {
	$options = array();
	foreach ($sassOptions as $option) {
		$_option = Configure::read("Sass.$option");
		if (!is_null($_option)) {
			$options[$option] = $_option;
		}
	} // foreach
	
	App::import('Vendor', 'SassParser', array('file'=>'sass'.DS.'SassParser.php'));
	
	$parser = new SassParser($options);

	echo $parser->toCss($sassFile);
}
// Look for a CSS file if no Sass file
elseif (file_exists($cssFile)) {
	echo file_get_contents($cssFile);
}
// If no Sass or CSS then die
else {
	die('/* No Sass or CSS file found. */');
}
ob_end_flush();
Ejemplo n.º 29
0
            if (!empty($returnPath)) {
                $paths[] = $returnPath;
            }
        }
    }
    return $paths;
}
function getFunctions($extensions)
{
    $output = array();
    if (!empty($extensions)) {
        foreach ($extensions as $extension) {
            $name = explode('/', $extension, 2);
            $namespace = ucwords(preg_replace('/[^0-9a-z]+/', '_', strtolower(array_shift($name))));
            $extensionPath = realpath(__DIR__ . '/../' . $namespace . '/' . $namespace . '.php');
            if (file_exists($extensionPath)) {
                require_once $extensionPath;
                $namespace = $namespace . '::';
                $function = 'getFunctions';
                $output = array_merge($output, call_user_func($namespace . $function, $namespace));
            }
        }
    }
    return $output;
}
$path = realpath(__DIR__) . '/../..';
$library = $path . '/SassParser.php';
require_once $library;
$options = array('style' => 'expanded', 'cache' => false, 'syntax' => 'scss', 'debug' => false, 'debug_info' => false, 'load_path_functions' => array('loadCallback'), 'load_paths' => array(dirname($file)), 'functions' => getFunctions(array('Compass', 'Own')), 'extensions' => array('Compass', 'Own'));
$parser = new SassParser($options);
return $parser->toCss($file);
Ejemplo n.º 30
0
    if (!empty($extensions)) {
        foreach ($extensions as $extension) {
            $name = explode('/', $extension, 2);
            $namespace = ucwords(preg_replace('/[^0-9a-z]+/', '_', strtolower(array_shift($name))));
            $extensionPath = './' . $namespace . '/' . $namespace . '.php';
            if (file_exists($extensionPath)) {
                require_once $extensionPath;
                $namespace = $namespace . '::';
                $function = 'getFunctions';
                $output = array_merge($output, call_user_func($namespace . $function, $namespace));
            }
        }
    }
    return $output;
}
$file = 'example.scss';
$path = '../';
$library = $path . '/SassParser.php';
if ($path && file_exists($library)) {
    try {
        require_once $library;
        $options = array('style' => 'expanded', 'cache' => false, 'syntax' => 'scss', 'debug' => false, 'debug_info' => false, 'load_path_functions' => array('loadCallback'), 'load_paths' => array(dirname($file)), 'functions' => getFunctions(array('Compass', 'Own')), 'extensions' => array('Compass', 'Own'));
        // Execute the compiler.
        $parser = new SassParser($options);
        print $parser->toCss($file);
    } catch (Exception $e) {
        print "body::before {\n          display: block;\n          padding: 5px;\n          white-space: pre;\n          font-family: monospace;\n          font-size: 8pt;\n          line-height: 17px;\n          overflow: hidden;\n          content: '" . $e->getMessage() . "';\n        }";
    }
} else {
    echo 'Path or library are wrong';
}