I needed to generate HTML elements which had random background colors with Sass. Unfortunately, it’s absolutely impossible.
So, I decided to add a custom ruby method to the Sass::Script::Functions module. It’s incredibly elementary but maybe it’ll help someone :)
So, here is the code. You can put it in your config.rb for example.
module Sass::Script::Functions
def getRandomColor()
Sass::Script::String.new("#%06x" % (rand * 0xffffff))
end
end
Usage
@for $i from 1 through $len {
.item-#{$i} {
background:getRandomColor();
}
}