<commit_before>'use strict';

/**
 * module dependencies
 */

var path = require('path');
var Core = require('assemble-core');
var utils = require('./lib/utils');
var cli = require('./lib/cli');

/**
 * Create an `assemble` app. This is the main function exported
 * by the assemble module.
 *
 * ```js
 * var assemble = require('assemble');
 * var app = assemble();
 * ```
 * @param {Object} `options` Optionally pass default options to use.
 * @api public
 */

function Assemble(options) {
  if (!(this instanceof Assemble)) {
    return new Assemble(options);
  }

  Core.apply(this, arguments);
  this.isAssemble = true;

  this.initAssemble(this);
}

/**
 * Inherit assemble-core
 */

Core.extend(Assemble);

/**
 * Initialize Assemble defaults
 */

Assemble.prototype.initAssemble = function(app) {
  var opts = this.options;
  var exts = opts.exts || ['md', 'hbs', 'html'];
  var regex = utils.extRegex(exts);

  // ensure `name` is set for composer-runtimes
  if (!this.name) {
    this.name = opts.name || 'base';
  }

  /**
   * Register plugins
   */

  this.use(utils.pipeline(opts))
    .use(utils.pipeline())
    .use(utils.loader())
    .use(utils.config())
    .use(utils.store())
    .use(utils.argv())
    .use(utils.list())
    .use(utils.cli())
    .use(utils.ask())
    .use(cli());

  /**
   * Default engine
   */

  this.engine(exts, require('engine-handlebars'));

  /**
   * Middleware for parsing front matter
   */

  this.onLoad(regex, function(view, next) {
    // needs to be inside the middleware, to
    // account for options defined after init
    if (view.options.frontMatter !== false && app.options.frontMatter !== false) {
      utils.matter.parse(view, next);
    } else {
      next();
    }
  });

  /**
   * Built-in view collections
   *  | partials
   *  | layouts
   *  | pages
   */

  var engine = opts.defaultEngine || 'hbs';

  this.create('partials', {
    engine: engine,
    viewType: 'partial',
    renameKey: function(fp) {
      return path.basename(fp, path.extname(fp));
    }
  });

  this.create('layouts', {
    engine: engine,
    viewType: 'layout',
    renameKey: function(fp) {
      return path.basename(fp, path.extname(fp));
    }
  });

  this.create('pages', {
    engine: engine,
    renameKey: function(fp) {
      return fp;
    }
  });
};

/**
 * Set a `base` instance that can be used for storing
 * additional instances.
 */

Object.defineProperty(Assemble.prototype, 'base', {
  configurable: true,
  get: function() {
    return this.parent ? this.parent.base : this;
  }
});

/**
 * Expose `Assemble`
 */

module.exports = Assemble;
<commit_msg>split out init code into multiple methods, for easier overriding<commit_after>'use strict';

/**
 * module dependencies
 */

var path = require('path');
var Core = require('assemble-core');
var utils = require('./lib/utils');
var cli = require('./lib/cli');

/**
 * Create an `assemble` app. This is the main function exported
 * by the assemble module.
 *
 * ```js
 * var assemble = require('assemble');
 * var app = assemble();
 * ```
 * @param {Object} `options` Optionally pass default options to use.
 * @api public
 */

function Assemble(options) {
  if (!(this instanceof Assemble)) {
    return new Assemble(options);
  }

  Core.apply(this, arguments);
  this.isAssemble = true;

  this.initDefaults(this);
  this.initPlugins(this);
  this.initCollections(this);
}

/**
 * Inherit assemble-core
 */

Core.extend(Assemble);

/**
 * Initialize Assemble defaults
 */

Assemble.prototype.initDefaults = function(app) {
  var opts = this.options;
  var exts = opts.exts || ['md', 'hbs', 'html'];
  var regex = utils.extRegex(exts);

  /**
   * Default engine
   */

  this.engine(exts, require('engine-handlebars'));

  /**
   * Middleware for parsing front matter
   */

  this.onLoad(regex, function(view, next) {
    // check options inside the middleware to
    // account for options defined after init
    if (view.options.frontMatter !== false) {
      return next();
    }
    if (app.options.frontMatter !== false) {
      return next();
    }
    utils.matter.parse(view, next);
  });
};

/**
 * Load default plugins. Built-in plugins can be disabled
 * on the `assemble` options.
 *
 * ```js
 * var app = assemble({
 *   plugins: {
 *     loader: false,
 *     store: false
 *   }
 * });
 * ```
 * @api public
 */

Assemble.prototype.initPlugins = function(app) {
  enable('pipeline', utils.pipeline);
  enable('loader', utils.loader);
  enable('config', utils.config);
  enable('store', utils.store);
  enable('argv', utils.argv);
  enable('list', utils.list);
  enable('ask', utils.ask);
  enable('cli', cli);

  function enable(name, fn) {
    if (app.option('plugins') === false) return;
    if (app.option('plugins.' + name) !== false) {
      app.use(fn(app.options));
    }
  }
};

/**
 * Built-in view collections
 *  | partials
 *  | layouts
 *  | pages
 */

Assemble.prototype.initCollections = function(app) {
  if (this.option('collections') === false) return;

  var engine = this.options.defaultEngine || 'hbs';
  this.create('partials', {
    engine: engine,
    viewType: 'partial',
    renameKey: function(fp) {
      return path.basename(fp, path.extname(fp));
    }
  });

  this.create('layouts', {
    engine: engine,
    viewType: 'layout',
    renameKey: function(fp) {
      return path.basename(fp, path.extname(fp));
    }
  });

  this.create('pages', {
    engine: engine,
    renameKey: function(fp) {
      return fp;
    }
  });
};

/**
 * Ensure `name` is set on the instance for lookups.
 */

Object.defineProperty(Assemble.prototype, 'name', {
  configurable: true,
  set: function(name) {
    this.options.name = name;
  },
  get: function() {
    return this.options.name || 'base';
  }
});

/**
 * Set a `base` instance that can be used for storing
 * additional instances.
 */

Object.defineProperty(Assemble.prototype, 'base', {
  configurable: true,
  get: function() {
    return this.parent ? this.parent.base : this;
  }
});

/**
 * Expose `Assemble`
 */

module.exports = Assemble;

{'fraction_non_alphanumeric': 0.1683429513602638, 'fraction_numerical': 0.0, 'mean_word_length': 3.030564784053156, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3237242', 'n_tokens_mistral': 2021, 'n_tokens_neox': 1995, 'n_words': 475}