Skip to content

Instantly share code, notes, and snippets.

@mpalpha
Created June 25, 2015 22:11
Show Gist options
  • Save mpalpha/7845f33b1b47f994720e to your computer and use it in GitHub Desktop.
Save mpalpha/7845f33b1b47f994720e to your computer and use it in GitHub Desktop.
icon-generation sass to scss from https://gist.github.com/coltpini/b59b3064d6ecde760c6a
//Function that converts a base10 number to base16 number.
//This is needed to convert an index from a list to the appropriate hex value for unicode values.
@function decToHex($dec, $length) {
$hexVals: "A", "B", "C", "D", "E", "F";
$base: 16;
$q: $dec;
$result: "";
@while $q != 0 {
$mod: $q % $base;
$q: floor($q / $base);
@if $mod > 9 {
$mod: nth($hexVals, $mod - 9);
}
$result: $mod + $result;
}
@while str-length($result) < $length {
$result: 0 + $result;
}
@return $result;
}
//Hack -- this will allow the output to have "\e900", without this hack Sass compiles the \e9 first to an "é" so I couldn't get a "\e9" + "02" to work.
// Lots of thanks to "larsbo" for this function!
@function unicode($str) {
@return unquote('"') + $str + unquote('"');
}
//List of icons, these will be the classes
$utility: menu settings account secure home language info help warning refresh edit delete leave camera camera-active show history;
// This will spit out all of the ".icon-xxx" rules so I don't have to maintain a bunch of them.
@for $i from 1 through length($utility) {
$item: nth($utility, $i);
$unicode: \e9 + decToHex($i - 1, 2);
.icon-#{$item}:before {
content: unicode($unicode);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment