<commit_before>var LESSCompiler = require('broccoli-less-single');
var path         = require('path');
var merge        = require('lodash-node/modern/objects/merge');
var mergeTrees   = require('broccoli-merge-trees');
var checker      = require('ember-cli-version-checker');

function LESSPlugin(options) {
  this.name = 'ember-cli-less';
  this.ext = 'less';
  this.options = options;
}

LESSPlugin.prototype.toTree = function(tree, inputPath, outputPath, options) {
  options = merge({}, this.options, options);
  var ext = this.ext;
  var paths = options.outputPaths || { app: options.registry.app.options.outputPaths.app.css };

  var trees = Object.keys(paths).map(function(file) {
    var input = path.join(inputPath, file + '.' + ext);
    var output = paths[file];

    return new LESSCompiler([tree], input, output, options);
  });

  return mergeTrees(trees);
};

module.exports = {
  name: 'Ember CLI LESS',
  project: this.project,

  shouldSetupRegistryInIncluded: function() {
    return !checker.isAbove(this, '0.2.0');
  },

  lessOptions: function() {
    var env = process.env.EMBER_ENV;
    var options = this.project.config(env).lessOptions
        || (this.app && this.app.options.lessOptions) || {};
    if ((options.sourceMap === undefined) && (env === 'development')) {
      options.sourceMap = true;
    }
    return options;
  },

  setupPreprocessorRegistry: function(type, registry) {
    registry.add('css', new LESSPlugin(this.lessOptions()));

    // prevent conflict with broccoli-less-single if it's installed
    if (registry.remove) {
      registry.remove('css', 'broccoli-less-single');
    }
  },

  included: function(app) {
    this.app = app; // used to provide back-compat for ember-cli < 0.2.0 in lessOptions()
    this._super.included.apply(this, arguments);

    if (this.shouldSetupRegistryInIncluded()) {
      this.setupPreprocessorRegistry('parent', app.registry);
    }
  }
}<commit_msg>[fixes #19] make options building lazy<commit_after>var LESSCompiler = require('broccoli-less-single');
var path         = require('path');
var merge        = require('lodash-node/modern/objects/merge');
var mergeTrees   = require('broccoli-merge-trees');
var checker      = require('ember-cli-version-checker');

function LESSPlugin(optionsFn) {
  this.name = 'ember-cli-less';
  this.ext = 'less';
  this.optionsFn = optionsFn;
}

LESSPlugin.prototype.toTree = function(tree, inputPath, outputPath, options) {
  options = merge({}, this.optionsFn(), options);

  var ext = this.ext;
  var paths = options.outputPaths || { app: options.registry.app.options.outputPaths.app.css };

  var trees = Object.keys(paths).map(function(file) {
    var input = path.join(inputPath, file + '.' + ext);
    var output = paths[file];

    return new LESSCompiler([tree], input, output, options);
  });

  return mergeTrees(trees);
};

module.exports = {
  name: 'Ember CLI LESS',
  project: this.project,

  shouldSetupRegistryInIncluded: function() {
    return !checker.isAbove(this, '0.2.0');
  },

  lessOptions: function() {
    var env = process.env.EMBER_ENV;
    var options =  (this.app && this.app.options.lessOptions) || {};

    if ((options.sourceMap === undefined) && (env === 'development')) {
      options.sourceMap = true;
    }

    return options;
  },

  setupPreprocessorRegistry: function(type, registry) {
    registry.add('css', new LESSPlugin(this.lessOptions.bind(this)));

    // prevent conflict with broccoli-less-single if it's installed
    if (registry.remove) {
      registry.remove('css', 'broccoli-less-single');
    }
  },

  included: function(app) {
    this.app = app; // used to provide back-compat for ember-cli < 0.2.0 in lessOptions()
    this._super.included.apply(this, arguments);

    if (this.shouldSetupRegistryInIncluded()) {
      this.setupPreprocessorRegistry('parent', app.registry);
    }
  }
}
{'fraction_non_alphanumeric': 0.15342960288808663, 'fraction_numerical': 0.0036101083032490976, 'mean_word_length': 3.639952153110048, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3411712', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1199, 'n_words': 256}