'use strict';
var defaults = {
	sourcemap: 'external', // inline, external, false
	options: {
		'include css': true,
		'resolve url': true,
		'urlfunc': 'url'
	}
};

/**
 * Ingredients:
 *
 * gulp-stylus
 * https://github.com/stevelacy/gulp-stylus
 *
 * gulp-flatten
 * https://github.com/armed/gulp-flatten
 *
 * gulp-newer
 * https://github.com/tschaub/gulp-newer
 *
 * gulp-sourcemaps
 * https://github.com/floridoo/gulp-sourcemaps
 *
 */
function stylusTask(gulp, config, stream, done) {
	// lazy loading required modules.
	var stylus = require('gulp-stylus'),
		flatten = require('gulp-flatten'),
		newer = require('gulp-newer'),
		sourcemaps = require('gulp-sourcemaps'),
		_ = require('lodash');

	var options = _.defaults({}, config.options, defaults.options, {
			compress: !config.debug
		}),
		sourcemap = !config.debug && (config.sourcemap || config.sourcemaps);

	if (!stream) {
		stream = gulp.src(config.src.globs, config.src.options);
	}

	if (config.flatten) {
		stream = stream.pipe(flatten());
	}

	stream = stream.pipe(newer(config.dest.path));

	if (sourcemap) {
		stream = stream.pipe(sourcemaps.init());
	}

	stream = stream.pipe(stylus(options));

	if (sourcemap) {
		// To write external source map files,
		// pass a path relative to the destination to sourcemaps.write().
		stream = stream.pipe(sourcemaps.write(sourcemap === 'inline' ? undefined : '.'));
	}

	return stream
		.pipe(gulp.dest(config.dest.path, config.dest.options));
}

stylusTask.description = '';
stylusTask.consumes = ['dest', 'flatten', 'options', 'sourcemap', 'sourcemaps', 'src'];
stylusTask.defaults = defaults;

module.exports = stylusTask;

@@ -10,159 +10,8 @@
 ct';
-%0Avar defaults = %7B%0A%09sourcemap: 'external', // inline, external, false%0A%09options: %7B%0A%09%09'include css': true,%0A%09%09'resolve url': true,%0A%09%09'urlfunc': 'url'%0A%09%7D%0A%7D;
 %0A%0A/*
@@ -1322,143 +1322,817 @@
 sk.d
-escription = '';%0AstylusTask.consumes = %5B'dest', 'flatten', 'options', 'sourcemap', 'sourcemaps', 'src'%5D;%0AstylusTask.defaults = defaults
+isplayName = 'stylus';%0AstylusTask.description = '';%0AstylusTask.schema = %7B%0A%09%22properties%22: %7B%0A%09%09%22src%22: %7B%0A%09%09%09%22description%22: %22%22%0A%09%09%7D,%0A%09%09%22dest%22: %7B%0A%09%09%09%22description%22: %22%22%0A%09%09%7D,%0A%09%09%22flatten%22: %7B%0A%09%09%09%22description%22: %22%22,%0A%09%09%09%22type%22: %22boolean%22,%0A%09%09%09%22default%22: false%0A%09%09%7D,%0A%09%09%22sourcemap%22: %7B%0A%09%09%09%22description%22: %22generate sourcemap file or not?%22,%0A%09%09%09%22enum%22: %5B%0A%09%09%09%09%22inline%22, %22external%22, false%0A%09%09%09%5D,%0A%09%09%09%22alias%22: %5B%22sourcemaps%22%5D,%0A%09%09%09%22default%22: false%0A%09%09%7D,%0A%09%09%22options%22: %7B%0A%09%09%09%22description%22: %22%22,%0A%09%09%09%22properties%22: %7B%0A%09%09%09%09%22include css%22: %7B%0A%09%09%09%09%09%22description%22: %22%22,%0A%09%09%09%09%09%22type%22: %22boolean%22,%0A%09%09%09%09%09%22default%22: true%0A%09%09%09%09%7D,%0A%09%09%09%09%22resolve url%22: %7B%0A%09%09%09%09%09%22description%22: %22%22,%0A%09%09%09%09%09%22type%22: %22boolean%22,%0A%09%09%09%09%09%22default%22: true%0A%09%09%09%09%7D,%0A%09%09%09%09%22urlfunc%22: %7B%0A%09%09%09%09%09%22description%22: %22%22,%0A%09%09%09%09%09%22type%22: %22string%22,%0A%09%09%09%09%09%22default%22: %22url%22%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D,%0A%09%22required%22: %5B%22src%22, %22dest%22%5D%0A%7D
 ;%0A%0Am

add schema for stylus