wbf/compiler

样式编译的辅助组件

dev-master 2016-12-01 13:09 UTC

This package is not auto-updated.

Last update: 2024-09-28 19:52:52 UTC


README

一个可扩展的样式编译器。

目前它内置了Less编译器,但开发者可以通过Base_Compiler接口实现新的编译器。

LESS文件的使用示例

//Setup the base compiler:
$output_dir = "...."

$base_compiler = new WBF\components\compiler\less\Less_Compiler([
    "sets" => [
        "theme_frontend" => [
            "input" => get_stylesheet_directory()."/assets/src/less/input.less",
            "output" => $output_dir."/output.css",
            "map" => $output_dir."/output.css.map",
            "map_url" => $output_uri."/output.css.map",
            "cache" => get_stylesheet_directory()."/assets/cache",
            "import_url" => get_stylesheet_directory_uri(),
            "primary" => true //This is the primary set (by now this is just a label for further usage)
        ]
    ],
    "sources_path" => get_stylesheet_directory()."/assets/src/less/"    
]);

//Create a new instance of compiler
$c = new components\compiler\Styles_Compiler($base_compiler); //This is a wrapper which rely on Base_Compiler implementation of $base_compiler.

$c->compile(); //Wraps the call to $base_compiler compile() method

如果与WordPress或用户动作挂钩,编译动作更有用。

集合

Base_Compiler提供了add_set()remove_set()函数,而compile()函数允许指定要编译的集合名称。因此,新的编译器需要在考虑这一概念的情况下开发。

集合有一个名称和一些用数组指定的属性。

例如,这是一个适用于Less_Compiler的集合

[
    "input" => "...",
    "output" => "...",
    "map" => "...",
    "map_url" => "...",
    "cache" => "...",
    "import_url" => "...",
    "primary" => true
]

属性的数目是任意的。