/* global require, module */
'use strict';

var mergeTrees  = require('broccoli-merge-trees');
var compileCompass = require('broccoli-compass');

function CompassCompilerPlugin(options, appName) {
  this.name    = 'ember-cli-compass-compiler';
  this.appName = appName;
  this.options = options || {};
  this.ext     = 'scss';
}

CompassCompilerPlugin.prototype.toTree = function(tree, inputPath, outputPath) {
  // broccoli-compass doesn't like leading slashes
  if (inputPath[0] === '/') { inputPath = inputPath.slice(1); }

  var options        = this.options;
  var mainFile       = options.mainFile       || (this.appName + '.' + this.ext);
  var outputStyle    = options.outputStyle    || 'compressed'; // or expanded
  var sassDir        = options.sassDir        || inputPath;
  var cssDir         = options.cssDir         || outputPath;
  var imagesDir      = options.imagesDir      || 'images';
  var fontsDir       = options.fontsDir       || 'fonts';
  var compassCommand = options.compassCommand || 'compass';

  var compassOptions = {
    outputStyle: outputStyle,
    require: options.require,
    importPath: options.importPath,
    sassDir: sassDir,
    imagesDir: imagesDir,
    fontsDir: fontsDir,
    cssDir: cssDir,
    compassCommand: compassCommand
  };

  tree = mergeTrees([tree, 'public'], {
    description: 'TreeMerger (stylesAndVendorAndPublic)'
  });

  return compileCompass(tree, inputPath + '/' + mainFile, compassOptions);
};

function EmberCLICompassCompiler(project) {
  this.project = project;
  this.name    = 'Ember CLI Compass Compiler';
}

EmberCLICompassCompiler.prototype.treeFor = function treeFor() {

};

EmberCLICompassCompiler.prototype.included = function included(app) {
  this.app     = app;
  var registry = this.app.registry;
  var plugin   = new CompassCompilerPlugin(this.app.options.compassOptions, this.app.name);
  registry.add('css', plugin);
};

module.exports = EmberCLICompassCompiler;

@@ -639,16 +639,109 @@
 s.ext);%0A
+  var relativeAssets = options.relativeAssets !== undefined ? options.relativeAssets : true;%0A
   var ou
@@ -1134,16 +1134,52 @@
 ons = %7B%0A
+    relativeAssets: relativeAssets,%0A
     outp

Add support for relativeAssets, a boolean option, defaulting to true.