<commit_before>var fspath = require('path'),
  express = require('express'),
  util = require('util'),
  fs = require('fs'),
  events = require('events'),
  url = require('url'),
  extensions = require('./extensions'),
  Doc = require('./doc'),
  jade = require('jade'),
  xtend = require('xtend'),
  converter = require('rel-to-abs');
    
function App(basePath, baseUrl, app){

  events.EventEmitter.call(this);

  var self = this;

  this._embedded = !!app;
  this._baseUrl = baseUrl || '';
  this._basePath = basePath || process.cwd();
  this._markdocsPath = __dirname;
  this._preRenders = [];
  this._extensions = extensions.slice(0);

  //app
  this._app = app || express();

  var merge = function (target, source) {
    for(var attr in source) {
      target[attr] = source[attr];
    }
    return target;
  };

  var defaultSettings = require(fspath.resolve(this._markdocsPath, 'default_settings.json'));
  var appSettings = require(fspath.resolve(this._basePath, 'settings.json'));

  //load theme
  this._themePath = fspath.resolve(this._basePath, 'themes', appSettings.theme || defaultSettings.theme || 'default');
  this._theme = new (require(this._themePath))(this);

  var themeSettings = require(fspath.resolve(this._themePath, 'settings.json'));
  this._settings = merge(defaultSettings, merge(themeSettings, appSettings));

  //configure app
  this._app.configure(function(){
    if (!self._embedded) {
      self._app.set('port', process.env.PORT || 3000);
      self._app.set('views',  fspath.resolve(self._themePath, 'views'));
      self._app.set('view engine', 'jade');
      self._app.use(express.favicon());
      self._app.use(express.logger('dev'));
      self._app.use(express.bodyParser());
      self._app.use(express.methodOverride());
      self._app.use(self._app.router);
    }
    self._app.use(express.static(fspath.resolve(self._basePath, 'public')));
    self._app.use(express.static(fspath.resolve(self._themePath, 'public')));
  });


  //load docs
  this._docsPath = fspath.resolve(basePath, 'docs');
  this._docsByUrl = {};
  this._docsByFilename = {};
  var middlewares = [].concat(self._get.bind(self))
                      .concat(self._preRender.bind(self))
                      .concat(self._render.bind(self));
  fs.readdirSync(this._docsPath).forEach(function(filename) {
    if (!/\.md$/.test(filename)) return;
    var doc = new Doc(self, filename);<commit_msg>Fix basepath for cases where it is not provided<commit_after>var fspath = require('path'),
  express = require('express'),
  util = require('util'),
  fs = require('fs'),
  events = require('events'),
  url = require('url'),
  extensions = require('./extensions'),
  Doc = require('./doc'),
  jade = require('jade'),
  xtend = require('xtend'),
  converter = require('rel-to-abs');
    
function App(basePath, baseUrl, app){

  events.EventEmitter.call(this);

  var self = this;

  this._embedded = !!app;
  this._baseUrl = baseUrl || '';
  this._basePath = basePath || process.cwd();
  this._markdocsPath = __dirname;
  this._preRenders = [];
  this._extensions = extensions.slice(0);

  //app
  this._app = app || express();

  var merge = function (target, source) {
    for(var attr in source) {
      target[attr] = source[attr];
    }
    return target;
  };

  var defaultSettings = require(fspath.resolve(this._markdocsPath, 'default_settings.json'));
  var appSettings = require(fspath.resolve(this._basePath, 'settings.json'));

  //load theme
  this._themePath = fspath.resolve(this._basePath, 'themes', appSettings.theme || defaultSettings.theme || 'default');
  this._theme = new (require(this._themePath))(this);

  var themeSettings = require(fspath.resolve(this._themePath, 'settings.json'));
  this._settings = merge(defaultSettings, merge(themeSettings, appSettings));

  //configure app
  this._app.configure(function(){
    if (!self._embedded) {
      self._app.set('port', process.env.PORT || 3000);
      self._app.set('views',  fspath.resolve(self._themePath, 'views'));
      self._app.set('view engine', 'jade');
      self._app.use(express.favicon());
      self._app.use(express.logger('dev'));
      self._app.use(express.bodyParser());
      self._app.use(express.methodOverride());
      self._app.use(self._app.router);
    }
    self._app.use(express.static(fspath.resolve(self._basePath, 'public')));
    self._app.use(express.static(fspath.resolve(self._themePath, 'public')));
  });


  //load docs
  this._docsPath = fspath.resolve(this._basePath, 'docs');
  this._docsByUrl = {};
  this._docsByFilename = {};
  var middlewares = [].concat(self._get.bind(self))
                      .concat(self._preRender.bind(self))
                      .concat(self._render.bind(self));
  fs.readdirSync(this._docsPath).forEach(function(filename) {
    if (!/\.md$/.test(filename)) return;
    var doc = new Doc(self, filename);
{'fraction_non_alphanumeric': 0.1731006160164271, 'fraction_numerical': 0.002053388090349076, 'mean_word_length': 3.7383268482490273, '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': '4359204', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1529, 'n_words': 269}