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

Make viable for more use cases #108

Open
dikkadev opened this issue Aug 10, 2024 · 6 comments · May be fixed by #109
Open

Make viable for more use cases #108

dikkadev opened this issue Aug 10, 2024 · 6 comments · May be fixed by #109

Comments

@dikkadev
Copy link

The custom-regex option is great, but it's still only possible to use this when the classes can be in a capture group with nothing else but spaces in between them (at least from all I've tried)

More options would allow Rustywind to be used when the classes are in the files, not as space-separated lists. This needs more than a simple addition but more reworking of the sorter.

Here is a single example of where it would be nice to use.
classes = ["flex", "flex-col", "rounded-xl", "border", "border-teal-600", "p-4", "w-[var(--rhs-width)]"]

Maybe another regex could be used after we have extracted the part that has all the classes (which is the current settable regex) and another that matches each single classes (although then one would also need to define something like a pre- and suffix for a class entry)
Honestly I do not have a good (UX-wise) way in mind to do that.

If you have a better idea and/or would want this feature in rustywind, I'd be happy to also spend some time on implementation.

@praveenperera
Copy link
Member

This would be hard because not only would you have to define how to capture the classes, but also how to output them in the same format, instead of one long string.

@dikkadev
Copy link
Author

Exactly, but I believe this could all be done with more regexes (I don't necessarily love regexes either, but this is the least bad way I could come up with so far.

  1. Define regex where a specific group (named, or only capturing group) that gets us the string that holds all entries. (basically the same as the current custom-regex)
    classes = ["flex", "flex-col", "rounded-xl", "border", "border-teal-600", "p-4", "w-[var(--rhs-width)]"]
    regex ⇒
    "flex", "flex-col", "rounded-xl", "border", "border-teal-600", "p-4", "w-[var(--rhs-width)]"
    
  2. Define a string (not a regex) that defined how to split this string into 'augmented' entries
    "flex", "flex-col", "rounded-xl", "border", "border-teal-600", "p-4", "w-[var(--rhs-width)]"
    split ⇒
    array of strings ["flex", "flex-col", "rounded-xl", "border", "border-teal-600", "p-4", "w-[var(--rhs-width)]"]
    
    The downside to this is that it requires that the splitting string is the same between all entries. One could maybe use a regex for this, but the problem would be how to handle rewriting it. There would be two options, either that the splitting strings depends on the position (e.g. after the 3rd entry) or it depends on the actual entry. One cannot know which is correct, thus that would need to be another setting
  3. Define a regex to unaugment the entries.
    "flex"
    regex ⇒
    flex
    
  4. Sort just like now
  5. Reaugment the entries. If we have kept some reference to the augmented entries, we can just use that using the sorted order from the clean entries.
  6. Join it. Simply join the augmented entries, now in sorted oder, back together with the splitting string.
  7. Put it back in it's place. If we have the match from the first step, we can use the group we used there to replace just that with the result from the last step.
  8. Profit!!

I don't there is much missing here, and that this would cove a lot of cases (see note on the splitting step). The regular option with just custom-regex could be kept and this new 'process' would be used if all the other needed parameters are given (If one is there, all if them must be there)

@praveenperera
Copy link
Member

maybe instead of a regex inside a regex we can have an enum that describes how to get the classes from the capture group, the options would be

  • default (current way, classes separated by space)
  • array (split on comma, remove " or ' if it exists)

then we could use this enum to decide how to write the classes back as well

@dikkadev
Copy link
Author

dikkadev commented Aug 13, 2024

And then save which one it was? (' / "). Or maybe do that enum approach but do it finer, so e.g.

  • default
  • ' with comma
  • ' without comma
  • " with comma
  • " without comma

That would also leave room for better extending it at some point if need be

Edit: typo

@praveenperera
Copy link
Member

I don’t think we need them to tell us about the commas. We can just check that without regex.

Do you want to take a first swing at this?

@dikkadev
Copy link
Author

Yeah sure, no promises about the timeframe tho.
So I'll do the simpler enum variant.

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 a pull request may close this issue.

2 participants