CodeSleeve / asset-pipeline

This Laravel 4 package provides a very simple and easy to use asset pipeline. It was heavily inspired by the Rails asset pipeline. We make use of the wonderful Assetic package to help with pre-compliation!
http://www.codesleeve.com
MIT License
489 stars 53 forks source link

[Proposal] File extension mapper class #154

Open kdocki opened 10 years ago

kdocki commented 10 years ago

The responsibility for this decorator would be to keep up with file naming conventions. The assets:generate depends on this proposal.

http://localhost:8000/assets/foobar.scss

then the controller is going to handle sending the request header of text/css for us. This is fine.

However the issue here is that if we generate an asset in public/assets/foobar.sass then what is the header? After testing, I found we get

Content-Type:application/octet-stream

This is not going to work. So we are forced to rename the sass to a .css extension. I have a strong hunch that this is why rails does foobar.css.sass so they can strip off extension.

So, I am keeping up with the mime types so I could just strip off base extension 'foobar.sassorfoobar.css.sasswould be come justfoobar`.

But then what if I have foobar.css and foobar.less

Out of the box the user would never see foobar.less, because the 'css' filter is listed before less filter. But if I wrote these files out to a public/ directory now the user will see the content of the less file in public/assets/foobar.css which is very confusing.

I cannot think of any reason why we would ever have the same filename with different extensions though, as this is just asking for headaches. So I am going to ignore this and just go ahead with the file extension mapper.

Scenario: Given a request comes through the controller for,

http://localhost:8000/assets/foobar.css

And there is no public/assets/foobar.css then we will serve And there is a /app/assets/stylesheets/foobar.less Then we will serve that file.

Scenario: When a request comes through the controller for,

http://localhost:8000/assets/foobar.less

Then we will serve a 404.

Before we pass files to the javascript_include_tag and stylesheet_link_tag decorators, I think it would be best to run those through the File extension mapper class.

<?= stylesheet_link_tag() ?> will not get /assets/application.less but rather /assets/application.css.

Having this file extension mapper class will also allow for us to later bring in cache busting in the filenames as well. Then if we have file names and client busting cache, we might get rid of the client cache filter.