"use strict";

var util = require('util'),
    stylus = require('stylus'),
    nib = require('nib'),

    Asset = require('../Asset'),
    StylusAsset = function(settings) {
        settings.compressor = settings.compressor || 'none';

        this.init(settings);

        var self = this;

        this.on('variantRenderFile', function(variant, file, cb) {
            stylus(variant.getRenderCache(file))
                .use(nib())
                .set('filename', file)
                .set('linenos', !Asset.COMPRESS)
                .set('compress', Asset.COMPRESS)
                .define('staticAsset', function(assetId) {
                    return self.manager.getAssetUrl(assetId.val);
                })
                .render(function(err, css) {
                    if (err) {
                        console.error("ERROR: Unable to render " + file + " using stylus!");
                        console.error(err);
                        variant.setRenderCache(file, '/* Error */');
                        return cb(err);
                    }

                    variant.setRenderCache(file, css);

                    return cb();
                });
        });
    };

util.inherits(StylusAsset, Asset);

StylusAsset.configure = function(opts) {
    Asset.configure(opts);
};

module.exports = StylusAsset;

@@ -32,24 +32,76 @@
 re('util'),%0A
+    path = require('path'),%0A    fs = require('fs'),%0A
     stylus =
@@ -116,24 +116,24 @@
 ('stylus'),%0A
-
     nib = re
@@ -415,16 +415,161 @@
         
+ var absFileDir = path.dirname(fs.realpathSync(file)),%0A                imports = variant.imports %7C%7C self.settings.imports,%0A                styl =
  stylus(
@@ -614,16 +614,20 @@
         
+    
 .use(nib
@@ -642,24 +642,28 @@
             
+   
+ 
 .set('filena
@@ -673,16 +673,20 @@
 , file)%0A
+    
         
@@ -738,24 +738,28 @@
             
+ 
+   
 .set('compre
@@ -795,16 +795,20 @@
         
+  
+  
 .define(
@@ -838,24 +838,28 @@
 (assetId) %7B%0A
+    
             
@@ -909,16 +909,32 @@
 etId.val
+, variant.params
 );%0A     
@@ -944,18 +944,24 @@
         
-%7D)
+    %7D);%0A
 %0A       
@@ -965,20 +965,518 @@
         
-    
+imports && imports.forEach(function(i) %7B%0A                var iPath = path.relative(absFileDir, fs.realpathSync(i));%0A%0A                if (!/%5C.(css%7Cstyl)$/i.test(path.extname(iPath))) %7B%0A                    console.warn('WARNING: Not importing ' + i + ' into stylus file ' + file + '; file extension must be .css or .styl!');%0A                    return;%0A                %7D%0A%0A                iPath = iPath.replace(/%5C.styl$/i, '');%0A%0A                styl = styl.import(iPath);%0A            %7D);%0A%0A            styl
 .render(

Support dynamic inclusion of files for @import in stylus