PDA

View Full Version : Quick SASS question re: mixin arguments



user56279
28 Feb 2011, 11:32 AM
I didn't see this addressed in any SASS documentation, so I'll try here.

If you have multiple arguments, is there a way to pass only an argument later than the first without passing the first?

In javascript you could use empty quotes to indicate that you want to skip that argument, but that doesn't appear to work with SASS. e.g., myFunction('','',500);

What do you do in SASS to indicate empty arguments?

Thanks.

user56279
28 Feb 2011, 2:11 PM
Can't be done...yet.

"In Sass 3, there's no way to use the default values for the first arguments to a mixin and a non-default value for later arguments. Sass 3.1, currently in development, supports passing arguments by name, but in 3.0 the best way to do this is just to manually pass in the default values."

- Nathan Weizenbaum

TommyMaintz
28 Feb 2011, 4:49 PM
If you do the following:

sudo gem install sass --pre
sudo gem install compass --pre
sudo gem install haml --pre

You can actually do named arguments. We have started to use this a little inside the Ext 4 theme. This is one of the reasons you need the bleeding edge versions of all the gems to be able to compile to Ext 4 theme. You can use named arguments like this:

@include x-frame($border-radius: 10px, $background-gradient: 'matte');

For the rest it would use all the default values.

user56279
1 Mar 2011, 7:21 AM
Nice.

Thanks for the info, Tommy.

I've only been exploring SASS for a couple days now. It's funny that it doesn't naturally support the very first thing I wanted it to do. It seemed like an obvious thing to do when you have the option to specify default values. It kind of defeats the purpose of using arguments if you need to pass back the default values to get at an argument later in the list.