Tailwind-Formatter icon indicating copy to clipboard operation
Tailwind-Formatter copied to clipboard

Any plan on supporting Tailwind classes in Ruby files?

Open xdmx opened this issue 1 year ago • 5 comments

I've just discovered this plugin and it seems working great! I'm using it with Rubymine.

One thing that I've noticed is that it formats html files, but not Ruby ones. I'm having Ruby classes with components where sometimes I set the class to be reused in the html, something like:

  LEVELS = {
    danger: "border-transparent shadow-sm text-white bg-red-500 hover:bg-red-600",
    primary: "shadow-sm text-white border-transparent bg-emerald-500 hover:bg-emerald-600",
    secondary: "border-transparent text-emerald-700 bg-emerald-100 hover:bg-emerald-200",
    tertiary: "border-gray-300 shadow-sm text-gray-700 bg-white hover:bg-gray-50"
  }.freeze

  def button_classes
    "inline-flex justify-center items-center py-2 px-4 select-none " \
    "text-sm font-normal rounded-md border cursor-pointer text-center " \
    "focus:ring-2 focus:ring-emerald-500 focus:ring-offset-2 focus:outline-none " \
    "#{LEVELS[level]}"
  end

It'd be nice if this plugin was able to reformat those as well. I don't know if that'd even be possible (especially the multi line ones, but I could format them first, and then manually split the line)

xdmx avatar Dec 01 '22 11:12 xdmx

Can you link me a few files to test against?

WalrusSoup avatar Jan 16 '23 20:01 WalrusSoup

Sure, I've uploaded a couple of example files here (removing most of the ruby logic): https://pastebin.com/GDmBUBFh https://pastebin.com/bx4SPm6j

Let me know if you'd need more

xdmx avatar Jan 19 '23 10:01 xdmx

So this is challenging and I'm not sure what approach to take. For the PsiElements API to work, the IDE would need to support ruby in order to crawl and identify which nodes are plain text. Which isn't much different than just processing plain text with regex & checking if most of it is tailwind. It feels really messy, so I'm still thinkin things over.

WalrusSoup avatar Jan 24 '23 19:01 WalrusSoup

Would it make it easier to support this only on Rubymine, as it understands Ruby and hopefully identifies those nodes as plain text? :thinking:

xdmx avatar Jan 24 '23 20:01 xdmx

I think so, ill download & play with rubymine and see how far I get with this when I have time.

WalrusSoup avatar Feb 07 '23 20:02 WalrusSoup