Created
May 22, 2014 20:13
-
-
Save griiettner/153c6f878bb3566e0dca to your computer and use it in GitHub Desktop.
Complex mixin to turn variables part of another variable name
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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