Skip to content

Instantly share code, notes, and snippets.

@griiettner
Created May 22, 2014 20:13
Show Gist options
  • Save griiettner/153c6f878bb3566e0dca to your computer and use it in GitHub Desktop.
Save griiettner/153c6f878bb3566e0dca to your computer and use it in GitHub Desktop.
Complex mixin to turn variables part of another variable name
// Code from Seven Phase Max
// ............................................................
// .for
.for(@i, @n) {.-each(@i)}
.for(@n) when (isnumber(@n)) {.for(1, @n)}
.for(@i, @n) when not (@i = @n) {
.for((@i + (@n - @i) / abs(@n - @i)), @n);
}
// ............................................................
// .for-each
.for(@array) when (default()) {.for-impl_(length(@array))}
.for-impl_(@i) when (@i > 1) {.for-impl_((@i - 1))}
.for-impl_(@i) {.-each(extract(@array, @i))}
// Brands
@dodge : "dodge";
@ford : "ford";
@chev : "chev";
// Colors
@dodge-color : "#fff";
@ford-color : "#000";
@chev-color : "#ff0";
// Setting variables and escaping than
@brands: ~"dodge" ~"ford" ~"chev";
// Define our variable
.define(@var) {
@brand-color: '@{var}-color';
}
// Starting the mixin
.color() {
// Generating the loop to each brand
.for(@brands); .-each(@name) {
// After loop happens, it checks what brand is being called
.define(@name);
// When the brand is found, match the selector and color
.brand-@{name} & {
color: @@brand-color;
}
}
}
.carColor {
.color();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment