There are several issues with the CSS aggregator. Since they are all very much related I'll try to fix them all in this issue.

I'll also provide extra/better tests.

Comments

Status: Needs review » Needs work

The last submitted patch failed testing.

casey’s picture

Status: Needs work » Needs review
StatusFileSize
new14.42 KB

hmm

Status: Needs review » Needs work

The last submitted patch failed testing.

casey’s picture

Status: Needs work » Needs review
StatusFileSize
new24.41 KB

I tried to create tests first. CSS aggregator however can't handle all tests correctly, so I already disabled some of the new tests. Those can be reenabled when CSS aggregator is ready for them.

Plz review + commit this one first, so I can work from there.

casey’s picture

StatusFileSize
new24.41 KB

retry

rfay’s picture

subscribing - I'll take a look.

rfay’s picture

This looks like great work, and very valuable. I haven't reviewed the code yet.

See also #494498: Add CSS parsing capability to Drupal.

IMO, really valid aggregation AND actually valid tests will be based on parsing and determining that the resultant parse tree is the same.

casey’s picture

StatusFileSize
new34.16 KB

It probably will take a while before an actual css parser will get adopted. I think we should at least fix what s fixable. I also volunteer to work on such a parser afterwards.

Fixes this patch contains:
* added a $flatten parameter to drupal_load_stylesheet() so replacement of @import is optional
* D7 allows to optimize inline css too, however @import's shouldn't get replaced in inline css
* all inline css is merged into one <style> tag; @import should proceed any other style
* strengthened _drupal_build_css_path()
* #265719: CSS aggregator produces invalid code and directory names for @import files Breaks IE, Internet explorer does not style page.
* #511998: CSS aggregator change url path in imported files
* #258846: CSS aggregation fails to parse some url()'s
* Replaced usage of chdir() with a safer approach
* Optimized optimization
* More tests

I copied hacks.css from http://code.google.com/p/minify/source/browse/trunk/#trunk/min_unit_test... and the regexps from http://code.google.com/p/minify/source/browse/trunk/min/lib/Minify/CSS/C.... Does it need credit? Where do I add that?

Status: Needs review » Needs work

The last submitted patch failed testing.

casey’s picture

StatusFileSize
new34.44 KB

This one should pass them all...

casey’s picture

Status: Needs work » Needs review
casey’s picture

Status: Needs review » Needs work

Review is not necessary yet; new patch incoming.

casey’s picture

I created seperate issues for easier reviewing. When they are commited I'll have a look at what is left in this issue.

casey’s picture

StatusFileSize
new53.79 KB

Second thoughts, the issues are so much related that fixing them all at once seems easier to me.

Tests included.

casey’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch failed testing.

casey’s picture

Status: Needs work » Needs review
StatusFileSize
new56.27 KB

Fixed fail + added new test + added more comments to tests.

Review plz.

Status: Needs review » Needs work

The last submitted patch failed testing.

mattyoung’s picture

~

mfer’s picture

There seem to be a lot of changes rolled in here. Some might be bug fixes and some are definitely new features. D7 is past the new features stage and now only bug fixes can go in. Plus, this definitely makes changes to the API and that is frozen as well.

I'd suggest a few things.

First, break the patch up into bug fixes and new features. The new features should go in an issue for Drupal 8 and the bug fixes can stay in an issue for Drupal 7.

Second, per Webchick advice, mega patches that change a bunch of things are bad. She would rather deal with individual patches per thing rather than one patch that does a lot of things. This makes it easier to review and get committed.

Third, share and promote your CSS Preprocessor module in contrib during D7. I'm curious to see how it goes.

For Drupal 8 I'd like to make both the CSS and JS preprocessors pluggable. So, we can swap them out with others from contrib. Some people will use something like YUI Compressor to shrink down CSS and not take the runtime performance hit. Others, could take advantage of what you do here. And, still others just want something simple like what core offers now. What do you think of that?

In past issues we've not been able to get core to do anything complex when it comes to shrinking this stuff down. In the JS preprocessing patch it went in initially and was later removed.

casey’s picture

It's not really containing new features, other than the the seperate 'aggregate', 'optimize' and 'flatten' options in drupal_add_css(). Without these you lose flexibillity, but if necessary I can strip those.

Minimizing is debatable as a new feature, but I disagree. Current HEAD already minimizes CSS, just not that good. And besides, performance improvements are still allowed right? Well this is also a performance improvement.

About the mega patch. see http://drupal.org/project/issues/search/drupal?issue_tags=CSS%20aggregation. I added seperate issues, but they are all very related. It's just much easier to fix them all at once.

The CSS Preprocessor is going to have a real parser; beside that I would put CSS aggregation in a seperate module in core, that module is something else.

CSS and JS preprocessors are pluggable in Drupal 7! drupal_alter('css') makes that possible very easily. That's why I opened this issue: #643534: separate module for CSS aggregation

casey’s picture

Status: Needs work » Needs review
StatusFileSize
new56.27 KB

Status: Needs review » Needs work

The last submitted patch failed testing.

casey’s picture

Status: Needs work » Needs review
StatusFileSize
new56.36 KB

This should do...

mfer’s picture

The CSS and JS preprocessors are not pluggable in core. hook_js_alter and hook_css_alter allow you access to the original files but that does not provide the ability to swap out the preprocessor itself. For example, see http://drupal.org/project/sf_cache. This module allows for multiple preprocessed files in groupings. You would need a pluggable system to support the groupings. Something like #352951: Make JS & CSS Preprocessing Pluggable. This is a good place for a plugin (swappable subsystem) not a module.

When it comes to having a more complex parser 2 things concern me. First, is there a project already doing this we can leverage so we don't duplicate code? Second, slow performance of a more complex parser is why tools like YUI say not to use them in setups like this. So, what is performance like? What is the performance change to drupal core?

You said, "* all inline css is merged into one

tag; @import should proceed any other style" Why should imports proceed any other style? What do you mean by "* strengthened _drupal_build_css_path()"? I mean as far as describing what would be different from there currently. So, we can test a change against a stated description. For D7, is there something that's a bug or is this just a better system? If it's a bug can you describe the bug and how to reproduce it? That should be fixed. If this is about a better system for drupal to use I'm afraid that will have to wait until D8.
rfay’s picture

@casey: It looks to me like you're still adding new features ('preprocess', 'aggregate'), which definitely won't fly.

Please confine this to bug fixes, and make sure (if you haven't already) to label the tests as to what bug they test.

For this version of the patch, it would be nice to have comments indicating which bug is fixed by what change as well.

casey’s picture

@mfer you should read the comments of the code and tests.

all inline css is merged into one tag
see test CascadingStylesheetsTestCase::testRenderInlineMediaPrint()

@import should proceed any other style
http://www.w3.org/TR/REC-CSS2/cascade.html#at-import. When a stylesheet is aggregated and non-resolved @import rules (like external stylesheets) should be moved to the top, else browser won't process them.

strengthened _drupal_build_css_path()
see #511998: CSS aggregator change url path in imported files, #265719: CSS aggregator produces invalid code and directory names for @import files Breaks IE, Internet explorer does not style page. and #258846: CSS aggregation fails to parse some url()'s

They are all bugs...

Status: Needs review » Needs work

The last submitted patch failed testing.

mfer’s picture

Status: Needs work » Needs review

Thanks for detailing out the issues with @import. That's the kind of information we need here.

The patch does a lot more than change how @import is handled. This is a mega patch addressing multiple issues. Keeping it that was isn't going to help get the patch committed. I've learned this the hard way. Each desecrate issue needs to be broken out separately. Even if it is easier for you to write it that way.

This patch changes APIs and we are past the API freeze. A whole new way to handle this that changes internal APIs will need to wait for D8. That's the point in the process we are at. If you want this in D7 i'd suggest changing this to multiple issues that address the individual bugs and do them one after another. Otherwise, this will become a D8 issue and the D8 maintainers can sort it out.

mfer’s picture

Status: Needs review » Needs work
casey’s picture

Status: Needs work » Needs review
StatusFileSize
new54.42 KB

Added comments to tests with links to the seperate issues.

And removed the 'aggregate', 'optimize' and 'flatten' options. Patch does not contain any new features any more.

casey’s picture

About API change
I did not remove any parameters from public functions, so usage stays the same. I did add some parameters for internal usage. Do I have to remove them? Would result in some duplicate code however.

Module sf_cache does something; it allows grouping.

CSS Aggregation is pluggable for Drupal 7; have a look at module css_preprocessor. When enabled, Core aggregator won't run anymore.

Status: Needs review » Needs work

The last submitted patch failed testing.

casey’s picture

Status: Needs work » Needs review
StatusFileSize
new52.23 KB
new18.62 KB

Besides it's so large because of the tests.

Status: Needs review » Needs work

The last submitted patch failed testing.

casey’s picture

Status: Needs work » Needs review

Hmm weird, it does pass locally.

casey’s picture

StatusFileSize
new52.25 KB

*Now* it should pass!

Status: Needs review » Needs work

The last submitted patch failed testing.

casey’s picture

Status: Needs work » Needs review
StatusFileSize
new52.37 KB

Not sure what is going wrong.

mfer’s picture

What version of PHP are you using? 5.2.x?

casey’s picture

5.3 local...

/edit ow wait I am testing on an external server. yes 5.2.9

Status: Needs review » Needs work

The last submitted patch failed testing.

casey’s picture

Status: Needs work » Needs review
StatusFileSize
new52.5 KB

I think I found it...

casey’s picture

StatusFileSize
new33.49 KB
new18.7 KB

Finally.
For easier reviewing I seperated the actual code changes and the new tests.

rfay’s picture

Status: Needs review » Needs work

I'm afraid that a large, disruptive patch like this won't fly. I skimmed it and came away with the impression that "here's a bunch of code that will fix what ails you". But no clear justification for the things you're doing. I'm sure you have a clear vision, but the community process means that you have to sell the rest of us on your vision.

Also, it's clear that you're changing APIs if you had to change color.module. That's clearly past the code freeze.

Here's what you need to do, IMO, to continue successfully with this:

1. Explain in this issue what problems you're trying to solve.
2. Explain in this issue exactly how you propose to solve them.
3. Explain in this issue how the tests that you've provided can give us adequate confidence that nothing else will break as a result.
4. Explain how we can demonstrate current system failures using the tests that you provide, and map them to open issues.

The most explanation I see is in #8... I think you need a treatise on what you want. You have a big job ahead.

You have to remember that we're at the very conservative *end* of the release cycle, and that CSS aggregation mostly works for most people and has for some time. So people are going to be very reluctant (rightly or wrongly) to take a risk on a huge new redesign. I wish you'd started this initiative 6 months ago - I'd be much more optimistic.

Basically, I agree with mfer. You won't get this whole thing into D7. And you should probably work on one piece at a time. I know it needs a redesign, and that that is probably the correct approach. But it's too late in the release cycle.

I also agree with mfer that your best chance of getting this into D8 is by building a very high quality CSS aggregator module, as you've started to do. If that is high quality and popular, it will both solve the failings of D7 (people can switch to your module when they hit new bugs) and it will also be a very good candidate for integration into D8.

Thanks for the good work on this, and I look forward to good long-term results. Sorry for the pessimism about the short term.

casey’s picture

You're most probably right. For now I'll try to use my in-depth experience :p on this subject to provide clear single line solutions in their own issues where possible.

Thanks for the help though!

mfer’s picture

@Casey, please realize we want to help you with this. We want the best system possible and are glad you've come along to try an help improve on that. Sometimes the way to get stuff in past the core committers isn't the way we like to work the best.

casey’s picture

@mfer ow I do. I even kinda knew this patch wasn't going to land. But I am sure this issue is proving there's lot to improve on the current CSS aggregator. And I am also happy with your help. This is just going to improve my community-driven development skills.

Status: Needs work » Needs review

teamfighter requested that failed test be re-tested.

casey’s picture

Version: 7.x-dev » 8.x-dev
catch’s picture

Missed this first time around, just found it via the css parsing issue.

xjm’s picture

Status: Needs review » Needs work

I think we need a new, more targeted patch for this issue.

wim leers’s picture

Status: Needs work » Closed (won't fix)

It's been pointed out by several people that this patch was unacceptable for several reasons. This issue has been silent for >3.5 years. None of the code applies anymore. Closing. If you still want to work on this, please open new, focused issues.

Thanks!