Skip to content

Instantly share code, notes, and snippets.

@roytomeij
Last active September 26, 2015 19:42
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 roytomeij/ebd7af1dc1967d992dab to your computer and use it in GitHub Desktop.
Save roytomeij/ebd7af1dc1967d992dab to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// 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
)
));
.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