jadu/twig-style
Composer 安装命令:
composer require jadu/twig-style
包简介
Jadu Twig coding style configuration for Twig-CS-Fixer
README 文档
README
Jadu Twig style is powered by Twig-CS-Fixer.
Installation
- Require the jadu/twig-style dev dependency:
composer require --dev jadu/twig-style
- Add the twig-cs-fixer config file
.twig-cs-fixer.php:
<?php use Jadu\Style\Twig\Standard\JaduStandard; use TwigCsFixer\Config\Config; use TwigCsFixer\File\Finder; use TwigCsFixer\Ruleset\Ruleset; $finder = Finder::create() ->in(__DIR__ . '/src') ->ignoreVCSIgnored(true); $config = new Config(); $config->setFinder($finder); $ruleset = new Ruleset(); $ruleset->addStandard(new JaduStandard()); $config->setRuleset($ruleset); return $config;
- Add
.twig-cs-fixer.cacheto your project's.gitignorefile.
Usage
Dry run
To lint your project's twig files, run the following dry run command:
vendor/bin/twig-cs-fixer lint
This command will return a list of twig-cs-fixer violations and is recommended for build tasks.
Fix
To fix any reported fixable violations, run the following fix command:
vendor/bin/twig-cs-fixer lint --fix
Jadu Twig Coding Standard Rules
This standard is based on the official Twig coding standards, with the following additions and changes:
Block spacing and new lines
There must be one new line before block tags and one new line after endblock tags.
{% block aside %}
<div class="aside">
{% block aside_inner %}
{% block before_primary_supplements %}
{% endblock %}
{% block primary_supplements %}
{% endblock %}
{% block after_primary_supplements %}
{% endblock %}
{% endblock %}
</div>
{% endblock %}
The following exceptions apply:
-
Inline blocks are allowed.
<body class="{% block body_classes %}{{ bodyClasses }}{% endblock %}">
-
Comments on the line above block tags are allowed.
{# This block adds a container around the aside #} {% block aside_container %}
Endblock names
Any endblock tags must be followed by the name of the block they are closing.
{% block aside_container %}
{% endblock aside_container %}
No spaceless tags
The spaceless tag was deprecated in Twig 1.38 and 2.7.31 and an equivalent spaceless filter was introduced. Usages of the spaceless tag must be replaced with the equivalent apply spaceless filter.
{% apply spaceless %}
{% endapply %}
No filter tags
The filter tag was deprecated in Twig 1.402 and 2.93 in favour of the apply tag, which behaves identically to filter except that the wrapped template data is not scoped. Usages of the filter tag must be replaced with the equivalent apply tag.
{% apply lower|escape('html') %}
<strong>UPPERCASE TEXT</strong>
{% endapply %}
{# outputs "<strong>uppercase text</strong>" #}
Punctuation spacing
A single space is required after the opening and before the closing of a hash.
{{ { 'foo': 'bar', 'baz': 'qux' } }}
The following exceptions apply:
- Empty hashes must not contain any whitespace.
{% set emptyHash = {} %}
Variable names
Variable naming conventions are not enforced.
Development
The rules in the Jadu\Style\Twig\Rule\Development namespace are provided for development purposes to help with maintaining Jadu Twig style.
You will need to update your project's twig-cs-fixer config file .twig-cs-fixer.php to enable these rules, as non-fixable rules are disabled by default.
<?php use Jadu\Style\Twig\Rule\Development\TokenTypeRule; use TwigCsFixer\Config\Config; use TwigCsFixer\File\Finder; use TwigCsFixer\Ruleset\Ruleset; $finder = Finder::create() ->in(__DIR__ . '/src') ->ignoreVCSIgnored(true); $config = new Config(); $config->setFinder($finder); $ruleset = new Ruleset(); $ruleset->addRule(new TokenTypeRule()); $config->setRuleset($ruleset); $config->allowNonFixableRules(); return $config;
TokenTypeRulehelps you see how a twig template is tokenized by Twig-CS-Fixer by mapping token types to values.
Footnotes
jadu/twig-style 适用场景与选型建议
jadu/twig-style 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15.87k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 02 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 jadu/twig-style 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jadu/twig-style 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 15.87k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2024-02-20