Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing mixins between scss files in rails 3.1

I'm trying to refer to a mixin defined in one file (application.css.scss) in another (home.css.scss). I have tried importing application into home but still get an "Undefined mixin" error.

Is there a way to automatically import all of my files, or what is the best way to manage imports between files?

like image 683
parker Avatar asked Sep 10 '11 20:09

parker


1 Answers

I haven't been able to make the jump to 3.1 yet, but using Compass & Sass for quite a while, I've found it's best to try to manage mixin/definition sass separately from your actual CSS generating sass. In this way, the mixin files can be treated freely like code libraries, included wherever necessary, without them repeatedly generating CSS rules.

So you might have:

/* my-mixin-concern.scss */
$default_foo: 123px !default;

@mixin some-concern($foo: $default_foo) {
  // do something
}

/* application.scss */
$default_foo: 321px; // optionally, pre-set the default value before import.
@import 'my-mixin-concern';  
p { @include some-concern; }

/* home.scss */
@import 'my-mixin-concern';
body.home p { @include some-concern(9000px); }

In this way you are explicitly importing all requirements for each scss file, similarly to how you would do so in a code library.

like image 174
numbers1311407 Avatar answered Nov 09 '22 00:11

numbers1311407