Back Home

This post is a follow up to my previous post entitled Less annoying CSS using PHP Preprocessing. It's a refactoring of the original code that's evolved through various projects I've thrown it at.

I'd like to think that the quality of the code is higher since I now consider it far more maintainable. Strikingly, it now is implemented as a class since I never liked having the guts of the implementation visible through all of its helper functions and callbacks.

It is not, mind you, an attempt to make it faster, just more maintainable and powerful, so caching is absolutely necessary on a high traffic website (when is it not though).

So, the complete feature set is now:

Allows for nested selectors
The following is valid code:
Constants
Constants may be defined, and may be overridden like CSS rules.
Imports are performed
CSS imports are now expanded inline with some restrictions. They need to be relative paths, and they need to be relative to the "$base_path" specified while calling the processor. Also, because I didn't want to fiddle with the Regex anymore, I've made it require double quotes around the path. If a file can't be imported, it's treated as an empty CSS file.

For example, the following piece of code would perform the imports and then perform preprocessing:

Single Line Comments
I found this too annoying to allow. I found myself using single line comments (of the double forward slash variety) and getting CSS errors. Never again
Minification (Compression)
I'm stripping everything out that I think isn't necessary and doesn't seem to affect the final rendered page (whitespace, empty rules, etc). I haven't yet encountered anything that's troublesome, but please let me know if you do.

Without Further Ado... he's the code: