Skip to content

Instantly share code, notes, and snippets.

@pixelass
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pixelass/8835048 to your computer and use it in GitHub Desktop.
Save pixelass/8835048 to your computer and use it in GitHub Desktop.
compare to lists to find matches
@import 'for';
// compare two lists
// the wild animals will show a picture and a warning "This animal is wild"
// others do not
@wild: bear, tiger, elefant, lion, zebra, crocodile, gorilla;
@animals: gorilla, dog, cat, hamster, tiger;
.in(@array, @value) {
.for(@array); .-each(...) {}
.-each(~'@{value}') {@-: true}
.-() {@-: false} .-;
}
.wild(@bool) when (@bool) {
&:before {
content: url('../images/@{i}.png');
}
&:after {
content: 'This animal is wild.'
}
}
.animal {
.for(@animals);.-each(@i){
.in(@wild, @i);
&.@{i} {
.wild(@-);
}
}
}
// output
//.animal.gorilla:before {
// content: url('../images/gorilla.png');
//}
//.animal.gorilla:after {
// content: 'This animal is wild.';
//}
//.animal.tiger:before {
// content: url('../images/tiger.png');
//}
//.animal.tiger:after {
// content: 'This animal is wild.';
//}
// example: http://codepen.io/pixelass/pen/Ggkwy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment