aretecode/planck-id

压缩(几乎)所有的 HTML id 和类名,以及 CSS + JS 选择器

dev-master / 0.11.2.x-dev 2016-05-06 03:17 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:42:06 UTC


README

#PlanckId (planck-id) Build Status HHVM Status License Latest Unstable Version Codacy Badge shrinking

这是什么?

压缩(几乎)所有的 HTML id 和类名,以及 CSS + JS 选择器。

示例

将这个

<a href="https://packagist.org.cn/login/github" class="pull-right btn btn-primary btn-github">
    <span class="icon-github" id="special_github"></span>Use Github
</a>
<style>.pull-right, .btn, .btn-primary, .btn-github, .icon-github {} #special_github{}</style>
<style>.btn{}</style>
<script>var githubButtons = document.getElementsByClassName('btn-github'); var specialGithub = document.getElementById('special_github');</script>
<script>githubIconButtons = $('.icon-github');</script>

转换为这个

<a href="https://packagist.org.cn/login/github" class="c e a d">
    <span class="b" id="f"></span>Use Github
</a>
<style>.c, .e, .a, .d, .b {} #f{}</style>
<style>.e{}</style>
<script>var githubButtons = document.getElementsByClassName('d'); var specialGithub = document.getElementById('f');</script>
<script>githubIconButtons = $('.b');</script>

图表

planck-id/graphs 中的 .json 文件放入 NoFlo

安装

可以使用 PackagistComposer 安装。确保您的 composer.json 包含

{
    "require": {
        "aretecode/planck-id"
    }
}

然后,运行

$ wget https://getcomposer.org.cn/composer.phar
$ php composer.phar install

使用

基本用法

查看示例

命令行

转换名为 markup.html 的文件

planck markup.html

转换名为 markup.html 的文件

planck markup.html --debug

转换文件并保存其输出

planck markup.html > output.html

使用现有映射替换样式文件转换文件

planck style.css map.json style Replace

使用现有映射,提取更多内容添加到映射中,然后替换样式文件

planck style.css map.json style ExtractAndReplace

提取文件内容并将其添加到映射中

planck markup.html map.json markup Extract

从 STDIN 转换

echo -e '<section class="post-simple media-adjacent"></section><style>.post-simple{}</style>' | planck

从 STDIN 转换并保存输出

echo -e '<section class="post-simple media-adjacent"></section><style>.post-simple{}</style>' | planck > output.html

术语

  • Planck: (普朗克长度,原则上,最短的可测长度。) 最短有效类名/ID/选择器的一个实例。
  • 原始:在它被转换为 Planck 之前的 类名/ID/选择器。(我可以更改这个,欢迎提出新术语的建议。)

它是如何做到这一点的?

使用基于流的编程,根据需求创建一个map<original, planck>,然后将内容传递到一系列组件中,以实现预期的结果。

运行测试

  1. 通过导航到planck-id/tests/Run.php在浏览器中运行
  2. 通过将目录更改到planck-id/bin,然后运行behat通过命令行运行
  3. 通过进入planck-id并运行phpunit通过命令行运行

这些测试使用了thegrids网站的一个片段

待办事项