toCss() публичный Метод

Parse a sass file or Sass source code and returns the CSS.
public toCss ( string $source, boolean $isFile = true ) : string
$source string name of source file or Sass source
$isFile boolean
Результат string CSS
Пример #1
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');
     }
 }
Пример #2
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');
 }
Пример #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);
}
Пример #4
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));
 }
Пример #5
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);
     }
 }
Пример #6
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);
 }
Пример #7
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));
 }
Пример #8
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;
 }
Пример #9
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>");
     }
 }
Пример #10
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;
 }
Пример #11
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);
 }
Пример #13
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);
 }
Пример #14
0
	public function __construct($node){
		$this->node=$node;

		$scsscCacheDir=$node->ini['front']['cache_dir'].'scss';
		$cssCacheDir=$node->ini['front']['cache_dir'].'css';
		
		//load css fields
		$this->css=isset($node->ini['front']['css']) && 
				    is_array($node->ini['front']['css']) ? 
						$node->ini['front']['css'] : array();
		if(isset($node->ini['front']['scss'])){
			foreach($node->ini['front']['scss'] as $input){
				//adjust the input filename if its relative to current directory
				if(substr($input,0,2)==='./') $input=substr($input,2);
				//determine output filename
				$output=$cssCacheDir.'/'.preg_replace(array('/^.\//','/\//','/.scss/'),array('','-','.css'),$input);
				try {
					if (!file_exists($output) || (@filemtime($input) > filemtime($output))) {
						if (!is_dir($cssCacheDir)) @mkdir($cssCacheDir);
	
						if(!isset($node->ini['front']['scss_compiler']) || $node->ini['front']['scss_compiler']==='scssphp'){
							//scssphp parser
							if(!isset($scss)){
								require_once $node->fs_path.'lib/scssphp/scss.inc.php';
								$scss = new scssc();
							}
							$parsed=$scss->compile(file_get_contents($input));
						}elseif($node->ini['front']['scss_compiler']==='phamlp'){
							//phamlp parser
							if(!isset($sass)){
								require_once $node->fs_path.'lib/sass/SassParser.php';
								$sass = new SassParser(array('cache_location'=>$scsscCacheDir,
															 'css_location'=>$cssCacheDir,
															 'style'=>'compact',
															 'vendor_properties'=>true));
							}
							$parsed=$sass->toCss($input);
						}		
						//adjust src values relative to the cache dir
						$relative=str_repeat('../',count(explode('/',$cssCacheDir))).substr($input,0,strrpos($input,'/')+1);
						$parsed=explode('url(',$parsed);
						for($i=1;$i<count($parsed);$i++){
							//don't get rid of quote marks
							$fChar=substr($parsed[$i],0,1);
							if($fChar==='"' || $fChar==="'") $parsed[$i]=substr($parsed[$i],1);
							else $fChar='';
							$parsed[$i]=$fChar.$relative.$parsed[$i];
						}
						$parsed=implode('url(',$parsed);
						//save the file
						$return = (file_put_contents($output, $parsed)
								=== false ? false : $output);
					}
					$this->css[]=$output;
				}catch (exception $ex) {
					exit($ex->getMessage());
				}
			}
		}
		$html='';
		if(isset($node->query['page']))
			$toRoot=str_repeat('../',count(explode('/',$node->query['page']))-1);
		else $toRoot='';
		foreach($this->css as $file){
			$html.='<link href="'.(substr($file,0,2)!=='//' ? $toRoot : '').$file.'" rel="stylesheet" />'."\n";
		}
		$node->page['headerHTML'][]=$html;
		
	}
Пример #15
0
 /**
  * Parse a Sass file to CSS
  * @param string path to file
  * @return string CSS
  */
 public function parse($file)
 {
     return $this->sass->toCss($file);
 }
Пример #16
0
            show_error('Your SASS output path isn\'t writtable, check the permissions and try again.');
        }
    }
    if (!file_exists($_ci_sass_output_path)) {
        mkdir($_ci_sass_output_path);
    }
    load_class('SassParser', 'libraries/phamlp/sass', '');
    $SASS = new SassParser(array("cache_location" => $_ci_sass_cache_path));
    foreach ($_ci_sass_assets as $_ci_sass_asset) {
        $_ci_sass_asset_out = $_ci_sass_output_path . str_replace($_ci_sass_asset_path, "", $_ci_sass_asset);
        $_ci_sass_asset_out = str_replace(".sass", ".css", $_ci_sass_asset_out);
        $_ci_sass_asset_out = str_replace(".scss", ".css", $_ci_sass_asset_out);
        if (!file_exists(dirname($_ci_sass_asset_out))) {
            mkdir(dirname($_ci_sass_asset_out));
        }
        $_ci_sass_css_output = $SASS->toCss($_ci_sass_asset, TRUE);
        $_ci_sass_do_write = FALSE;
        if ($SASS->getCame_from_cache() && !file_exists($_ci_sass_asset_out) || !$SASS->getCame_from_cache()) {
            $_ci_sass_do_write = TRUE;
        }
        if ($_ci_sass_do_write == TRUE) {
            file_put_contents($_ci_sass_asset_out, $_ci_sass_css_output);
        }
    }
}
/*
 * ------------------------------------------------------
 *  Instantiate the hooks class
 * ------------------------------------------------------
 */
$EXT =& load_class('Hooks', 'core');
Пример #17
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();
Пример #18
0
<?php

@ini_set('display_errors', 'off');
define('DOCROOT', rtrim(realpath(dirname(__FILE__) . '/../../../'), '/'));
define('DOMAIN', rtrim(rtrim($_SERVER['HTTP_HOST'], '/') . str_replace('/extensions/sass_compiler/lib', NULL, dirname($_SERVER['PHP_SELF'])), '/'));
// Include some parts of the engine
require_once DOCROOT . '/vendor/autoload.php';
require_once CONFIG;
require_once 'dist/SassParser.php';
function processParams($string)
{
    $param = (object) array('file' => 0);
    if (preg_match_all('/^(.+)$/i', $string, $matches, PREG_SET_ORDER)) {
        $param->file = $matches[0][1];
    }
    return $param;
}
$param = processParams($_GET['param']);
$mode = "scss";
if ($_GET['mode'] == "sass") {
    $mode = "sass";
}
header('Content-type: text/css');
$options = array('style' => 'nested', 'cache' => FALSE, 'syntax' => $mode, 'debug' => FALSE, 'callbacks' => array('warn' => 'cb_warn', 'debug' => 'cb_debug'));
$parser = new SassParser($options);
$css = $parser->toCss(WORKSPACE . '/' . $param->file);
$filename = pathinfo($param->file);
$filename = $filename['filename'];
file_put_contents(CACHE . '/sass_compiler/' . $filename . '.css', $css);
echo $css;
exit;
Пример #19
0
 public function save()
 {
     current_user_can('manage_options') || die;
     check_admin_referer(self::NONCE);
     $_post = stripslashes_deep($_POST);
     $doing_ajax = defined('DOING_AJAX') && DOING_AJAX;
     if ($doing_ajax) {
         $scheme = $this->get_color_scheme('preview');
     } else {
         $scheme = $this->get_color_scheme();
     }
     $colors = $this->get_colors('keys');
     // @todo: which, if any, of these are required?
     foreach ($colors as $key => $scss_key) {
         // really, these are always set, but always check, too!
         if (isset($_post[$key])) {
             $scheme->{$key} = $_post[$key];
         }
     }
     $scss = '';
     foreach ($colors as $key => $scss_key) {
         if (!empty($scheme->{$key})) {
             $scss .= "\${$scss_key}: {$scheme->{$key}};\n";
         }
     }
     if (empty($scss)) {
         // bail if this gets emptied out
         if ($doing_ajax) {
             $response = array('errors' => true, 'message' => __('Please make more selections to preview the color scheme.', 'admin-color-schemer'));
             echo json_encode($response);
             die;
         }
         // reset color scheme object
         $scheme = $this->get_color_scheme();
         wp_redirect($this->admin_url() . '&empty_scheme=true');
         exit;
     }
     $scss .= "\n\n@import 'colors.css';\n@import '_admin.scss';\n";
     // okay, let's see about getting credentials
     // @todo: what to do about preview
     if (false === ($creds = request_filesystem_credentials($this->admin_url()))) {
         return true;
     }
     // now we have some credentials, try to get the wp_filesystem running
     if (!WP_Filesystem($creds)) {
         // our credentials were no good, ask the user for them again
         request_filesystem_credentials($this->admin_url(), '', true);
         return true;
     }
     global $wp_filesystem;
     $wp_upload_dir = wp_upload_dir();
     $upload_dir = $wp_upload_dir['basedir'] . '/admin-color-schemer';
     $upload_url = $wp_upload_dir['baseurl'] . '/admin-color-schemer';
     // @todo: error handling if this can't be made - needs to be differentiated from already there
     $wp_filesystem->mkdir($upload_dir);
     if ($doing_ajax) {
         $scss_file = $upload_dir . '/preview.scss';
         $css_file = $upload_dir . '/preview.css';
         // use a modified query arg to avoid caching problems
         // @todo: chances are we'll need to do this for the saved scheme as well.
         $uri = $upload_url . '/preview.css?m=' . microtime();
     } else {
         // @todo: save into another subdirectory for multiple scheme handling
         $scss_file = $upload_dir . '/scheme.scss';
         $css_file = $upload_dir . '/scheme.css';
         $uri = $upload_url . '/scheme.css';
     }
     $this->maybe_copy_core_files($upload_dir);
     // write the custom.scss file
     if (!$wp_filesystem->put_contents($scss_file, $scss, FS_CHMOD_FILE)) {
         if ($doing_ajax) {
             $response = array('errors' => true, 'message' => __('Could not write custom SCSS file.', 'admin-color-schemer'));
             echo json_encode($response);
             die;
         }
         // @todo: error that the scheme couldn't be written and redirect
         exit('Could not write custom SCSS file.');
     }
     // Compile and write!
     require_once $this->base . '/lib/phpsass/SassParser.php';
     $sass = new SassParser();
     $css = $sass->toCss($scss_file);
     if (!$wp_filesystem->put_contents($css_file, $css, FS_CHMOD_FILE)) {
         if ($doing_ajax) {
             $response = array('errors' => true, 'message' => __('Could not write compiled CSS file.', 'admin-color-schemer'));
             echo json_encode($response);
             die;
         }
         // @todo: error that the compiled scheme couldn't be written and redirect
         exit('Could not write compiled CSS file.');
     }
     // add the URI of the sheet to the settings array
     $scheme->uri = $uri;
     if ($doing_ajax) {
         $response = array('uri' => $scheme->uri, 'message' => __('Previewing. Be sure to save if you like the result.', 'admin-color-schemer'));
         echo json_encode($response);
         die;
     }
     $this->set_option('schemes', array($scheme->id => $scheme->to_array()));
     // switch to the scheme
     update_user_meta(get_current_user_id(), 'admin_color', $scheme->slug);
     wp_redirect($this->admin_url() . '&updated=true');
     exit;
 }
Пример #20
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();
}
Пример #21
0
                $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);
Пример #22
0
 if ($_SERVER['REMOTE_ADDR'] == DEVIP && file_exists(DEVDIR . '/' . $file) && $opt != 'page') {
     $fromdev = true;
     $res = ROOTURL . DEVDIR . '/' . $res;
     $file = DEVDIR . '/' . $file;
 } else {
     $file = PAGESDIR . '/' . $file;
 }
 $fileparts = pathinfo($file);
 if (isset($fileparts['extension'])) {
     if ($fileparts['extension'] == 'sass' || $fileparts['extension'] == 'scss') {
         $cssfile = $fileparts['dirname'] . '/' . $fileparts['filename'] . '.css';
         if (file_exists($cssfile) && filemtime($cssfile) < filemtime($file) || !file_exists($cssfile)) {
             require 'lib/phpsass/SassParser.php';
             $options = array('style' => 'expanded', 'syntax' => $fileparts['extension'], 'cache' => FALSE, 'debug' => FALSE);
             $parser = new SassParser($options);
             $data = $parser->toCss($file);
             file_put_contents($cssfile, $data);
         }
         $res = str_replace('.' . $fileparts['extension'], '.css', $res);
     } else {
         if ($fileparts['extension'] == 'less') {
             $cssfile = $fileparts['dirname'] . '/' . $fileparts['filename'] . '.css';
             if (file_exists($cssfile) && filemtime($cssfile) < filemtime($file) || !file_exists($cssfile)) {
                 require 'lib/lessphp/lessc.inc.php';
                 $less = new lessc();
                 $data = $less->compileFile($file);
                 file_put_contents($cssfile, $data);
             }
             $res = str_replace('.less', '.css', $res);
         } else {
             if ($fileparts['extension'] == 'coffee') {
Пример #23
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;
 }
Пример #24
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';
}
Пример #25
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");


}

?>
Пример #26
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);
 }
Пример #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);
 }
Пример #28
0
Файл: sacy.php Проект: 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()));
     }
 }
Пример #29
0
function parse_sass($input)
{
    $sass = new SassParser(array('style' => 'nested', 'ugly' => false));
    $scss = $sass->toCss($input);
    echo $scss;
}