kevinbaubet/kss-php-markup

这是 kss-php 的一个扩展,用于通过 URL 和 HTML 选择器获取标记。

1.0.1 2018-10-16 12:08 UTC

This package is auto-updated.

Last update: 2024-09-17 02:02:00 UTC


README

这是 Knyle Style Sheets PHP (KSS) 的一个扩展([KSS](https://github.com/kss-php/kss-php))。KSS PHP Markup 为样式文件中编写标记添加了新方法。标记可以通过 URL 和 HTML 选择器生成,并且可以被缓存。

之前

/*
Markup: <ul class="list list--primary">
<li class="list-item">
    <article>
        <h2>Title</h2>
        ...
        ...
    </article>
</li>
</ul>

Styleguide Lists - Primary
*/
.list--primary {
    ...
}

之后

/*
Markup: url(http://site.com/news)->find(.list--primary)->filter(.list-item)

Styleguide Lists - Primary
*/
.list--primary {
    ...
}

PHP 库

<?php

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

$section = $styleguide->getSection('Lists - Primary');
$markup = new \Kss\Markup($section);

echo $markup->getNormal();
// echoes <ul class="list list--primary">...</ul>

$markup->flushcache();
// clean all markup cache, if enabled

语法

/*
Get html markup
Markup: url(http://site.com/news)->find(.classSelector)

Get html markup with urlPrefix option
Markup: url(/news)->find(.classSelector)

Get html markup with filter result
Markup: url(/news)->find(.classSelector)->filter(.classSelector)

Get html markup with filter result and choose length
Markup: url(/news)->find(.classSelector)->filter(.classSelector, 4)
*/

选项

<?php

$options = new \StdClass;
$options->cache = true;
$options->urlPrefix = 'http://site.com';

$markup = new \Kss\Markup($section, $options);