Esempio n. 1
0
 protected function runSassTest($input, $output = FALSE, $settings = [])
 {
     $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 + ['style' => 'nested', 'cache' => FALSE, 'syntax' => $syntax, 'debug' => FALSE, 'debug_info' => FALSE, 'callbacks' => ['debug' => [$this, 'sassParserDebug'], 'warn' => [$this, 'sassParserWarning']]];
     $parser = new \PHPSass\Parser($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');
 }
Esempio n. 2
0
 /**
  * Invoke filter
  *
  * @param string $code
  * @param \Lohini\WebLoader\WebLoader $loader
  * @param string $file
  * @return string
  */
 public function __invoke($code, \Lohini\WebLoader\WebLoader $loader, $file = NULL)
 {
     if ($file === NULL || !in_array(\Nette\Utils\Strings::lower(pathinfo($file, PATHINFO_EXTENSION)), [\PHPSass\File::SASS, \PHPSass\File::SCSS])) {
         return $code;
     }
     $so = ['style' => \PHPSass\Renderers\Renderer::STYLE_COMPRESSED, 'syntax' => pathinfo($file, PATHINFO_EXTENSION), 'load_paths' => [dirname($file)]];
     if (class_exists('PHPSass\\Extensions\\Compass')) {
         $so['functions'] = \PHPSass\Extensions\Compass::getFunctions('Compass');
         $so['extensions'] = ['Compass'];
         $so['load_paths'][] = dirname(\Nette\Reflection\ClassType::from('PHPSass\\Extensions\\Compass')->getFileName());
     }
     if (!\Nette\Environment::isProduction()) {
         $so['debug'] = TRUE;
         $so['debug_info'] = TRUE;
         $so['style'] = \PHPSass\Renderers\Renderer::STYLE_NESTED;
     }
     $filter = new \PHPSass\Parser($so);
     return $filter->toCss($file, TRUE);
 }
Esempio n. 3
0
 *     Action compile-sass /git/phpsass/compile-apache.php
 *     AddHandler compile-sass .sass .scss
 */
header('Content-type: text/css');
require_once './vendor/autoload.php';
/**
 * @param string $text
 * @param \PHPSass\Context $context
 */
function warn($text, $context)
{
    print "/** WARN: {$text}, on line {$context->node->token->line} of {$context->node->token->filename} **/\n";
}
/**
 * @param string $text
 * @param \PHPSass\Context $context
 */
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 = ['style' => 'expanded', 'cache' => FALSE, 'cache_location' => NULL, 'syntax' => $syntax, 'debug' => FALSE, 'callbacks' => ['warn' => 'warn', 'debug' => 'debug']];
// Execute the compiler.
$parser = new \PHPSass\Parser($options);
try {
    print "\n\n" . $parser->toCss($file);
} catch (Exception $e) {
    print $e->getMessage();
}
Esempio n. 4
0
/**
 * Compile a Sass or SCSS string to CSS.
 * Defaults to SCSS.
 * 
 * @param string $filename The path to the Sass, SCSS, or CSS file on disk.
 * @param array $options
 * @return string
 */
function compileFile($filename, array $options = [])
{
    if (!is_readable($filename) && !is_file($filename)) {
        echo 'Errno::ENOENT: No such file or directory - ' . $filename;
        exit(1);
    }
    if (!isset($options['syntax'])) {
        $options['syntax'] = \PHPSass\File::SCSS;
    }
    $engine = new \PHPSass\Parser($options);
    return $engine->toCss($filename);
}
Esempio n. 5
0
                $paths[] = $returnPath;
            }
        } catch (\Exception $e) {
        }
    }
    return $paths;
}
/**
 * @param array $extensions
 * @return array
 */
function getFunctions($extensions)
{
    $output = array();
    if (!empty($extensions)) {
        foreach ($extensions as $namespace => $class) {
            $output = array_merge($output, call_user_func($class . '::getFunctions', $namespace));
        }
    }
    return $output;
}
$file = 'test.scss';
require_once 'vendor/autoload.php';
try {
    $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' => '\\PHPSass\\Extensions\\Compass')), 'extensions' => array('Compass'));
    // Execute the compiler.
    $parser = new \PHPSass\Parser($options);
    print $parser->toCss($file);
} catch (\Exception $e) {
    print "body::before {\n\tdisplay: block;\n\tpadding: 5px;\n\twhite-space: pre;\n\tfont-family: monospace;\n\tfont-size: 8pt;\n\tline-height: 17px;\n\toverflow: hidden;\n\tcontent: '" . $e->getMessage() . "';\n\t}\n";
}
Esempio n. 6
0
/**
 * @param string $file
 * @param string $syntax
 * @param string $style
 * @return string
 */
function __parse($file, $syntax, $style = 'nested')
{
    $options = ['style' => $style, 'cache' => FALSE, 'syntax' => $syntax, 'debug' => FALSE, 'callbacks' => ['warn' => 'cb_warn', 'debug' => 'cb_debug']];
    // Execute the compiler.
    $parser = new \PHPSass\Parser($options);
    return $parser->toCss($file);
}