Currently, I'm utilizing Express for Node.js and Stylus as the CSS engine. While Stylus is great, I'm facing some challenges in passing color variables or generating random colors. Despite attempting to use the javascript API for stylus, I find myself confused and perhaps complicating things unnecessarily.
var stylus = require('stylus');
app.use(stylus.middleware({
src: __dirname + '/public',
compile: function (str, path) {
var mylib = function(style) {
style.define('randomColor', function () {
return '#5f5'; // using a temporary color just to test functionality.
});
};
return stylus(str).use(mylib);
}
}));
In my stylus sheet, I have:
mainColor = randomColor()
Unfortunately, this results in the following error message:
RGB or HSL value expected, got a string #5f5
I am struggling to pass a color variable correctly from JavaScript to the Stylus sheet.
Edit:
Find my app.js file here: https://gist.github.com/4345823
And my Stylus file here: https://gist.github.com/4345839