承接 jadu/twig-style 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jadu/twig-style

最新稳定版本:1.1.1

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

  1. Require the jadu/twig-style dev dependency:
composer require --dev jadu/twig-style
  1. 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;
  1. Add .twig-cs-fixer.cache to your project's .gitignore file.

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 "&lt;strong&gt;uppercase text&lt;/strong&gt;" #}

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;
  • TokenTypeRule helps you see how a twig template is tokenized by Twig-CS-Fixer by mapping token types to values.

Footnotes

  1. https://symfony.com/blog/better-white-space-control-in-twig-templates#added-a-spaceless-filter

  2. https://twig.symfony.com/doc/1.x/tags/filter.html

  3. https://twig.symfony.com/doc/2.x/tags/filter.html

统计信息

  • 总下载量: 15.77k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 16
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2024-02-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固