Created
May 27, 2013 19:59
-
-
Save chriseppstein/5658817 to your computer and use it in GitHub Desktop.
Sass function that returns a unique value each time it is called within the scope of a single css file compilation.
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
module Sass::Script::Functions | |
def unique | |
options[:unique_values] ||= Set.new | |
r = rand(100000) | |
r = rand(100000) while options[:unique_values].include?(r) | |
options[:unique_values] << r | |
Sass::Script::String.new("u#{r.to_s(36)}") #we add a u to the font to ensure this is a legal css identifier. | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is useful for doing things like generating placeholder classes that are unique within a single mixin include.