Created
August 7, 2015 19:49
-
-
Save scheibome/1f8eb8c8636c5d48a2c8 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
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
// ---- | |
// libsass (v3.2.5) | |
// ---- | |
$elementSeparator: '__'; | |
$modifierSeparator: '--'; | |
@function containsModifier($selector) { | |
$selector: selectorToString($selector); | |
@if str-index($selector, $modifierSeparator) { | |
@return true; | |
} @else { | |
@return false; | |
} | |
} | |
@function selectorToString($selector) { | |
$selector: inspect($selector); //cast to string | |
$selector: str-slice($selector, 2, -2); //remove brackets | |
@return $selector; | |
} | |
@function getBlock($selector) { | |
$selector: selectorToString($selector); | |
$modifierStart: str-index($selector, $modifierSeparator) - 1; | |
@return str-slice($selector, 0, $modifierStart); | |
} | |
@mixin b($block) { | |
.#{$block} { | |
@content; | |
} | |
} | |
@mixin e($element) { | |
$selector: &; | |
@if containsModifier($selector) { | |
$block: getBlock($selector); | |
@at-root { | |
#{$selector} { | |
#{$block+$elementSeparator+$element} { | |
@content; | |
} | |
} | |
} | |
} @else { | |
@at-root { | |
#{$selector+$elementSeparator+$element} { | |
@content; | |
} | |
} | |
} | |
} | |
@mixin m($modifier) { | |
@at-root { | |
#{&}#{$modifierSeparator+$modifier} { | |
@content; | |
} | |
} | |
} | |
@include b(test) { | |
background: red; | |
@include e(element){ | |
font-size: 14px; | |
@include m(big) { | |
font-size: 18px; | |
} | |
}; | |
@include m(modifier) { | |
color: blue; | |
@include e(subelement) { | |
background: gray; | |
} | |
} | |
} |
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
.test { | |
background: red; | |
} | |
.test .test__element { | |
font-size: 14px; | |
} | |
.test .test__element .test .test__element--big { | |
font-size: 18px; | |
} | |
.test .test--modifier { | |
color: blue; | |
} | |
.test .test--modifier .test .test--modifier test .test__subelement { | |
background: gray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment