Ejemplo n.º 1
0
 /**
  * @return scssc
  */
 private function get_compiler()
 {
     if (is_null($this->compiler)) {
         if (!class_exists('scssc')) {
             require_once dirname(__FILE__) . '/Compiler/lib/scssphp/scss.inc.php';
         }
         $this->compiler = new scssc();
         $this->compiler->setImportPaths($this->get_import_paths());
         $this->compiler->setFormatter('scss_formatter_compressed');
     }
     return $this->compiler;
 }
Ejemplo n.º 2
0
 public static function compile_sass($parent)
 {
     if (!empty(self::$path)) {
         require "scssphp/scss.inc.php";
         $scss = new scssc();
         $scss->setImportPaths(self::$path);
         if (!$parent->args['dev_mode']) {
             $scss->setFormatter("scss_formatter_compressed");
         }
         $new_css = '';
         foreach (self::$import as $import) {
             $new_css .= $scss->compile($import);
         }
         if ($new_css != '') {
             if ($parent->args['sass']['page_output']) {
                 echo '<style type="text/css" id="redux-' . $parent->args['opt_name'] . '">' . $new_css . '</style>';
             } else {
                 //Redux_Functions::initWpFilesystem();
                 //global $wp_filesystem;
                 $filesystem = $parent->filesystem;
                 $css_file = Redux_Helpers::cleanFilePath(ReduxFramework::$_upload_dir . $parent->args['opt_name'] . '-redux.css');
                 //$ret_val    = $wp_filesystem->put_contents($css_file, $new_css, FS_CHMOD_FILE);
                 $ret_val = $filesystem->execute('put_contents', $css_file, array('content' => $new_css));
             }
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Compiles all .scss files in a given folder into .css files in a given folder
  *
  * @param string $scss_folder source folder where you have your .scss files
  * @param string $css_folder destination folder where you want your .css files
  * @param string $format_style CSS output format, see http://leafo.net/scssphp/docs/#output_formatting for more.
  */
 public static function run($scss_folder, $css_folder, $format_style = "scss_formatter")
 {
     // scssc will be loaded automatically via Composer
     $scss_compiler = new scssc();
     // set the path where your _mixins are
     $scss_compiler->setImportPaths($scss_folder);
     // set css formatting (normal, nested or minimized), @see http://leafo.net/scssphp/docs/#output_formatting
     $scss_compiler->setFormatter($format_style);
     // get all .scss files from scss folder
     $filelist = glob($scss_folder . "*.scss");
     // step through all .scss files in that folder
     foreach ($filelist as $file_path) {
         // get path elements from that file
         $file_path_elements = pathinfo($file_path);
         // get file's name without extension
         $file_name = $file_path_elements['filename'];
         // get .scss's content, put it into $string_sass
         $string_sass = file_get_contents($scss_folder . $file_name . ".scss");
         // compile this SASS code to CSS
         $string_css = $scss_compiler->compile($string_sass);
         // create target directory if doesn't exist
         if (!is_dir($css_folder)) {
             mkdir($css_folder, 0777, true);
         }
         // write CSS into file with the same filename, but .css extension
         file_put_contents($css_folder . $file_name . ".css", $string_css);
     }
 }
Ejemplo n.º 4
0
 /**
  * Compiles all .scss files in a given folder into .css files in a given folder
  *
  * @param string $scss_folder source folder where you have your .scss files
  * @param string $css_folder destination folder where you want your .css files
  * @param string $format_style CSS output format, see http://leafo.net/scssphp/docs/#output_formatting for more.
  */
 public static function run($scss_folder, $css_folder, $format_style = "scss_formatter", $file_append = false)
 {
     // scssc will be loaded automatically via Composer
     $scss_compiler = new scssc();
     // set the path where your _mixins are
     $scss_compiler->setImportPaths($scss_folder);
     // set css formatting (normal, nested or minimized), @see http://leafo.net/scssphp/docs/#output_formatting
     $scss_compiler->setFormatter($format_style);
     // create master css file
     if (!is_dir($css_folder) && $file_append == false) {
         file_put_contents($css_folder, "");
     }
     if (is_dir($scss_folder)) {
         $scan = scandir($scss_folder);
     } else {
         $scan = [$scss_folder];
     }
     if (!file_exists($scss_folder)) {
         throw new Exception("Arquivo inexistente: {$scss_folder}");
     }
     foreach ($scan as $file) {
         if (in_array($file, array(".", ".."))) {
             continue;
         }
         if (is_dir($scss_folder)) {
             if (!file_exists($css_folder . $file)) {
                 if (is_dir($css_folder)) {
                     if (!mkdir($css_folder . $file . "/")) {
                         throw new Exception("Falha ao compilar arquivo .scss. Não foi possível criar a pasta {$css_folder}{$file}/");
                     }
                     if (!chmod($css_folder . $file, 0755)) {
                         throw new Exception("Falha ao compilar arquivo .scss. Não foi possível mudar a permissão do arquivo {$css_folder}{$file}/ para 755 (rwxr-xr-x)");
                     }
                 }
             }
             if (is_dir($css_folder)) {
                 self::run($scss_folder . $file . "/", $css_folder . $file . "/", $format_style);
             } else {
                 self::run($scss_folder . $file, $css_folder, $format_style);
             }
         } else {
             if (preg_match('/(.*).scss$/', $file) and $file[0] != '.') {
                 // get path elements from that file
                 $file_path_elements = pathinfo($file);
                 // get file's name without extension
                 $file_name = $file_path_elements['filename'];
                 // get .scss's content, put it into $string_sass
                 $string_sass = file_get_contents($scss_folder);
                 // compile this SASS code to CSS
                 $string_css = $scss_compiler->compile($string_sass);
                 // write CSS into file with the same filename, but .css extension
                 if (is_dir($css_folder)) {
                     file_put_contents($css_folder . $file_name . ".css", $string_css);
                 } else {
                     file_put_contents($css_folder, $string_css, FILE_APPEND);
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 public static function compile_sass($parent)
 {
     if (!empty(self::$path)) {
         if (!class_exists('scssc') && !isset($GLOBALS['redux_scss_compiler'])) {
             $GLOBALS['redux_scss_compiler'] = true;
             require "scssphp/scss.inc.php";
         }
         $scss = new scssc();
         $scss->setImportPaths(self::$path);
         if (!$parent->args['dev_mode']) {
             $scss->setFormatter("scss_formatter_compressed");
         }
         $new_css = '';
         foreach (self::$import as $import) {
             $new_css .= $scss->compile($import);
         }
         if ($new_css != '') {
             if ($parent->args['sass']['page_output']) {
                 echo '<style type="text/css" id="redux-' . $parent->args['opt_name'] . '">' . $new_css . '</style>';
             } else {
                 $filesystem = $parent->filesystem;
                 $css_file = Redux_Helpers::cleanFilePath(ReduxFramework::$_upload_dir . $parent->args['opt_name'] . '-redux.css');
                 $ret_val = $filesystem->execute('put_contents', $css_file, array('content' => $new_css));
             }
         }
     }
 }
/**
 * Compile SCSS
 * 
 * @return string
 */
function mob_admin_compile_scss($scss_folder, $css_folder, $format_style = "scss_formatter")
{
    // scssc will be loaded automatically via Composer
    $scss_compiler = new scssc();
    // set the path where your _mixins are
    $scss_compiler->setImportPaths($scss_folder);
    // set css formatting (normal, nested or minimized), @see http://leafo.net/scssphp/docs/#output_formatting
    $scss_compiler->setFormatter($format_style);
    // get all .scss files from scss folder
    $filelist = glob($scss_folder . "*.scss");
    try {
        // step through all .scss files in that folder
        foreach ($filelist as $file_path) {
            // get path elements from that file
            $file_path_elements = pathinfo($file_path);
            // get file's name without extension
            $file_name = $file_path_elements['filename'];
            // get .scss's content, put it into $string_sass
            $string_sass = mob_file_read($scss_folder . $file_name . ".scss");
            // compile this SASS code to CSS
            $string_css = $scss_compiler->compile($string_sass);
            // write CSS into file with the same filename, but .css extension
            mob_file_write($css_folder . $file_name . ".css", $string_css);
        }
    } catch (Exception $e) {
        return $e->getMessage();
    }
}
Ejemplo n.º 7
0
 /** Default RudraX Plug
  *
  * @RequestMapping(url="scss/{mdfile}",type=css)
  *
  */
 function serveStyle($mdfile)
 {
     include_once LIB_PATH . "/leafo/scssphp/scss.inc.php";
     $scss = new scssc();
     $scss->setFormatter("scss_formatter_compressed");
     $server = new scss_server(get_include_path(), get_include_path() . BUILD_PATH . "/scss/", $scss);
     $server->serve();
 }
 function compileScss()
 {
     require "scss.inc.php";
     $scss = new scssc();
     $scss->setImportPaths(get_stylesheet_directory() . '/assets/scss/');
     $scss->setFormatter('scss_formatter_compressed');
     file_put_contents(get_stylesheet_directory() . '/assets/css/global-gen.css', $scss->compile('@import "global.scss"'));
 }
Ejemplo n.º 9
0
 /**
  * Set values for Wp_Scss::properties
  *
  * @param string scss_dir - path to source directory for scss files
  * @param string css_dir - path to output directory for css files
  * @param string method - type of compile (compressed, expanded, etc)
  *
  * @var object scssc - instantiate the compiling object.
  *
  * @var array compile_errors - catches errors from compile
  */
 public function __construct($scss_dir, $css_dir, $compile_method)
 {
     $this->scss_dir = $scss_dir;
     $this->css_dir = $css_dir;
     $this->compile_method = $compile_method;
     global $scssc;
     $scssc = new scssc();
     $scssc->setFormatter($compile_method);
     $scssc->setImportPaths($scss_dir);
     $this->compile_errors = array();
 }
Ejemplo n.º 10
0
function jetpack_sass_css_preprocess($sass)
{
    require_once dirname(__FILE__) . '/preprocessors/scss.inc.php';
    $compiler = new scssc();
    $compiler->setFormatter('scss_formatter');
    try {
        return $compiler->compile($sass);
    } catch (Exception $e) {
        return $sass;
    }
}
Ejemplo n.º 11
0
 /**
  * Process scss file
  *
  * @param string $filename
  * @return array
  */
 public static function serve($filename)
 {
     $result = ['success' => false, 'error' => [], 'data' => ''];
     // try to get scss file
     $scss_string = file_get_contents($filename);
     if ($scss_string === false) {
         $result['error'][] = 'Scss file does not exists!';
     } else {
         $scss_compiler = new scssc();
         $scss_compiler->setFormatter('scss_formatter');
         $result['data'] = $scss_compiler->compile($scss_string);
         $result['success'] = true;
     }
     return $result;
 }
 /**
  * Compile the SCSS.
  *
  * @return string
  */
 protected function compile_scss()
 {
     if (!class_exists('scssc') && !class_exists('scss_formatter_nested')) {
         include_once 'libs/class-scss.php';
     }
     // Get options
     $colors = WC_Colors::get_options(get_option('woocommerce_colors'));
     ob_start();
     include 'views/scss.php';
     $scss = ob_get_clean();
     $compiler = new scssc();
     $compiler->setFormatter('scss_formatter_compressed');
     $compiled_css = $compiler->compile(trim($scss));
     return $compiled_css;
 }
 public function run_compiler($scss_dir, $sass_vars, $sass_import_file, $css_name, $compile_method = 'scss_formatter_nested')
 {
     require_once WPCSC_PLUGIN_DIR . '/scssphp/scss.inc.php';
     $scss = new scssc();
     $scss->setImportPaths($scss_dir);
     $scss->setFormatter($compile_method);
     $scss->setVariables($sass_vars);
     $new_css = $scss->compile($sass_import_file);
     /* Write the CSS to the Database */
     $wpcscOptions = get_option('wpcsc1208_option_settings');
     /* Sanitze the CSS before going into the Database
        Refer to this doc, http://wptavern.com/wordpress-theme-review-team-sets-new-guidelines-for-custom-css-boxes */
     $wpcscOptions['wpcsc_content'][$css_name] = wp_kses($new_css, array('\'', '\\"'));
     update_option('wpcsc1208_option_settings', $wpcscOptions);
 }
Ejemplo n.º 14
0
 public function compile($scss_folder, $scss_filename, $stylename, $format_style = "scss_formatter")
 {
     require_once plugin_dir_path(__FILE__) . 'lib/scssphp/scss.inc.php';
     $scss_compiler = new scssc();
     $scss_compiler->setImportPaths($scss_folder);
     $scss_compiler->setFormatter($format_style);
     try {
         $file = $scss_filename;
         $content = file_get_contents($file);
         $string_css = $scss_compiler->compile($content);
         file_put_contents($stylename, $string_css);
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
Ejemplo n.º 15
0
 public function compile()
 {
     // go on even if user "stops" the script by closing the browser, closing the terminal etc.
     ignore_user_abort(true);
     // set script running time to unlimited
     set_time_limit(0);
     $root_dir = $this->root_dir;
     $scss_compiler = new scssc();
     $scss_compiler->setNumberPrecision(10);
     $scss_compiler->stripComments = $this->strip_comments;
     $scss_compiler->addImportPath(function ($path) use($root_dir) {
         $path = $root_dir . $path . '.scss';
         $path_parts = pathinfo($path);
         $underscore_file = $path_parts['dirname'] . '/_' . $path_parts['basename'];
         if (file_exists($underscore_file)) {
             $path = $underscore_file;
         }
         if (!file_exists($path)) {
             return null;
         }
         return $path;
     });
     // set the path to your to-be-imported mixins. please note: custom paths are coming up on future releases!
     //$scss_compiler->setImportPaths($scss_folder);
     // set css formatting (normal, nested or minimized), @see http://leafo.net/scssphp/docs/#output_formatting
     $scss_compiler->setFormatter($this->formatter);
     // get .scss's content, put it into $string_sass
     $string_sass = '';
     if (is_array($this->scss_file)) {
         foreach ($this->scss_file as $scss_file) {
             $string_sass .= file_get_contents($scss_file);
         }
     } else {
         $string_sass = file_get_contents($this->scss_file);
     }
     // try/catch block to prevent script stopping when scss compiler throws an error
     try {
         // compile this SASS code to CSS
         $string_css = $scss_compiler->compile($string_sass) . "\n";
         // $string_css = csscrush_string($string_css, $options = array('minify' => true));
         // write CSS into file with the same filename, but .css extension
         file_put_contents($this->css_file, $string_css);
     } catch (Exception $e) {
         // here we could put the exception message, but who cares ...
         echo $e->getMessage();
         exit;
     }
 }
Ejemplo n.º 16
0
 /**
  * Compile the SCSS
  * @param \Contao\ThemeModel
  * @param boolean
  */
 public static function compile(\Contao\ThemeModel $objTheme, $blnForce = false)
 {
     if (!self::confirmDependencies()) {
         return;
     }
     //Get file key
     $strKey = self::getKey($objTheme);
     //Set file path
     $strCSSPath = 'assets/foundation/css/' . $strKey . '.css';
     //Compile the scss
     if (!file_exists(TL_ROOT . '/' . $strCSSPath) || $blnForce) {
         //Gather up the SCSS files in the assets/foundation/scss folder
         //This allows to work with different configs and edit defaults
         //Without affecting the original source
         $strBasePath = COMPOSER_DIR_RELATIVE . '/vendor/zurb/foundation/scss';
         $strCopyPath = 'assets/foundation/scss/' . $strKey;
         //Create new folder if not exists and clean it out
         $objNew = new \Folder($strCopyPath);
         $objNew->purge();
         $objOriginal = new \Folder($strBasePath);
         $objOriginal->copyTo($strCopyPath);
         //Apply the config
         self::applyConfig($objTheme, $strCopyPath);
         $strFoundationCSS = '';
         $strNormalizeCSS = '';
         //Create the SCSS compiler
         if (class_exists('scssc')) {
             $objCompiler = new \scssc();
             $objCompiler->setImportPaths(TL_ROOT . '/' . $strCopyPath);
             $objCompiler->setFormatter(\Config::get('debugMode') ? 'scss_formatter' : 'scss_formatter_compressed');
         } else {
             $objCompiler = new Compiler();
             $objCompiler->setImportPaths(TL_ROOT . '/' . $strCopyPath);
             $objCompiler->setFormatter(\Config::get('debugMode') ? 'Leafo\\ScssPhp\\Formatter\\Expanded' : 'Leafo\\ScssPhp\\Formatter\\Compressed');
         }
         $strFoundationContent = file_get_contents(TL_ROOT . '/' . $strCopyPath . '/foundation.scss');
         $strNormalizeContent = file_get_contents(TL_ROOT . '/' . $strCopyPath . '/normalize.scss');
         //Compile
         $strFoundationCSS = $objCompiler->compile($strFoundationContent);
         $strNormalizeCSS = $objCompiler->compile($strNormalizeContent);
         //Write to single CSS file cache
         $objFile = new \File($strCSSPath);
         $objFile->write($strNormalizeCSS . "\n" . $strFoundationCSS);
         $objFile->close();
     }
     return $strCSSPath;
 }
Ejemplo n.º 17
0
 /**
  * Process file content
  *
  * @param File $asset
  * @return string
  */
 public function processContent(File $asset)
 {
     $path = $asset->getPath();
     try {
         $compiler = new \scssc();
         $compiler->setFormatter('scss_formatter');
         $content = $this->assetSource->getContent($asset);
         if (trim($content) === '') {
             return '';
         }
         return $compiler->compile($content);
     } catch (\Exception $e) {
         $errorMessage = PHP_EOL . self::ERROR_MESSAGE_PREFIX . PHP_EOL . $path . PHP_EOL . $e->getMessage();
         $this->logger->critical($errorMessage);
         return $errorMessage;
     }
 }
Ejemplo n.º 18
0
function cuttz_scss_compile()
{
    if (!current_user_can('update_themes')) {
        return;
    }
    $scss = new scssc();
    $scss->setFormatter('scss_formatter');
    if (file_exists(CHILD_DIR . '/lib/stylesheet-core/style.scss')) {
        if (filemtime(CHILD_DIR . '/lib/stylesheet-core/style.scss') > filemtime(CHILD_DIR . '/style.css')) {
            $css = "@charset \"UTF-8\"; \n\n/*S********************************************************************************\n******************** Make all your changes to themes/cuttz/lib/stylesheet-core/style.scss **************************\n**** This file will be overwritten by style.scss and your changes will be lost ****\n**********************************************************************************/\n\n";
            $css = '';
            $css .= $scss->compile('@import "' . CHILD_DIR . '/lib/stylesheet-core/style.scss' . '"');
            file_put_contents(CHILD_DIR . '/style.css', $css);
            if (function_exists('w3tc_browsercache_flush')) {
                //check if W3Total cache is installed and active
                w3tc_browsercache_flush();
                //flush the w3tc browser cache to fetch the new css
            }
        }
    }
    if (file_exists(cuttz_current_skin_path() . '/style.scss')) {
        if (filemtime(cuttz_current_skin_path() . '/style.scss') > @filemtime(cuttz_current_skin_path() . '/autogenerated.css')) {
            $css = "@charset \"UTF-8\"; \n\n/*D*********************************************************************************\n******************** Make all your changes to style.scss **************************\n**** This file will be overwritten by style.scss and your changes will be lost ****\n**********************************************************************************/\n\n";
            $css .= $scss->compile('@import "' . cuttz_current_skin_path() . '/style.scss' . '"');
            file_put_contents(cuttz_current_skin_path() . '/autogenerated.css', $css);
            if (function_exists('w3tc_browsercache_flush')) {
                //check if W3Total cache is installed and active
                w3tc_browsercache_flush();
                //flush the w3tc browser cache to fetch the new css
            }
        }
    }
    $user_dir = cuttz_get_res('dir');
    if (file_exists($user_dir . 'style.scss')) {
        if (filemtime($user_dir . 'style.scss') > @filemtime($user_dir . 'autogenerated.css')) {
            $css = "@charset \"UTF-8\"; \n\n/*U********************************************************************************\n******************** Make all your changes to style.scss **************************\n**** This file will be overwritten by style.scss and your changes will be lost ****\n**********************************************************************************/\n\n";
            $css .= $scss->compile('@import "' . $user_dir . 'style.scss' . '"');
            file_put_contents($user_dir . 'autogenerated.css', $css);
            if (function_exists('w3tc_browsercache_flush')) {
                //check if W3Total cache is installed and active
                w3tc_browsercache_flush();
                //flush the w3tc browser cache to fetch the new css
            }
        }
    }
}
Ejemplo n.º 19
0
function getSCSS($file)
{
    $uncompiled = basename($file) . '.scss';
    $compiled = 'cache/' . basename($file) . '.css';
    $scssContent = '';
    if (!is_writable('cache')) {
        die('/* Not writable: ' . $compiled . ' */');
    }
    if (@filemtime($compiled) < @filemtime($uncompiled)) {
        $scss = new scssc();
        $scss->setFormatter('scss_formatter_compressed');
        try {
            $return = file_put_contents($compiled, $scss->compile(file_get_contents($uncompiled)));
        } catch (Exception $e) {
            $scssContent .= "/*\n" . $e->getMessage() . "\n*/\n";
        }
    }
    $scssContent .= file_get_contents($compiled);
    return $scssContent;
}
Ejemplo n.º 20
0
 public function filterLoad(AssetInterface $asset)
 {
     $sc = new \scssc();
     if ($this->compass) {
         new \scss_compass($sc);
     }
     if ($dir = $asset->getSourceDirectory()) {
         $sc->addImportPath($dir);
     }
     foreach ($this->importPaths as $path) {
         $sc->addImportPath($path);
     }
     foreach ($this->customFunctions as $name => $callable) {
         $sc->registerFunction($name, $callable);
     }
     if ($this->formatter) {
         $sc->setFormatter($this->formatter);
     }
     $asset->setContent($sc->compile($asset->getContent()));
 }
Ejemplo n.º 21
0
 /**
  * Watches a folder for .scss files, compiles them every X seconds
  * Re-compiling your .scss files every X seconds seems like "too much action" at first sight, but using a
  * "has-this-file-changed?"-check uses more CPU power than simply re-compiling them permanently :)
  * Beside that, we are only compiling .scss in development, for production we deploy .css, so we don't care.
  *
  * @param string $scss_folder source folder where you have your .scss files
  * @param string $css_folder destination folder where you want your .css files
  * @param int $interval interval in seconds
  * @param string $scssphp_script_path path where scss.inc.php (the scssphp script) is
  * @param string $format_style CSS output format, ee http://leafo.net/scssphp/docs/#output_formatting for more.
  */
 public function watch($scss_folder, $css_folder, $interval, $scssphp_script_path, $format_style = "scss_formatter")
 {
     // go on even if user "stops" the script by closing the browser, closing the terminal etc.
     ignore_user_abort(true);
     // set script running time to unlimited
     set_time_limit(0);
     // load the compiler script (scssphp), more here: http://www.leafo.net/scssphp
     require $scssphp_script_path;
     $scss_compiler = new scssc();
     // set the path to your to-be-imported mixins. please note: custom paths are coming up on future releases!
     $scss_compiler->setImportPaths($scss_folder);
     // set css formatting (normal, nested or minimized), @see http://leafo.net/scssphp/docs/#output_formatting
     $scss_compiler->setFormatter($format_style);
     // start an infinitive loop
     while (1) {
         // get all .scss files from scss folder
         $filelist = glob($scss_folder . "*.scss");
         // step through all .scss files in that folder
         foreach ($filelist as $file_path) {
             // get path elements from that file
             $file_path_elements = pathinfo($file_path);
             // get file's name without extension
             $file_name = $file_path_elements['filename'];
             // get .scss's content, put it into $string_sass
             $string_sass = file_get_contents($scss_folder . $file_name . ".scss");
             // try/catch block to prevent script stopping when scss compiler throws an error
             try {
                 // compile this SASS code to CSS
                 $string_css = $scss_compiler->compile($string_sass);
                 // write CSS into file with the same filename, but .css extension
                 file_put_contents($css_folder . $file_name . ".css", $string_css);
             } catch (Exception $e) {
                 // here we could put the exception message, but who cares ...
             }
         }
         // wait for X seconds
         sleep($interval);
     }
 }
Ejemplo n.º 22
0
 protected function compile()
 {
     if (!class_exists('scssc')) {
         require_once __DIR__ . '/scss.inc.php';
     }
     $inputDir = dirname($this->inputFiles[0]);
     $outputDir = dirname($this->outputFile);
     $scss = new scssc();
     $scss->setFormatter('scss_formatter_compressed');
     $scss->setImportPaths($inputDir);
     if (!file_exists($outputDir)) {
         mkdir($outputDir, 0755, true);
     }
     try {
         $content = file_get_contents($this->inputFiles[0]);
         $css = $scss->compile($content);
         $css = AutoBuildPrefixer::addPrefixes($css);
     } catch (Exception $e) {
         $css = file_get_contents($this->outputFiles[0]);
         $css .= 'html:after{display:block;position:fixed;bottom:0;left:0;width:100%;padding:1em;font:14px sans;text-align:center;background:#d34;color:white;content:' . json_encode($e->getMessage()) . '}';
     }
     file_put_contents($this->outputFile, $css);
 }
Ejemplo n.º 23
0
 public static function getSCSS($file)
 {
     $uncompiled = self::getThemePath() . 'css/' . basename($file) . '.scss';
     $compiled = self::getThemePath() . 'cache/' . basename($file) . '.css';
     if (@filemtime($compiled) < @filemtime($uncompiled)) {
         $scss = new scssc();
         $scss->setFormatter('scss_formatter_compressed');
         try {
             file_put_contents($compiled, $scss->compile(file_get_contents($uncompiled)));
         } catch (Exception $e) {
             Functions::log(Functions::LOG_ERROR, $e->getMessage());
         }
     }
     return self::getThemeURL() . 'cache/' . basename($file) . '.css';
 }
Ejemplo n.º 24
0
 public static function compile_single_field($parent, $scss_path, $filename)
 {
     echo 'single field compile: ' . $scss_path . ' ' . $filename;
     if (!class_exists('scssc') && !isset($GLOBALS['redux_scss_compiler'])) {
         $GLOBALS['redux_scss_compiler'] = true;
         require "scssphp/scss.inc.php";
     }
     $scss = new scssc();
     $scss->setImportPaths($scss_path);
     if (!$parent->args['dev_mode']) {
         $scss->setFormatter("scss_formatter_compressed");
     }
     $new_css = $scss->compile('@import "' . $filename . '.scss"');
     unset($scss);
     $ret = @file_put_contents($scss_path . '/' . $filename . '.css', $new_css);
 }
Ejemplo n.º 25
0
 /**
  * Compiles raw SCSS into CSS for a particular menu location.
  *
  * @since 1.3
  * @return mixed
  * @param array $settings
  * @param string $location
  */
 public function generate_css_for_location($location, $theme, $menu_id)
 {
     $scssc = new scssc();
     $scssc->setFormatter('scss_formatter');
     $import_paths = apply_filters('megamenu_scss_import_paths', array(trailingslashit(get_stylesheet_directory()) . trailingslashit("megamenu"), trailingslashit(get_stylesheet_directory()), trailingslashit(get_template_directory()) . trailingslashit("megamenu"), trailingslashit(get_template_directory()), trailingslashit(WP_PLUGIN_DIR)));
     foreach ($import_paths as $path) {
         $scssc->addImportPath($path);
     }
     try {
         return $scssc->compile($this->get_complete_scss_for_location($location, $theme, $menu_id));
     } catch (Exception $e) {
         $message = __("Warning: CSS compilation failed. Please check your changes or revert the theme.", "megamenu");
         return new WP_Error('scss_compile_fail', $message . "<br /><br />" . $e->getMessage());
     }
 }
Ejemplo n.º 26
0
// Set default SCSS if there is no SCSS for current template. If template is default, skip check.
if ($template == 'default' or !file_exists($SCSS)) {
    $SCSS = $root . '/assets/scss/default.scss';
    $CSS = $root . '/assets/css/default.css';
    $CSSKirbyPath = 'assets/css/default.css';
}
// Get file modification times. Used for checking if update is required and as version number for caching.
$SCSSFileTime = filemtime($SCSS);
$CSSFileTime = filemtime($CSS);
// Update CSS when needed.
if (!file_exists($CSS) or $SCSSFileTime > $CSSFileTime) {
    // Activate library.
    require_once $root . '/site/plugins/scssphp/scss.inc.php';
    $parser = new scssc();
    // Setting compression provided by library.
    $parser->setFormatter('scss_formatter_compressed');
    // Setting relative @import paths.
    $importPath = $root . '/assets/scss';
    $parser->addImportPath($importPath);
    // Place SCSS file in buffer.
    $buffer = file_get_contents($SCSS);
    // Compile content in buffer.
    $buffer = $parser->compile($buffer);
    // Minify the CSS even further.
    require_once $root . '/site/plugins/scssphp/minify.php';
    $buffer = minifyCSS($buffer);
    // Update CSS file.
    file_put_contents($CSS, $buffer);
}
?>
<link rel="stylesheet" property="stylesheet" href="<?php 
Ejemplo n.º 27
0
function oxy_compile_sass_to_css($sass)
{
    $css = '';
    if (!class_exists('scssc')) {
        require OXY_THEME_DIR . 'vendor/leafo/scssphp/scss.inc.php';
    }
    $scss = new scssc();
    $scss->setFormatter('scss_formatter_compressed');
    if (!empty($sass)) {
        try {
            $css = $scss->compile($sass);
        } catch (Exception $e) {
        }
    }
    return $css;
}
Ejemplo n.º 28
0
 /**
  * Install method.
  */
 public static function install()
 {
     // Get old frontend colors from WooCommerce core.
     $colors = get_option('woocommerce_frontend_css_colors');
     if ($colors) {
         $colors = self::get_options($colors);
         update_option('woocommerce_colors', $colors);
         // Compile the css.
         if (!class_exists('scssc') && !class_exists('scss_formatter_nested')) {
             include_once 'includes/libs/class-scss.php';
         }
         ob_start();
         include 'includes/views/scss.php';
         $scss = ob_get_clean();
         $compiler = new scssc();
         $compiler->setFormatter('scss_formatter_compressed');
         $compiled_css = $compiler->compile(trim($scss));
         update_option('woocommerce_colors_css', $compiled_css);
         // Delete the old option.
         delete_option('woocommerce_frontend_css_colors');
         // Remove the notice.
         $notices = array_diff(get_option('woocommerce_admin_notices', array()), array('frontend_colors'));
         update_option('woocommerce_admin_notices', $notices);
     }
 }
Ejemplo n.º 29
0
 /**
  * Generates a CSS string of all the options
  *
  * @return  string A CSS string of all the values
  * @since   1.2
  */
 public function generateCSS()
 {
     $cssString = '';
     // These are the option types which are not allowed:
     $noCSSOptionTypes = array('text', 'textarea', 'editor');
     // Compile as SCSS & minify
     require_once trailingslashit(dirname(__FILE__)) . "inc/scssphp/scss.inc.php";
     $scss = new scssc();
     // Get all the CSS
     foreach ($this->allOptionsWithIDs as $option) {
         // Only do this for the allowed types
         if (in_array($option->settings['type'], $noCSSOptionTypes)) {
             continue;
         }
         // Decide whether or not we should continue to generate CSS for this option
         if (!apply_filters('tf_continue_generate_css_' . $option->settings['type'] . '_' . $option->getOptionNamespace(), true, $option)) {
             continue;
         }
         // Custom generated CSS
         $generatedCSS = apply_filters('tf_generate_css_' . $option->settings['type'] . '_' . $option->getOptionNamespace(), '', $option);
         if ($generatedCSS) {
             try {
                 $testerForValidCSS = $scss->compile($generatedCSS);
                 $cssString .= $generatedCSS;
             } catch (Exception $e) {
             }
             continue;
         }
         // Don't render CSS for this option if it doesn't have a value
         $optionValue = $this->frameworkInstance->getOption($option->settings['id']);
         if (empty($optionValue)) {
             continue;
         }
         // Add the values as SaSS variables
         $generatedCSS = $this->formCSSVariables($option->settings['id'], $option->settings['type'], $optionValue);
         try {
             $testerForValidCSS = $scss->compile($generatedCSS);
             $cssString .= $generatedCSS;
         } catch (Exception $e) {
         }
         // Add the custom CSS
         if (!empty($option->settings['css'])) {
             // In the css parameter, we accept the term `value` as our current value,
             // translate it into the SaSS variable for the current option
             $generatedCSS = str_replace('value', '#{$' . $option->settings['id'] . '}', $option->settings['css']);
             try {
                 $testerForValidCSS = $scss->compile($generatedCSS);
                 $cssString .= $generatedCSS;
             } catch (Exception $e) {
             }
         }
     }
     // Add additional CSS added via TitanFramework::createCSS()
     foreach ($this->additionalCSS as $css) {
         $cssString .= $css . "\n";
     }
     // Compile as SCSS & minify
     if (!empty($cssString)) {
         $scss->setFormatter(self::SCSS_COMPRESSION);
         try {
             $cssString = $scss->compile($cssString);
         } catch (Exception $e) {
         }
     }
     return $cssString;
 }
Ejemplo n.º 30
0
<?php

// SCSS Preprocessor
header('Content-Type: text/css');
if (!hasCache($file) || $is_new) {
    $scss = new scssc();
    $scss->setFormatter("scss_formatter");
    $scss->setImportPaths($dir);
    generateCache($file, $scss->compile(file_get_contents($file)));
}
outputCache($file);