I have list of variables with appended values and corresponding list of classes with same name as variables, like so:
$cold-world: Verdana, sans-serif;
$cream: Verdana, sans-serif;
$fish: Verdana, sans-serif;
$knowledge-god: Verdana, sans-serif;
$run: test, test, Verdana, sans-serif;
$winter-warz: Verdana, sans-serif;
$font-list: $cold-world, $cream, $fish, $knowledge-god, $run, $winter-warz;
$pages: "cold-world", "cream", "fish", "knowledge-god", "run", "winter-warz";
Since both lists are the same I was trying to keep thing DRY and created function that prefixes each class in $pages
list with $
symbol. Then I used @each
loop to create $font-list
$font-list: (); // initilaze empty list
@function variable($x) {
@return unquote("$" + $x);
}
@each $page in $pages {
$font-list: append($font-list, variable($page), comma);
}
Problem is when I try to use generated list in output loop. I'm getting variable name instead of value
@mixin font($font-stack, $stack: 1) {
font-family: nth($font-stack, $stack);
}
@each $page in $pages {
.#{$page} {
@include font(nth($font-list, index($pages, $page)), 1);
//@include font(variable($page), 1); // same result as above
}
}
I also tried generate variable list from class list using str-slice
option (available in SASS 3.3.0) also to no avil. It outputs variable value in place of class name.
$font-list: $cold-world, $cream, $fish, $knowledge-god, $run, $winter-warz;
$pages: ();
@function slice($x) {
@return str-slice(#{$x},1,100);
}
@each $variable in $font-list {
$pages: append($pages, slice($variable), comma);
}