/**
 * Compile less files.
 * @function task.worker.compileLessFiles
 * @param {object} config - Work configuration.
 * @param {string} config.srcDir - Source jade directory.
 * @param {string} config.ignore - Ignore  jade pattern. Glob.
 * @param {string} config.pattern - Source jade file pattern. Glob.
 * @param {string} config.destDir - Destination html directory.
 * @param {function} callback - Callback when done.
 * @author Taka Okunishi
 *
 */

var debug = require('./_debug'),
    compile = require('../../lib/compile'),
    _convertDirectory = require('./_convert_directory'),
    compileLessFile = compile.compileLessFile;

exports = module.exports = function (config, callback) {
    _convertDirectory({
        srcDir: config.srcDir,
        destDir: config.destDir,
        pattern: config.pattern,
        ignore: config.ignore,
        fileNameConverter: function (filename) {
            return filename.replace(/\.less$/, '.css');
        },
        fileContentConverter: function (src, dest, callback) {
            compileLessFile(src, dest, function (err) {
                if (!err) {
                    debug.didCreateFile(dest);
                }
                callback(err);
            });
        }
    }, function (err) {
        callback(err);
    });
};