CSSTidy Add @import CSS Functionality

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
w0lf42
Forum Newbie
Posts: 3
Joined: Sun Aug 17, 2008 3:28 pm

CSSTidy Add @import CSS Functionality

Post by w0lf42 »

Goal
Add the following functionality to CSSTidy:
ability to import a CSS file which has @import calls to other CSS files and treat all selectors as if they exist in the main CSS file

So, if main.css contains the following code:

Code: Select all

@import url('../styles/global/reset.css');
@import url('/styles/themes/helloWorld/structure.css');
@import url('/styles/themes/helloWorld/presentation.css');
Import all of those selectors into one file and perform formatting and optimizations available to CSSTidy.

I found PHP-CSS-Parser. The Documentation says to:
To access the items stored in a CSSList – like the document you got back when calling $oCssParser->parse() –, use getContents(), then iterate over that collection and use instanceof to check whether you’re dealing with another CSSList, a CSSRuleSet, a CSSImport or a CSSCharset.
I believe this is how i need to start:

Code: Select all

$oCssParser = new CSSParser(file_get_contents('main.css'));
$oCssDocument = $oCssParser->parse();
getContents($oCssDocument);
I'm a PHP Newbie. I'd appreciate any help. THX.
Post Reply