Skip to content

Instantly share code, notes, and snippets.

@coltpini
Last active August 29, 2015 14:12
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 coltpini/b59b3064d6ecde760c6a to your computer and use it in GitHub Desktop.
Save coltpini/b59b3064d6ecde760c6a to your computer and use it in GitHub Desktop.
ascii problem, icon generation
//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