Ejemplo n.º 1
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.º 2
0
function alfath_custom_css_compiler($options)
{
    global $wp_filesystem;
    if (empty($wp_filesystem)) {
        require_once ABSPATH . '/wp-admin/includes/file.php';
        WP_Filesystem();
    }
    if (!class_exists('scssc')) {
        require_once ADMIN_DIR . '/option/configs/scss.inc.php';
    }
    $scssc = new scssc();
    $scssc->setImportPaths(get_template_directory() . '/assets/sass/');
    $scssc->setNumberPrecision(10);
    $file = get_template_directory() . '/assets/sass/custom.scss';
    $target = get_template_directory() . '/assets/css/custom.css';
    $var = '';
    if ($wp_filesystem->exists($file)) {
        $scss = $wp_filesystem->get_contents($file);
        if (!$scss) {
            return new WP_Error('reading_error', 'Error when reading file');
        }
        $var .= '$primary-color: ' . $options['primary-color'] . ';';
        $var .= '$secondary-color: ' . $options['secondary-color'] . ';';
        $var .= '$background-color: ' . $options['background-color'] . ';';
        $scss = $var . $scss;
        // Fallback image
        if ($options['nav-bg-fallback-switch'] === '1' && $options['nav-bg-fallback']['url'] !== '') {
            $nav = " .nav-dropline { > li { &.active, &.open, &:hover, &:focus { background: url('" . $options['nav-bg-fallback']['url'] . "') no-repeat bottom left, url('" . $options['nav-bg-fallback']['url'] . "') no-repeat bottom right; @media (min-width: 1200px) { background: url('" . $options['nav-bg-fallback']['url'] . "') no-repeat top left, url('" . $options['nav-bg-fallback']['url'] . "') no-repeat top right; } } } }";
            $scss .= $nav;
        }
        // Fallback Image End;
        $css = $scssc->compile($scss);
        if (!$css) {
            return new WP_Error('compile_error', 'Error on compiling scss to css');
        }
        $wp_filesystem->put_contents($target, $css, FS_CHMOD_FILE);
    }
}
Ejemplo n.º 3
0
 public function compile_stack($post_id, $css_format)
 {
     // create return value
     $css = '';
     // reset fontstack array
     $this->fontstack = array();
     // setup sass compiler
     if (!class_exists('scssc')) {
         require OXY_THEME_DIR . 'vendor/leafo/scssphp/scss.inc.php';
     }
     $scss = new scssc();
     $scss->addImportPath(OXY_THEME_DIR . 'assets/scss');
     $scss->setNumberPrecision(8);
     $scss->setFormatter($css_format);
     // create sass code
     $scss_code = $this->variables($post_id);
     $scss_code .= apply_filters('oxy_stack_scss', '');
     // compile sass and store in metadata
     try {
         $css = $scss->compile($scss_code);
     } catch (Exception $e) {
         print_r($e);
     }
     // create extra font js / links
     $this->build_before_css_code($post_id);
     return $css;
 }