// Generated by CoffeeScript 1.12.1
(function() {
  var Adapter, SCSS, W, path,
    extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
    hasProp = {}.hasOwnProperty;

  Adapter = require('../../adapter_base');

  W = require('when');

  path = require('path');

  SCSS = (function(superClass) {
    extend(SCSS, superClass);

    function SCSS() {
      return SCSS.__super__.constructor.apply(this, arguments);
    }

    SCSS.prototype.name = 'scss';

    SCSS.prototype.extensions = ['scss', 'sass'];

    SCSS.prototype.output = 'css';

    SCSS.prototype.supportedEngines = ['node-sass'];

    SCSS.prototype._render = function(str, options) {
      var deferred;
      deferred = W.defer();
      if (options.sourcemap === true) {
        options.sourceMap = true;
        options.outFile = path.basename(options.filename).replace('.scss', '.css');
        options.omitSourceMapUrl = true;
        options.sourceMapContents = true;
      }
      options.file = options.filename;
      options.data = str;
      options.error = function(err) {
        return deferred.reject(err);
      };
      options.success = function(res) {
        var data;
        data = {
          result: String(res.css),
          imports: res.stats.includedFiles,
          meta: {
            entry: res.stats.entry,
            start: res.stats.start,
            end: res.stats.end,
            duration: res.stats.duration
          }
        };
        if (res.map && Object.keys(JSON.parse(res.map)).length) {
          data.sourcemap = JSON.parse(res.map);
          data.sourcemap.sources.pop();
          data.sourcemap.sources.push(options.file);
        }
        return deferred.resolve(data);
      };
      this.engine.render(options);
      return deferred.promise;
    };

    return SCSS;

  })(Adapter);

  module.exports = SCSS;

}).call(this);
