Created
June 4, 2013 09:15
-
-
Save lunelson/5704708 to your computer and use it in GitHub Desktop.
Contains and Contains-Any
This file contains 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
// --- | |
// Sass (v3.2.9) | |
// --- | |
// testing containment of any of multiple keys in a complex list | |
@function contains-any($list, $keys...) { | |
$result: false; | |
@each $key in $keys { | |
@each $item in $list { | |
@if length($item) > 1 { | |
$result: $result or contains-any($item, $keys...); | |
} @else if index($item, $key) { | |
$result: true; | |
} | |
} | |
} | |
@return $result; | |
} | |
$testlist: body 5, heading (blue red, green yellow); | |
.test { | |
contains: contains-any($testlist, green); | |
contains2: contains-any(red blue yellow, green); | |
} |
This file contains 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
.test { | |
contains: true; | |
contains2: false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment