Last active
September 26, 2015 19:42
-
-
Save roytomeij/ebd7af1dc1967d992dab to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
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
// ---- | |
// libsass (v3.2.5) | |
// ---- | |
// LIBRARY: | |
$theme-properties: (); | |
@mixin theme-prop($property, $var) { | |
$selector: &; | |
@if map-has-key($theme-properties, $var) { | |
$new: join(map-get($theme-properties, $var), ($selector: $property), comma); | |
$theme-properties: map-merge($theme-properties, ($var: $new)) !global; | |
} @else { | |
$theme-properties: map-merge($theme-properties, ($var: ($selector: $property))) !global; | |
} | |
#{$property}: map-get($theme-variables, $var); | |
} | |
@mixin theme-variables($sections) { | |
@each $section, $overrides in $sections { | |
body.#{$section} { | |
@each $var, $override in $overrides { | |
@if (map-has-key($theme-properties, $var)) { | |
@each $selector in map-get($theme-properties, $var) { | |
$item: nth($selector, 1); | |
#{nth($item, 1)} { | |
#{nth($item, 2)}: $override; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
// DEVELOPER FACING: | |
// Set default variables ("main" theme): | |
$theme-variables: ( | |
'main-color': orange | |
); | |
// Write regular CSS | |
// When a themeable variable is used, include `theme-prop($property, $var)` | |
.mod-something { | |
header { | |
font-family: sans-serif; | |
color: #fff; | |
@include theme-prop(background, 'main-color'); | |
} | |
h1 { | |
font-size: 1.6rem; | |
@include theme-prop(color, 'main-color'); | |
} | |
} | |
// This mixin output overrides based on theme values in this list, | |
// expects .section class name on <body> (eg. <body class="quote">) | |
@include theme-variables(( | |
'quote': ( | |
'main-color': teal | |
), | |
'about': ( | |
'main-color': 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
.mod-something header { | |
font-family: sans-serif; | |
color: #fff; | |
background: orange; | |
} | |
.mod-something h1 { | |
font-size: 1.6rem; | |
color: orange; | |
} | |
body.quote .mod-something header { | |
background: teal; | |
} | |
body.quote .mod-something h1 { | |
color: teal; | |
} | |
body.about .mod-something header { | |
background: green; | |
} | |
body.about .mod-something h1 { | |
color: green; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment