Created
April 3, 2014 03:23
-
-
Save morewry/9947773 to your computer and use it in GitHub Desktop.
Something I wish I could do in Sass
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
// --------------------------------------- | |
/* | |
## Set / Get | |
http://cdpn.io/hgLal | |
*/ | |
// --------------------------------------- | |
$-fw-debug: false; | |
$-fw-default-inclusion: extend; | |
$-fw-mixins: ( init: true ); | |
@mixin -fw-set ( $name, $debug: $-fw-debug ) { | |
@if not map-has-key( $-fw-mixins, $name ) { | |
// create placeholder | |
%#{$name} { | |
@content; | |
} | |
// create class of same name if debugging | |
@if $debug { | |
.#{$name} { @extend %#{$name}; } | |
} | |
// create mixin - still no way to do this | |
// @mixin #{$name} { | |
// @content; | |
// } | |
$-fw-mixins: map-merge($-fw-mixins, ($name: true)); | |
} | |
} // -fw-set | |
@mixin -fw-get ( $name, $method: $-fw-default-inclusion ) { | |
@if map-has-key( $-fw-mixins, $name ) { | |
// add styles as extend | |
@if $method == extend { | |
@extend %#{$name}; | |
} | |
// add styles as include - still no way to do this | |
// @else { | |
// @include $name; | |
// } | |
} | |
} // -fw-get | |
@include -fw-set(test, true) { | |
margin-bottom: 10px; | |
padding: 10px; | |
color: red; | |
background: pink; | |
} | |
.extend { @include -fw-get(test, extend); } | |
.include { @include -fw-get(test, include); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment