documentcloud / jammit

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

Embedded assets and existing conditional comments #39

Closed caged closed 14 years ago

caged commented 14 years ago

We're looking into the possibility of using Jammit on Tender and Lighthouse and I've run into an issue with embedded assets and conditional comments.

We already have some Internet Explorer specific stylesheets, so this means we'll have markup like this:

This works fine until you turn on embedded assets. You end up with nested conditional comments and the IE mhtml stylesheets are included in other browsers such as Safari and Firefox. Below is what we end up with.

    <!--[if (!IE)|(gte IE 8)]><!-->
<link href="/pkg/frontend-datauri.css?1270158082" media="screen" rel="stylesheet" type="text/css" />
<!--<![endif]-->
<!--[if lte IE 7]>
<link href="/pkg/frontend-mhtml.css" media="screen" rel="stylesheet" type="text/css" />
<![endif]-->
<!--[if (!IE)|(gte IE 8)]><!-->
<link href="/pkg/safari-datauri.css?1270158084" media="screen" rel="stylesheet" type="text/css" />
<!--<![endif]-->
<!--[if lte IE 7]>
<link href="/pkg/safari-mhtml.css" media="screen" rel="stylesheet" type="text/css" />
<![endif]-->
<!--[if IE 6]>
<!--[if (!IE)|(gte IE 8)]><!-->
<link href="/pkg/ie6-datauri.css?1270158080" media="screen" rel="stylesheet" type="text/css" />
<!--<![endif]-->
<!--[if lte IE 7]>
<link href="/pkg/ie6-mhtml.css" media="screen" rel="stylesheet" type="text/css" />
<![endif]-->
<![endif]-->
<!--[if IE 7]>
<!--[if (!IE)|(gte IE 8)]><!-->
<link href="/pkg/ie7-datauri.css?1270158083" media="screen" rel="stylesheet" type="text/css" />
<!--<![endif]-->
<!--[if lte IE 7]>
<link href="/pkg/ie7-mhtml.css" media="screen" rel="stylesheet" type="text/css" />
<![endif]-->
<![endif]-->

Are there workarounds for this or perhaps I'm doing something wrong?

jashkenas commented 14 years ago

Ah yes, the nested conditionals. This needs to be documented better because it's come up a couple of times before (Issue #24 and #10, for reference). I'll put that on the todo-list.

The gist of it is that you can disable asset embedding on a per-package basis, as you'd want to do for browser-specific overrides. So change your snippet to:

<!--[if IE 6]>
  <%= include_stylesheets :ie6, :embed_assets => false %>
<![endif]-->

And you're off to the races. Let me know if that doesn't work for you.