Allow sorting classes inside function calls in Twig templates#358
Allow sorting classes inside function calls in Twig templates#358thecrypticace merged 11 commits intotailwindlabs:mainfrom
Conversation
…e formatting consistency - Added support for `attributes.addClass()` in Drupal Twig templates. - Updated test cases to validate new `addClass` functionality. - Improved formatting consistency in TypeScript code for better readability. - Added .DS_Store to .gitignore to prevent unnecessary files from being tracked.
|
@thecrypticace Thanks for the code revisions. Any plans to release this feature in the near future? |
|
I think we could also consider support for https://www.drupal.org/docs/8/theming-drupal-8/using-attributes-in-templates#s-attributesremoveclass |
|
I still have to do some thinking about the implementation as there's a disconnect between how call expressions are walked in JSX and Twig. That might be fine to have a slight difference in behavior but not sure.
This implementation supports any function call. I made it generic. Our plugin already has affordances for sorting in function calls via the See the updated tests. |
|
I've decided that, even though there's a disconnect, that it's probably okay. We could always tweak it by doing a walk toward the inside (like this PR does) and a walk toward the outside (like JSX) and matching against either if we wanted to have similar-ish behavior. |
|
This will go out in v0.7.0 next week. Thanks! |
|
So good to hear that! Thank you very much for your work on this 😁 |
Support for
prettier-plugin-tailwindcss-drupalDescription
This PR adds support for the
prettier-plugin-tailwindcss-drupalby including it in the plugin's supported file types and processors.The Drupal-specific plugin extends the sorting logic to match Tailwind conventions commonly used in Drupal theme development, including handling template attributes such as
attributes,title_attributesorcontent_attributes.Problem
Tailwind projects built within Drupal environments often rely on custom attributes, classes, and template structures (e.g.,
.html.twigfiles).The default Tailwind Prettier plugin does not handle these files or Drupal-specific class patterns out-of-the-box.
Solution
.html.twigand other Drupal-related file types as supported.prettier-plugin-tailwindcss-drupal, which is built on top of the core plugin but tailored to the Drupal ecosystem.attributes.addClass()), commonly used for dynamic class injection.Testing
.html.twigtemplates with embedded Tailwind classes.npm testto confirm plugin compatibility.