documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.com/jammit/
MIT License
1.16k stars 197 forks source link

Routes fail for assets with dots in their filename #98

Closed audionerd closed 13 years ago

audionerd commented 13 years ago

I'd like to generate assets with filenames like:

namespace.module.js

But Jammit routes that request as:

{
  :extension => "module.js", 
  :package => "namespace"
}

... instead of

{
  :extension => "js", 
  :package => "namespace.module"
}

I was able to work around the issue by editing the route, adding this:

:package => /.+/

... and requests to "namespace.module.js" were fulfulled.

jashkenas commented 13 years ago

I'm a little bit fuzzy on the change here. Can you cook up a patch for this? Will it work in both Rails 2.3.x and Rails 3?

audionerd commented 13 years ago

Turns out my regex was pretty naive. It breaks *.html.mustache routes!

I tried a few more regex patterns, but couldn't find anything that worked for both test.html.mustache and namespace.module.js.

Here's a patch (not a fix) that simply adds a test to illustrate the problem:

https://gist.github.com/758229

I think the solution is probably not in routing, but in processing later, probably in Jammit::Controller#parse_request.

Taking a break now, but that's what I have so far.

jashkenas commented 13 years ago

Ok -- I'm going to leave this one as it is for the time being ... considering that *.html.mustache-style routes are by far the most common. If you come up with a fix that works both ways, let me know.

I think it's impossible to tell, by definition -- how many of the dotted parts should be considered "extension", and how many should be considered to be "filename".

audionerd commented 13 years ago

I wrote a very simple before filter around Jammit::Controller#parse_request

Here's an example for a filename called 'namespace.module.js': https://gist.github.com/803580

This allows me to specifically override Jammit routes by name, when needed.

It might be useful for Jammit to have a real before filter, or some way to specify route overrides case-by-case in assets.yml. But this little hack was enough for my project :)