Created
May 24, 2012 11:00
-
-
Save StanAngeloff/2780831 to your computer and use it in GitHub Desktop.
Sass/Compass theming
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
$theme: | |
page #fff | |
navigation ( | |
background #f4f4f4 | |
text #595959 | |
) | |
; | |
$levels: | |
darkest -75% | |
darker -50% | |
dark -25% | |
darkish -10% | |
original 0% | |
lightish 10% | |
light 25% | |
lighter 50% | |
lightest 75% | |
; |
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
// Get a single value from a list of `(key value)` pairs. | |
@function value-from-list($key, $list) { | |
$lookup: $key; | |
$target: $list; | |
@if (type-of($lookup) == 'string') { | |
$lookup: -compass-list($lookup); | |
} | |
@for $i from 1 through length($lookup) { | |
$found: '__false'; | |
@for $j from 1 through length($target) / 2 { | |
@if (nth($target, ($j * 2) - 1) == nth($lookup, $i)) { | |
$found: nth($target, ($j * 2)); | |
} | |
} | |
@if ($found == '__false') { | |
@warn "The list (#{$list}) does not contain a value for key '#{$key}'."; | |
@return false; | |
} | |
$target: $found; | |
} | |
@return $target; | |
} | |
// Get the colour for a given theme component, e.g., 'page'. | |
@function theme($component, $level: original) { | |
$colour: value-from-list($component, $theme); | |
$brightness: value-from-list($level, $levels); | |
@if ($brightness < 0%) { | |
@return darken($colour, abs($brightness)); | |
} | |
@if ($brightness > 0%) { | |
@return lighten($colour, $brightness); | |
} | |
@return $colour; | |
} |
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
@import 'constants'; | |
@import 'functions'; | |
body { | |
background-color: theme(page); | |
} | |
#navigation { | |
background-color: theme(navigation background); | |
a { | |
color: theme(navigation text); | |
&:hover { | |
color: theme(navigation text, darker); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment