zauberfisch / silverstripe-better-requirements
替换SilverStripe Requirements_Backend
Requires
- silverstripe/framework: ^3.1
- symfony/process: 2.8.*@dev
This package is auto-updated.
Last update: 2024-09-04 07:52:22 UTC
README
进行中
此模块仍在开发中,是SilverStripe Requirements Backend的临时替代品。此模块存在是因为SilverStripe Requirements的当前限制,一旦Requirements重构,它可能改变API或完全过时。
当前功能
- 使用sassc编译sass/scss文件
- 使用less.php编译less文件
安装
使用sassc的要求
- *nix基于的系统。目前不支持Windows服务器
- php需要能够执行shell命令
- php需要写入css文件和combined_files文件夹的权限
- sassc需要安装到您的系统上。如果您的sassc可执行文件不在任何路径中,您可以将常量SS_SASSC_PATH设置为您自己的路径(例如:
define('SS_SASSC_PATH', '/path/to/sassc')
)。
使用less的要求
- Composer包
leafo/lessphp
安装模块
- 使用Composer安装模块或下载并放置到您的项目文件夹中
- 运行
?flush=1
安装sassc
如果您的系统没有安装sassc,您还需要安装它。截至本文撰写时,我知道没有现成的包或预编译的二进制文件,因此您可以选择自己编译它或使用Zauberfisch的定期构建(debian)(此链接可能会在未来更改)。
(注意:在共享主机上可能无法使用sassc,但在某些主机上可以通过将二进制文件上传到您的项目文件夹并设置define('SS_SASSC_PATH', BASE_PATH . '/sassc')
使其工作)
使用
单独使用此模块不会做任何事情。您必须设置Requirements的后端。一个好的地方是在PageController->init()
中这样做,但也可能在其他地方。只需确保在使用任何其他Requirements方法之前设置后端即可。
class PageController extends \SilverStripe\CMS\Controllers\ContentController {
// ...
public function init() {
Requirements::set_backend(new \BetterRequirements\Backend());
parent::init();
// ...
}
// ...
}
之后,您可以使用Requirements与之前一样,只需添加一个附加功能:您现在可以要求sass/scss/less文件。
后端将替换文件路径中的'sass'/'scss'/'less'并追加'.css'。
// create and require mysite/css/myfile.scss.css
\SilverStripe\View\Requirements::css(project() . '/scss/myfile.scss');
// will create and require mysite/css/otherfile.sass.css
\SilverStripe\View\Requirements::css('mysite/sass/otherfile.sass');
// will create and require themes/mytheme/css/myfile.less.css
\SilverStripe\View\Requirements::css($this->ThemeDir() . '/less/myfile.less');
// it also works with combined files and mixed file types:
\SilverStripe\View\Requirements::combine_files('main.css', [
project() . '/css/normal-file.css',
project() . '/scss/scss-file.scss',
project() . '/less/less-file.less',
project() . '/scss/main.scss',
project() . '/less/main.less',
]);
编译/预处理
在以下条件之一满足时将进行编译/预处理
?flush=1
(将重新编译所有文件)- 配置
\BetterRequirements\Backend.compile_in_live
- 站点处于开发模式,并且配置
\BetterRequirements\Backend.compile_in_dev
为true
您可以在yml配置文件中更改此配置
\BetterRequirements\Backend:
compile_in_live: true # default: false
compile_in_dev: true # default: true
如果您在更改文件后遇到文件编译延迟较长的情况,请尝试更改缓存键为md5_file,这样文件检查将实际考虑内容而不是文件时间戳
\BetterRequirements\Backend:
cache_key_method: 'md5_file' # default: 'filemtime'
注意
当在本地(开发)以及服务器(例如部署后自动化的)编译您的sass/scss文件时,建议将CSS文件添加到.gitignore并从版本控制中排除。
Composer 目前与 sassc 不兼容,但有一个解决方案:Composer 是 Ruby 和 Sass 的混合体,您可以使用 Sass 部分与 sassc 一起使用,只会丢失少量功能(如 image-height、image-width、sprite 函数等)。可以从 Igosuki/compass-mixins 获取 compass mixins,并查看 Zauberfisch 的 SilverStripe 模板 以了解示例用法。
许可证
Copyright (c) 2015, Zauberfisch
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name Zauberfisch nor the names of other contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.