Skip to content

Instantly share code, notes, and snippets.

@pizzapanther
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save pizzapanther/66efc58684ad5017c5af to your computer and use it in GitHub Desktop.

Select an option

Save pizzapanther/66efc58684ad5017c5af to your computer and use it in GitHub Desktop.
Less for each loop for theme building
// .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))}
// ............................................................
.theme(textmate) {
@bg: #dcdcdc;
@fg: #333;
}
.theme(terminal) {
@bg: #000;
@fg: #fff;
}
@themes: 'textmate', 'terminal';
body {
.for(@themes); .-each(@color) {
@name: e(@color);
&.@{name} {
.theme(@name);
color: @fg;
background-color: @bg;
}
}
}
/* Output
body.textmate {
color: #333333;
background-color: #dcdcdc;
}
body.terminal {
color: #ffffff;
background-color: #000000;
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment