[haml] Sass: using if to set a variable default value

2011-01-27 Thread abierbaum
Is it possible to use an if conditional to set the default value for a
variable in SASS?

I want to do something like this but I can't figure out a way to get
it to work.  It looks like if's are only good for CSS blocks, not
variable assignment.

$base_bg_color:  rgba(238, 238, 238, 0);

@if (lightness($base_bg_color) > 50)
{ $base_text_color: black !defalut; }
@else
{ $base_text_color: white !default; }

Thanks,
Allen

-- 
You received this message because you are subscribed to the Google Groups 
"Haml" group.
To post to this group, send email to haml@googlegroups.com.
To unsubscribe from this group, send email to haml+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=en.



Re: [haml] Sass: using if to set a variable default value

2011-01-27 Thread Nathan Weizenbaum
Since variables are scoped to their current block, this won't work. In Sass
3.1 (current dev branch), you can do this, though:

$base-text-color: if(lightness($base_bg_color) > 50, black, white) !default;

On Thu, Jan 27, 2011 at 12:40 PM, abierbaum  wrote:

> Is it possible to use an if conditional to set the default value for a
> variable in SASS?
>
> I want to do something like this but I can't figure out a way to get
> it to work.  It looks like if's are only good for CSS blocks, not
> variable assignment.
>
> $base_bg_color:  rgba(238, 238, 238, 0);
>
> @if (lightness($base_bg_color) > 50)
> { $base_text_color: black !defalut; }
> @else
> { $base_text_color: white !default; }
>
> Thanks,
> Allen
>
> --
> You received this message because you are subscribed to the Google Groups
> "Haml" group.
> To post to this group, send email to haml@googlegroups.com.
> To unsubscribe from this group, send email to
> haml+unsubscr...@googlegroups.com .
> For more options, visit this group at
> http://groups.google.com/group/haml?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Haml" group.
To post to this group, send email to haml@googlegroups.com.
To unsubscribe from this group, send email to haml+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=en.



Re: [haml] Sass: using if to set a variable default value

2011-01-27 Thread Chris Eppstein
Hmm. The presence of !default makes this hard to do like you'd expect.

In sass 3.1 there's a new function called if() that you can use like so:

$base_text_color: if(lightness($base_bg_color) > 50, black, white) !defalut;

if you can't/won't upgrade to the alpha version this is a (non-elegant) work
around:

$base_text_color: false !default;

@if not $base_text_color {
  @if (lightness($base_bg_color) > 50)
  { $base_text_color: black; }
  @else
  { $base_text_color: white; }
}

Chris

On Thu, Jan 27, 2011 at 12:40 PM, abierbaum  wrote:

> Is it possible to use an if conditional to set the default value for a
> variable in SASS?
>
> I want to do something like this but I can't figure out a way to get
> it to work.  It looks like if's are only good for CSS blocks, not
> variable assignment.
>
> $base_bg_color:  rgba(238, 238, 238, 0);
>
> @if (lightness($base_bg_color) > 50)
> { $base_text_color: black !defalut; }
> @else
> { $base_text_color: white !default; }
>
> Thanks,
> Allen
>
> --
> You received this message because you are subscribed to the Google Groups
> "Haml" group.
> To post to this group, send email to haml@googlegroups.com.
> To unsubscribe from this group, send email to
> haml+unsubscr...@googlegroups.com .
> For more options, visit this group at
> http://groups.google.com/group/haml?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Haml" group.
To post to this group, send email to haml@googlegroups.com.
To unsubscribe from this group, send email to haml+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=en.