aretecode / planck-id
压缩(几乎)所有的 HTML id 和类名,以及 CSS + JS 选择器
Requires
- php: >=5.6.0
- illuminate/support: dev-master
- league/event: 2.1.*
- league/flysystem: 1.0.*
- league/flysystem-memory: 1.0.*
- phpflo/phpflo: dev-master
- symfony/console: ~2.0
- symfony/var-dumper: 3.0.*
Requires (Dev)
- behat/behat: ~3.0
- phpunit/phpunit: 5.1.*
This package is not auto-updated.
Last update: 2024-09-14 18:42:06 UTC
README
这是什么?
压缩(几乎)所有的 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
安装
可以使用 Packagist 和 Composer 安装。确保您的 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>
,然后将内容传递到一系列组件中,以实现预期的结果。
运行测试
- 通过导航到
planck-id/tests/Run.php
在浏览器中运行 - 通过将目录更改到
planck-id/bin
,然后运行behat
通过命令行运行 - 通过进入
planck-id
并运行phpunit
通过命令行运行
(这些测试使用了thegrids网站的一个片段)