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

Feature/custom regex #190

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

HarwinBorger
Copy link

@HarwinBorger HarwinBorger commented Nov 15, 2017

I ran into a problem where not enough classes from the Foundation FrameWork were filtered. So i decided to make some adjustments to the purifying plugin.

I also found an outdated pull request to stricter purifying (#139 ). I figured out that it would be usefull if people could write their own regex to fit their own needs.

This features add the option to modify the regex expression to purify the css. For me this saved up to **~ 33.6%** instead of only **~ 8.7%**. This makes big sense to me.

You can use it option by adding the option regex to your config file. By default the regex splits words on everything which is not a-z. By adjusting the regex to a-z_- it doesn't split whole classes in half any longer.

Use for example:

purifycss: {
	options: {
		regex: 'a-z_-' // default: 'a-z'
	}
}

So instead of accepting .block-padding and .block-padding-vertical when only .block-padding is used. It now filters .block-padding-vertical since this one is not used.

This also means that you can filter a lot of unused Foundation Framework classes like:

.large-offset-0
.large-offset-1
.large-offset-2
.large-offset-3
.large-offset-4
.large-offset-5
...

I hope you find this usefull and accept my request.

@akabiru
Copy link

akabiru commented Feb 6, 2018

Please please merge this. 🙏 🙂

@HarwinBorger
Copy link
Author

I saw that a friendly 'Bump' works for merging:

Bump (A) @kennyt @Ffloriel @Illyism

This feature could solve the problems in: #184 #189 #178 #175 and probably many more

@Illyism
Copy link
Contributor

Illyism commented Mar 18, 2018

Good PR. However I feel like limiting the regex to always be inside [] is not a good idea. Would it be possible to change it so that you're able to define any regex? Or change the description of the "regex" option.

@Ffloriel
Copy link
Contributor

I agree. It would be better to pass the full regex as the option.

purifycss: {
	options: {
		regex: /[a-z_-]/g // default: /[^a-z]/g
	}
}

@Illyism the next version could be release as 1.3.0, fixing #180

@loadedsith
Copy link

Generalized regex or not, we need this. 👍

@HarwinBorger
Copy link
Author

HarwinBorger commented Mar 24, 2018

I had to dive into the code again, since it has been a while. To following choices I've made for this implementation:

In the original code you use 2 different kinds of regex. Those are:
/[^a-z]/g
and
/[a-z]/

The solutions I choose support of regex does fit in both kinds of regex. I think it's an obstacle to let the user define both full regex since the regex need each other. It is easier to only define the inner part of the regex: a-z or or a-z_-. This is less error prone.

Their for since this solution is probably already solving the problems we know off I think this solution is fine for now. I will change the description of what the regex attribute does.

If we think a full regex solution is needed in the future we could adjust the script by that time, since full regex support is more complicated to build in.

@HarwinBorger
Copy link
Author

HarwinBorger commented Mar 24, 2018

@Illyism @Ffloriel I updated the description of the regex option, improving the explaining of what you can do with it. If you think more changes are necessary please let me know 👍

Also thank you for taking this pull request under consideration 😄

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.

None yet

5 participants