Skip to content

Instantly share code, notes, and snippets.

@chriseppstein
Created May 27, 2013 19:59
Show Gist options
  • Save chriseppstein/5658817 to your computer and use it in GitHub Desktop.
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.
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
@chriseppstein
Copy link
Author

This is useful for doing things like generating placeholder classes that are unique within a single mixin include.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment