Setting variable defaults #1109

Closed
guybedford opened this Issue Jan 8, 2013 · 4 comments

Comments

Projects
None yet
2 participants
@guybedford
Contributor

guybedford commented Jan 8, 2013

The only previous references to this I can find is from #313.

I'm currently working on variable prepopulation as part of require-less. For example, to load an existing less stylesheet with some specific variables already set. By using variable CSS selector names and allowing the variables to be set as part of the loading, one can use the variables to allow the entire less file to act as a modular unit itself, just as a mixin is a modular unit.

In the process, it would be useful if one could define defaults for global variables in a less file, in case any expected variables are missed.

Is there something like this already?

Also, unlike in #313, it would be nice to assign the default to the variable itself so that this doesn't need to applied with each instance of use as given in the initial solution here.

I've considered some syntax examples here:

Using an operator:

  @mycolor: @mycolor || red;

Or using the guard expression system:

  @mycolor: red when not (@mycolor);

Or using a function:

  @mycolor: default(@mycolor, red);

Happy to discuss further.

@lukeapage

This comment has been minimized.

Show comment
Hide comment
@lukeapage

lukeapage Jan 8, 2013

Member

Did you see #1104 ?

Member

lukeapage commented Jan 8, 2013

Did you see #1104 ?

@guybedford

This comment has been minimized.

Show comment
Hide comment
@guybedford

guybedford Jan 9, 2013

Contributor

No I didn't - this would sort it out perfectly.

Contributor

guybedford commented Jan 9, 2013

No I didn't - this would sort it out perfectly.

@guybedford guybedford closed this Jan 9, 2013

@lukeapage

This comment has been minimized.

Show comment
Hide comment
@lukeapage

lukeapage Jan 9, 2013

Member

well that is closed.. but if you look in the comments you'll see why it is closed and why...

Member

lukeapage commented Jan 9, 2013

well that is closed.. but if you look in the comments you'll see why it is closed and why...

@guybedford

This comment has been minimized.

Show comment
Hide comment
@guybedford

guybedford Jan 9, 2013

Contributor

Thanks for following up. Ah, I think I get it - so one can define the variable again after the import and have the last defined value be the one used kind of like hoisting in JavaScript? That works just as well then if so. I've also tried to use mixins more for this sort of thing as well now anyway.

Contributor

guybedford commented Jan 9, 2013

Thanks for following up. Ah, I think I get it - so one can define the variable again after the import and have the last defined value be the one used kind of like hoisting in JavaScript? That works just as well then if so. I've also tried to use mixins more for this sort of thing as well now anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment