lib/css/stylus.js
function (src, dst, config, headers, callback) {

        if (_.isFunction(headers)) {
            callback = headers;
            headers = undefined;
        }

        var options = config.options;

        if (!fsys.isFileSync(src)) {
            return callback(new Error('source file not found. path:', src));
        }

        _.defaults(options || (options = {}), DEFAULT_OPTIONS);
        var encode = options.encode;
        var compress = options.compress;
        var firebug = options.firebug;
        var linenos = options.linenos;
        var urlopt = options.url;


        var raw = fs.readFileSync(src, encode);

        var styl = stylus(raw)
                .set('filename', dst)
                .set('compress', compress)
                .set('firebug', firebug)
                .set('linenos', linenos)
                .define('b64', stylus.url(urlopt))
        ;

        if (options.nib) { // use nib library
            styl.use(nib());
        }

        // extend options
        if (config.hasOwnProperty('extend') && headers && common.isUAOverride(config, headers) && config.extend.hasOwnProperty('content')) {
            options = obj.copy(config.extend.content, config).options;
            logger.debug('Override stylus options:', options);
        }

        // define functions and constant values
        if (options.fn && Object.keys(options.fn).length) {
            styl.use(function (styl) {
                _.each(options.fn, function (fn, name) {
                    if (_.isFunction(fn)) {
                        styl.define(name, function (data) {
                            return fn(data && data.val);
                        });
                    } else {
                        styl.define(name, function () {
                            return fn;
                        });
                    }
                });
            });
        }

        styl.render(function (err, css) {
            err && callback(err, css);

            fs.writeFileSync(dst, css, encode);
            callback(null, css);
        });
    }
function (src, dst, config, headers, callback) {

        if (_.isFunction(headers)) {
            callback = headers;
            headers = undefined;
        }

        var options = config.options;

        if (!fsys.isFileSync(src)) {
            return callback(new Error('source file not found. path:', src));
        }

        _.defaults(options || (options = {}), DEFAULT_OPTIONS);
        var encode = options.encode;
        var compress = options.compress;
        var firebug = options.firebug;
        var linenos = options.linenos;
        var urlopt = options.url;


        var raw = fs.readFileSync(src, encode);

        var styl = stylus(raw)
                .set('filename', dst)
                .set('compress', compress)
                .set('firebug', firebug)
                .set('linenos', linenos)
                .define('b64', stylus.url(urlopt))
        ;

        if (options.nib) { // use nib library
            styl.use(nib());
        }

        // extend options
        if (config.hasOwnProperty('extend') && headers && common.isUAOverride(config, headers) && config.extend.hasOwnProperty('content')) {
            options = obj.copy(config.extend.content, config).options;
            logger.debug('Override stylus options:', options);
        }

        // define functions and constant values
        if (options.fn && Object.keys(options.fn).length) {
            styl.use(function (styl) {
                _.each(options.fn, function (fn, name) {
                    if (_.isFunction(fn)) {
                        styl.define(name, function (data) {
                            return fn(data && data.val);
                        });
                    } else {
                        styl.define(name, function () {
                            return fn;
                        });
                    }
                });
            });
        }

        styl.render(function (err, css) {
            err && callback(err, css);

            fs.writeFileSync(dst, css, encode);
            callback(null, css);
        });
    }
function ( src , dst , config , headers , callback ) { if ( _ . isFunction ( headers ) ) { callback = headers ; headers = undefined ; } var options = config . options ; if ( ! fsys . isFileSync ( src ) ) { return callback ( new Error ( 'source file not found. path:' , src ) ) ; } _ . defaults ( options || ( options = { } ) , DEFAULT_OPTIONS ) ; var encode = options . encode ; var compress = options . compress ; var firebug = options . firebug ; var linenos = options . linenos ; var urlopt = options . url ; var raw = fs . readFileSync ( src , encode ) ; var styl = stylus ( raw ) . set ( 'filename' , dst ) . set ( 'compress' , compress ) . set ( 'firebug' , firebug ) . set ( 'linenos' , linenos ) . define ( 'b64' , stylus . url ( urlopt ) ) ; if ( options . nib ) { // use nib library styl . use ( nib ( ) ) ; } // extend options if ( config . hasOwnProperty ( 'extend' ) && headers && common . isUAOverride ( config , headers ) && config . extend . hasOwnProperty ( 'content' ) ) { options = obj . copy ( config . extend . content , config ) . options ; logger . debug ( 'Override stylus options:' , options ) ; } // define functions and constant values if ( options . fn && Object . keys ( options . fn ) . length ) { styl . use ( function ( styl ) { _ . each ( options . fn , function ( fn , name ) { if ( _ . isFunction ( fn ) ) { styl . define ( name , function ( data ) { return fn ( data && data . val ) ; } ) ; } else { styl . define ( name , function ( ) { return fn ; } ) ; } } ) ; } ) ; } styl . render ( function ( err , css ) { err && callback ( err , css ) ; fs . writeFileSync ( dst , css , encode ) ; callback ( null , css ) ; } ) ; }
Compile the stylus file, and save it to a file.

@name write
@memberof stylus
@method
@param {String} src Stylus target file(formt: stylus)
@param {String} dst CSS file to be saved
@param {Object} options stylus options
@param {function} callback
@example
beezlib.css.stylus.write('./test.styl', './test.css', {
options: {
compress: true,
firebug: false,
linenos: false,
nib: true,
fn : function (styl) {
styl.define('body-padding', function (data) {
var rate  = data.val || 1;
var base = 10;
return (rate * base) + 'px';
});
}
},
{
extend: {
"condition": {
"ua": [ "android", "ios" ]
},
"content": {
"options": {
"fn": {
"STAT_URL": "http://stat.example.com"
}
}
}
}
}
}, function (err, css) {
if (err) {
throw err;
}
console.log(css)
});
Compile the stylus file and save it to a file .