redcatphp/stylize 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

redcatphp/stylize

最新稳定版本:v2.4.3

Composer 安装命令:

composer require redcatphp/stylize

包简介

Stylize - Css Preprocessor using Scss syntax ( SASS 3.x ) ported to PHP with added supports: php imbrication, php mixin, mixin autoload, extend autoload, font autoload - derived from leafo-scssphp

README 文档

README

Stylize is a CSS Pre-processor using Scss syntax from SASS ( version 3.x ) ported to PHP with additional features.
If you're not familiar with this language, you can consult the basic documentation on SASS. I'll describe here only the PHP API and exclusive features of Stylize. The source code is derived from the excellent leafo-scssphp.

Additional Features to SCSS

Basic Usage

Compiler

$scss = new \\RedCat\\Stylize\\Compiler();  
$scss->setImportPaths(['css']);  
$scss->addImportPath('redcat/css');  
$scss->compile(file_get_contents('css/style.scss'));  
            

Server

The server will handle cache and rebuild it only if the files has changed and also deal in HTTP via Etag and Last-Modified. It also include by default, if they are present, "_config.scss" and "_var.scss". It will use a cache directory by default which is ".tmp/stylish/" from current working directory and which need to be writeable (chmod 0777).

$server = new \\RedCat\\Stylize\\Server();  
$directories = ['css','redcat/css'];  
$server->serveFrom('style.scss',$directories);  
            

PHP Support

The php will be executed before SCSS syntax parser.
By dint of tokenizer, the php support allow you tu use short php syntax even if short_open_tag is not enabled in php.ini.

Imbrication

$img-path'<?=$img_path?>' !default;  
  
<?if($bool){?>  
    // here is your scss code  
<?}?>  
  
<?foreach($elements as $key=>$val):?>  
    // here is your scss code  
<?endforeach;?>  
            

Hybride PHP Mixin

The hybride PHP mixins allow you to get your parameters passed to include as php variables in mixin declaration and using a different syntax for include parameters.
The syntax of hybride php mixins parameters is simple: the separator is the comma "," and no quotes are required, all parameters will be automaticaly typed.
The difference in declaration is that you have to use a "@?" instead of "@" and same for include: "*@?mixin " instead of "@mixin " and "@?include " instead of "@include *".
Let's take an example of declaration (the grid from RedCat's SCSS Toolbox):

@import "include/grid.reset-star";  
@?mixin grid{<?  
    $selector = is_string($e=current($args))&&!is_numeric(str_replace(array('-',',','.'),'',$e))?array_shift($args):false;  
    $mw = is_string($e=end($args))&&substr($e,-2)=='px'?array_pop($args):false;  
    $tt = 0;  
    foreach($args as $i=>$w){  
        ?>  
            <?if($mw):?>  
                @media(min-width:<?=$mw?>){  
            <?endif;?>  
                <?if($selector):?>  
                    ><?=$selector?>{  
                <?else:?>  
                    >*:nth-child(<?=$i+1?>){  
                <?endif;?>  
                        <?if(!$mw):?>  
                            positionrelative;  
                            display:block;  
                            float:left;  
                            min-height1px;  
                            -webkit-box-sizingborder-box;  
                            -moz-box-sizingborder-box;  
                            box-sizingborder-box;  
                        <?endif;?>  
                        <?if($tt>=100):?>  
                            <?$tt = 0;?>  
                            clear:left;  
                        <?else:?>  
                            clear:none;  
                        <?endif;?>  
                        <?  
                            if(is_string($w)){  
                                @list($margin_left,$w,$margin_right) = explode(',',str_replace('-',',',$w));  
                                if($margin_left){  
                                    ?>margin-left:<?=$margin_left?>%;<?  
                                    $tt += $margin_left;  
                                }  
                                if($margin_right){  
                                    ?>margin-right:<?=$margin_right?>%;<?  
                                    $tt += $margin_right;  
                                }  
                            }  
                            ?>width: <?=$w?$w.'%':'auto'?>;<?  
                        ?>  
                    }  
            <?if($mw):?>  
                }  
            <?endif;?>  
        <?  
        $tt += $w;  
    }  
?>}?@  
            

And then, a usage:

body>header>h1>a{  
    @?include grid(*,    2-96-2);  
    @?include grid(100        ,1-48-1,    1-48-1,    480px);  
    @?include grid(1-51-1    ,1-21-1,    1-21-1,    768px);  
}  
            

Autoload Support

Mixin

If the mixin to include isn't allready defined when used, the autoload support will look for presence of file corresponding to name of mixin in import paths followed by "include" and then ".scss" extension: $import-path/include/$name-of-mixin.scss. If they exists it will import them.

@include clearfix();  
@?include icon(css3);  
            

This code will trigger autoload to look for include/clearfix.sccs and include/icon.scss in the import paths and import them.

Extend

If the class to extend isn't allready defined when used, the autoload support will look for presence of file corresponding to name of class in import paths followed by "extend" and then ".scss" extension: $import-path/extend/$name-of-class.scss. If they exists it will import them.

body>footer>div:first-child{  
    @extend %surikat-powered;  
}  
            

This code will trigger autoload to look for extend/surikat-powered.scss in the import paths and import it.

Font

If the font-face declaration corresponding to font-familly which is used isn't allready defined when used, the autoload support will look for presence of file corresponding to name of font-family (lowercase and with spaces replaced by hyphen -) in import paths followed by "font" and then ".scss" extension: $import-path/font/$name-of-font.scss. If they exists it will import them. That doesn't work with variable font-name.

header{  
    font-family: Indie Flower;  
}  
body{  
    fontbold 10px Rock Salt;  
}  
            

This code will trigger autoload to look for font/indie-flower.scss and font/rock-salt.scss in the import paths and import it.

redcatphp/stylize 适用场景与选型建议

redcatphp/stylize 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 772 次下载、GitHub Stars 达 5, 最近一次更新时间为 2015 年 11 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「autoload」 「css」 「sass」 「scss」 「stylesheet」 「font」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 redcatphp/stylize 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 redcatphp/stylize 我们能提供哪些服务?
定制开发 / 二次开发

基于 redcatphp/stylize 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 772
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 19
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0
  • 更新时间: 2015-11-04