Add a docs option to the types and block tags - #4870
Conversation
|
I like |
|
I forgot to close the issue, since I closed the initial PR #4770. We went for symfony/ux#3694 in UX, and also in the PhpStorm plugin Haehnchen/idea-php-symfony2-plugin#2826 |
|
See #4871 |
|
📋 PR Summary This PR adds an optional Changes
|
| // "docs" followed by "=" is the docs option; "docs" alone might be an | ||
| // expression used as the shortcut syntax for the block body | ||
| $docs = null; | ||
| if ($stream->test(Token::NAME_TYPE, 'docs') && $stream->look()->test(Token::OPERATOR_TYPE, '=')) { |
There was a problem hiding this comment.
🔵 Info — Duplicated, divergent option parsing across two tags raises future maintenance cost.
The docs option is parsed differently in the two tags: BlockTokenParser uses test()+look() and silently falls back to the shortcut body when docs is not followed by =, while TypesTokenParser uses nextIf()+expect() and raises The "docs" option must be followed by an equal sign (=). The divergent block behavior is required to preserve the {% block title docs %} shortcut, but the two implementations duplicate the option-detection logic with different error semantics, so a future change to the option (e.g. renaming docs to desc) must be made in two places kept manually in sync.
|
Closing in favor of #4871 |
Implements the design proposed by @fabpot in #4768:
{% types %}entry accepts an optionaldocs="..."option after the type string; it is stored in theTypesNodemapping (docsisnullwhen not provided){% block %}tag accepts an optionaldocs="..."option after the block name; it is stored as adocsattribute on theBlockNode(new optional constructor argument, BC)The tags themselves do not use this documentation: it is metadata for tools (IDEs, documentation generators, the Symfony UX Toolkit) that analyze the parsed nodes.
Notes:
{% block %},docsis only treated as an option when followed by=, so the shortcut syntax{% block title docs %}(printing a variable nameddocs) keeps working; this is covered by a test.docsas originally proposed; renaming it todescis a one-line change if preferred.Closes #4768