rails/sass-rails — Issue #94: let an imported partial with .erb extension be processed by sprockets
Author: jfirebaugh
Created: 2012-02-16 19:55:55+00:00
State: open

I have a white-labeled service where customers can select a color scheme to match their branding. I'm using locales to hold the color information, and I want to use the colors in my stylesheets. (It's very similar to [this SO question](http://stackoverflow.com/questions/4622115/using-sass-with-user-specified-colors).) I'll use a custom `assets:precompile` task to statically compile the stylesheet assets for each locale. With that in mind, I'd like to do something like this:

In application.css.scss:

```scss
@import "colors";
#header { background-color: $header-color; }
```

In _colors.scss.erb:

```erb
$header-color: <%= I18n.t('header_color') %>;
```

But this doesn't work.

First off, `Sass::Rails::Importer` assumes that a file that has `.scss` [_anywhere_ in the name](https://github.com/rails/sass-rails/blob/922b199acd8284239e2b42555efdc868b47d8e8f/lib/sass/rails/importer.rb#L24) is an SCSS file (even if it's not the ending extension), so my `_colors.scss.erb` doesn't get processed by Sprockets at all.

Even if this bug were fixed, and `_colors.scss.erb` was sent through [@resolver.process](https://github.com/rails/sass-rails/blob/922b199acd8284239e2b42555efdc868b47d8e8f/lib/sass/rails/importer.rb#L52) instead, the result is not what I want, because it's been run through both ERB and SCSS processing. Since the file is just a set of SCSS variable declarations, the result is empty. What I really want is for _just_ ERB processing to take place, and then the result of that imported.

I've found a workaround -- name the file `_colors.css.erb`, but it would be awesome if this would just work.