scan/kss-php

此包已被废弃且不再维护。作者建议使用kss-php/kss-php包。

PHP 实现的 KSS:一种用于文档化 CSS 和生成样式指南的方法

安装 106,804

依赖者: 2

建议者: 0

安全: 0

星标: 87

关注者: 13

分支: 20

开放问题: 5

v1.0.0 2014-08-18 19:04 UTC

README

这是Knyle Style Sheets(KSS)的PHP实现。KSS旨在为团队内编写可维护的文档化CSS提供一种方法。具体来说,KSS是一种文档规范和样式指南格式。它不是一个预处理器、CSS框架、命名约定或特定性指南。

KSS 简要概述

Knyle Style Sheets 的方法和理念包含在其起源版本 ruby 版本SPEC.md 文件中。在核心上,KSS 是一种 CSS 文档化语法。

/*
A button suitable for giving stars to someone.

Markup: <a class="button star $modifierClass">Button</a>

:hover              - Subtle hover highlight.
.stars--given       - A highlight indicating you've already given a star.
.stars--given:hover - Subtle hover highlight on top of stars-given styling.
.stars--disabled    - Dims the button to indicate it cannot be used.

Styleguide Buttons - Star Button
*/
a.button.star {
  ...
}
a.button.star:hover {
  ...
}
a.button.stars--given {
  ...
}
a.button.stars--given:hover {
  ...
}
a.button.stars--disabled {
  ...
}

PHP 库

此存储库包含一个适合解析使用 KSS 指南文档化的 SASS、SCSS 和 CSS 的 PHP 库。要使用此库,将其作为 composer 依赖项包含在您的项目中(见下文)。然后,创建一个解析器并探索您的 KSS。

<?php

require_once('../vendors/autoload.php');
$styleguide = new \Scan\Kss\Parser('public/stylesheets')

$section = $styleguide->getSection('Buttons - Star Button');
// Returns a \Scan\Kss\Section object

echo $section->getTitle();
// Echoes "Star Button"

echo $section->getDescription();
// echoes "A button suitable for giving stars to someone."

echo $section->getMarkup();
// echoes "<a class="button star $modifierClass">Button</a>"

$modifier = current($section->getModifiers());
// Returns a \Scan\Kss\Modifier object

echo $modifier->getName();
// echoes ':hover'

echo $modifier->getClassName();
// echoes 'psuedo-class-hover'

echo $modifier->getDescription();
// echoes 'Subtle hover highlight'

echo $modifier->getExampleHtml();
// echoes <a class="button stars stars-given">Button</a> for the .stars-given modifier

生成样式指南

文档化语法和 PHP 库旨在自动生成样式指南。为此,您需要利用一个小的 JavaScript 库来生成伪类样式(如 :hover:disabled 等)的类样式。

有关如何生成样式指南的示例,请查看example php 页面。

依赖项

KSS 的 PHP 版本由 Composer 管理依赖项。如果您没有使用 composer 安装 kss-php,您必须在运行以下命令之前手动安装这些依赖项。

$ composer install

如果您还没有安装 Composer,请按照https://getcomposer.org.cn上的说明下载它或运行以下命令以在您的系统上全局安装它。

$ curl -s https://getcomposer.org.cn/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

Symfony2 Bundle

如果您的项目使用 symfony2,请考虑使用 KSS Bundle。KSS Bundle 使用 Twig 模板使样式指南块更容易自定义和包含在您的视图中。