Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom twig tags #35

Merged
merged 10 commits into from
Mar 1, 2020
Merged

Custom twig tags #35

merged 10 commits into from
Mar 1, 2020

Conversation

twbartel
Copy link
Collaborator

ATTENTION: Before merging this, https://github.com/trivago/melody/pull/154/commits has to be merged and released.

This merge request makes use of a new capability in the Melody parser to handle non-standard/unknown Twig tags.

By default, all unknown Twig tags will be handled and printed in a best-effort fashion that should be appropriate for a lot of Twig tags.

Additionally, a new option twigMultiTags is introduced which can be used to tell the parser about tag names that belong together, like nav and endnav. Example inspired by Craft CMS:

twigMultiTags: [
    "nav,endnav",
    "switch,case,default,endswitch",
    "ifchildren,endifchildren",
    "cache,endcache"
]

This will basically add indentation to everything between the first and the last tag. Tag names must be comma separated.

@twbartel twbartel mentioned this pull request Feb 27, 2020
@sjelfull
Copy link

One tiny syntax thing: The twigMultiTags tag names could maybe be an array instead of comma separated list.

@twbartel
Copy link
Collaborator Author

twbartel commented Feb 27, 2020

@sjelfull Totally agree. I wanted to make them an array. However, I did not find a way to get that through Prettier's validation of options. If you know how to do that, please tell me! :-)

EDIT: To elaborate a bit more, this is how the option is defined:

twigMultiTags: {
    type: "path",
    category: "Global",
    array: true,
    default: [{ value: [] }],
    description: "Make custom Twig tags known to the parser."
}

I use type: "path" because it's the only string type available. There is only a handful of types allowed, and "array" is not one of them. I can tell Prettier that twigMultiTags should be an array by setting array: true, but I have not found a way to tell Prettier that the passed value should be an array of an arrays.

@twbartel twbartel changed the title [WIP] Custom twig tags Custom twig tags Mar 1, 2020
@twbartel twbartel merged commit a428c7b into master Mar 1, 2020
@twbartel twbartel deleted the custom-twig-tags branch March 1, 2020 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants