コード例 #1
0
ファイル: smart_css.php プロジェクト: nekoya/smartcss-regex
 function exec()
 {
     if (!$this->getTargetFile()) {
         $this->notFoundError();
     }
     header('Content-type: text/css');
     $scss = new SmartCSS();
     $scss->parse(file_get_contents($this->filename));
     echo $scss->publish();
 }
コード例 #2
0
 function exec($params, $caller)
 {
     if (!count($params)) {
         return;
     }
     $depth = $caller->importDepth + 1;
     if ($depth === $this->maxDepth) {
         return;
     }
     $scss = new SmartCSS();
     $scss->importDepth = $depth;
     $basedir = dirname(dirname(__FILE__));
     foreach ($params as $file) {
         if (file_exists($file) && ScssUtils::isValidPath($file, $basedir)) {
             $scss->parse(file_get_contents($file));
         }
     }
     return str_replace("\n", '', $scss->publish());
 }
コード例 #3
0
ファイル: CLI.class.php プロジェクト: nekoya/SmartCSS
 /**
  *
  */
 public function getParams()
 {
     $short_opts = 'hdcsl';
     $long_opts = array('help', 'debug', 'compress', 'strict', 'lexdebug');
     $console = new Console_Getopt();
     $args = $console->readPHPArgv();
     $opts = $console->getopt($args, $short_opts, $long_opts);
     if (PEAR::isError($opts)) {
         echo $opts->getMessage() . PHP_EOL;
         $this->usage(1);
     }
     foreach ($opts[0] as $opt) {
         if ($opt[0] === '--help' || $opt[0] === 'h') {
             $this->usage();
         }
         if ($opt[0] === '--debug' || $opt[0] === 'd') {
             SmartCSS::$debug = true;
         }
         if ($opt[0] === '--compress' || $opt[0] === 'c') {
             SmartCSS::$compress = true;
         }
         if ($opt[0] === '--strict' || $opt[0] === 's') {
             SmartCSS::$strict = true;
         }
         if ($opt[0] === '--lexdebug' || $opt[0] === 'l') {
             SmartCSS::$lexdebug = true;
         }
     }
     if (empty($opts[1])) {
         $this->usage();
     }
     $filename = $opts[1][0];
     if (empty($filename)) {
         $this->usage();
     }
     return $filename;
 }
コード例 #4
0
ファイル: 01-lexer.php プロジェクト: nekoya/SmartCSS
@import url('http://www.example.com/print.css') print;
@IMPORT URL("http://www.example.com/print.css") PRINT;
__CSS__;
isToken($lexbuf, 'IMPORT NL IMPORT NL IMPORT', 'IMPORT');
$t->comment('rulesets');
isToken('* { margin:0; }', 'SELECTOR LBRACE SPACE IDENT : NUMBER ; SPACE }', 'star selector');
isToken('* { _margin:0; }', 'SELECTOR LBRACE SPACE IDENT : NUMBER ; SPACE }', 'under score hack');
isToken('div{margin:5px 10px}', 'SELECTOR LBRACE IDENT : LENGTH SPACE LENGTH }', 'basically ruleset');
isToken("div { margin:10px\nauto\n15px; }", 'SELECTOR LBRACE SPACE IDENT : LENGTH NL IDENT NL LENGTH ; SPACE }', 'expressions splited by NL');
isToken("p\n\n{\r\nmargin:\r\n\r\n0;}", 'SELECTOR NL NL LBRACE NL IDENT : NL NL NUMBER ; }', 'continuum NL');
isToken("a:hover\n{\n line-height:1.5;\n }\n", 'SELECTOR NL LBRACE NL SPACE IDENT : NUMBER ; NL SPACE } NL', 'pseudo');
isToken('ul,ol { margin:0; padding:0; }', 'SELECTOR LBRACE SPACE ' . 'IDENT : NUMBER ; SPACE ' . 'IDENT : NUMBER ; SPACE ' . '}', 'multi parent');
isToken('h2+p  ,  div > span { margin: 0; padding : 0 ; }', 'SELECTOR LBRACE SPACE ' . 'IDENT : SPACE NUMBER ; SPACE ' . 'IDENT SPACE : SPACE NUMBER SPACE ; SPACE ' . '}', 'selectors with plus and greater operator');
$t->comment('recursive rulesets');
isToken('div { width:100%; p { color:#3399ff; } }', 'SELECTOR LBRACE SPACE IDENT : PERCENTAGE ; SPACE ' . 'SELECTOR LBRACE SPACE IDENT : HEXCOLOR ; SPACE } SPACE ' . '}');
isToken('a:hover { color:#ccc; span:hover { text-decoration:underline; } }', 'SELECTOR LBRACE SPACE IDENT : HEXCOLOR ; SPACE ' . 'SELECTOR LBRACE SPACE IDENT : IDENT ; SPACE } SPACE }', 'resursive selector with pseudo');
isToken('div{a:hover{background:url("http://example.com/bg.png") no-repeat;}}', 'SELECTOR LBRACE SELECTOR LBRACE ' . 'IDENT : URI SPACE IDENT ; } }', 'no space, hexcolor, only child');
isToken('div { ul { list-style:none } margin:0 }', 'SELECTOR LBRACE SPACE ' . 'SELECTOR LBRACE SPACE IDENT : IDENT SPACE } ' . 'SPACE IDENT : NUMBER SPACE }', 'with spaces, parent rule after childs one');
isToken('DIV { UL { LIST-STYLE:NONE } BACKGROUND:URL("HTTP://EXAMPLE.COM/BG.PNG") NO-REPEAT }', 'SELECTOR LBRACE SPACE ' . 'SELECTOR LBRACE SPACE IDENT : IDENT SPACE } ' . 'SPACE IDENT : URI SPACE IDENT SPACE }', 'upper case');
$t->comment('variables');
isToken('[% HOGE %]', 'cLDELIM SPACE cCOMMAND SPACE cRDELIM', 'simple command');
isToken('div { margin:0 }[% HOGE %]p{padding:0}', 'SELECTOR LBRACE SPACE IDENT : NUMBER SPACE } ' . 'cLDELIM SPACE cCOMMAND SPACE cRDELIM ' . 'SELECTOR LBRACE IDENT : NUMBER }', 'ruleset - command - ruleset');
isToken('h2 { border:1px solid [%sky%]; }', 'SELECTOR LBRACE SPACE IDENT : LENGTH SPACE IDENT cLDELIM cIDENT cRDELIM ; SPACE }', 'variable as a value');
isToken("[% SEL %]\n{\n[% PROP %]\n:\n[% EXPR term %]\n}", 'cLDELIM SPACE cCOMMAND SPACE cRDELIM NL LBRACE NL ' . 'cLDELIM SPACE cCOMMAND SPACE cRDELIM NL : NL ' . 'cLDELIM SPACE cCOMMAND SPACE cIDENT SPACE cRDELIM NL }', 'command as selector, property, expr');
isToken('[% fuga = "hogege" %][%uge=\'UGE\'%]', 'cLDELIM SPACE cIDENT cEQUAL SPACE cVALUE SPACE cRDELIM ' . 'cLDELIM cIDENT cEQUAL cVALUE cRDELIM', 'define variable');
$t->comment('commands');
isToken('[% IMPORT "hoge.scss" %][% IMPORT \'fuga.scss\' %]', 'cLDELIM SPACE cCOMMAND SPACE cVALUE SPACE cRDELIM ' . 'cLDELIM SPACE cCOMMAND SPACE cVALUE SPACE cRDELIM', 'IMPORT command');
$t->comment('loose property');
isToken('body { *font-size:small }', 'SELECTOR LBRACE SPACE LOOSE_PROP : IDENT SPACE }', 'Loose property');
SmartCSS::$strict = true;
isToken('body { *font-size:small }', 'SELECTOR LBRACE SPACE * IDENT : IDENT SPACE }', 'Loose property had not parsed in strict mode');
コード例 #5
0
<?php

require 'initialize.php';
SmartCSS::$compress = true;
function parse($content, $expected, $note = '', $debug = false)
{
    global $t;
    $parser = new SCSS_Parser();
    $lexer = new SCSS_Lexer();
    $lexer->setBuffer($content);
    if ($debug) {
        $lexer->debug = true;
        $parser->debug = true;
    }
    try {
        $parser->yyparse($lexer);
    } catch (Exception $e) {
        echo '[ERROR]' . $e->getMessage() . PHP_EOL;
        var_dump($lexer->lexbuf);
        var_dump($e->getTraceAsString());
        $t->fail('Caught unexpected Exception');
        exit(1);
    }
    $t->is($parser->run(), $expected . PHP_EOL, $note);
    $parser->reset();
}
function throws_ok($content, $message = '')
{
    global $t;
    $parser = new SCSS_Parser();
    $lexer = new SCSS_Lexer();
コード例 #6
0
ファイル: smart_css.php プロジェクト: nekoya/SmartCSS
<?php

require 'Console/Getopt.php';
require 'libs/SmartCSS.class.php';
$scss = new SmartCSS();
$scss->run();