doxmate Version: 0.1.0 By @Jackson Tian

Generate your documentation.

doxmate: API索引


getIndexs

从Markdown中提取标题列表

方法 exports.getIndexs() exports getIndexs
返回 Array 返回标题列表
代码
exports.getIndexs = function (section, level, filter) {
  level = level || 3; // 默认抽取到三级标题
  level = level > 6 ? 6 : level; // 最大到6级标题
  level = level < 1 ? 1 : level; // 最小到1级标题
  filter = filter || function (item) {return true; };
  var matched = section.match(/.*\r?\n(\=+)|#+\s+(.*)/gm);
  if (matched) {
    return matched.map(function (item) {
      if (/#+/.test(item)) {
        var level = item.match(/#+/)[0].length;
        var title = item.replace(/#+\s+/, '');
        return {level: level, title: title};
      } else {
        return {level: 1, title: item.split(/\n/)[0]};
      }
    }).filter(function (item) {
      return item.level <= level;
    }).filter(filter);
  } else {
    return [];
  }
};

version

doxmate的版本号

属性 exports.version exports version
代码
exports.version = require('../package.json').version;

process

处理目录,生成文档

方法 exports.process() exports process
参数 input(String) 输入目录路径
参数 output(String) 输出目录路径
代码
exports.process = function (input, output, skin) {
  var obj = require(path.resolve(input, 'package.json'));

  //代码所在目录
  var libDir =  path.join(input, 'lib');

  //主题名
  obj.filename = path.join(__dirname, '../templates/' + skin + '/index.html');

  //代码文档
  obj.docs = getDocs(input);

  obj.apis = getAPIs(libDir);
  var section = getTemplates(skin).section;
  var folders = getFolders(libDir);
  for (var folder in folders) {
    for (var key in folders[folder]) {
      obj.apis[key] = folders[folder][key];
    }
  }

  Object.keys(obj.apis).forEach(function (key) {
    obj.apis[key] = ejs.render(section, obj.apis[key]);
  });

  if (Object.keys(obj.apis).length) {
    // generate api
    var api = getTemplates(skin).api;
    fs.writeFileSync(path.join(output, 'api.html'), ejs.render(api, obj), 'utf8');
  }

  // generate homepage
  var doc = getTemplates(skin).doc;
  var readme = getReadme(input);
  obj.content = readme.content;
  obj.indexs = readme.indexs;
  fs.writeFileSync(path.join(output, 'index.html'), ejs.render(doc, obj), 'utf8');

  // generate docs
  Object.keys(obj.docs).forEach(function (key) {
    obj.content = markdown(obj.docs[key]);
    obj.indexs = exports.getIndexs(obj.docs[key]);
    fs.writeFileSync(path.join(output, key + '.html'), ejs.render(doc, obj), 'utf8');
  });

  // copy styles
  ncp(path.join(__dirname, '../templates/' + skin + '/bootstrap'), path.join(output, 'bootstrap'), function () {});
  ncp(path.join(__dirname, '../templates/' + skin + '/assets'), path.join(output, 'assets'), function () {});
};

list

显示所有主题列表

方法 exports.list() exports list
代码
exports.list = function () {
  var themeFiles = fs.readdirSync(path.join(__dirname, '../templates/'));
  return themeFiles.join('\n');
};

// TODO: 支持主题下载
exports.install = function (url) {
  return 'Coming soon.';
};