builder/docgen.js
// Generate document object based on js filename and folder
Generate document object based on js filename and folder
Generate document object based on js filename and folder
function gendoc(filename,folder) {
  var path = './../lib/';
  var code  = fs.readFileSync(path + folder + '/' + filename,'utf8');
  var funstr = /\$u[.][^{]+/.exec(code)[0].trim();
    var funargs = funstr.split('function')[1];
  var re = /\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g;
  var arr = re.exec(code);
  var out = [];
  while (arr !== null) {
    out.push(arr);
    arr = re.exec(code);
    re.lastIndex;
  }
   var category = out[0][0].replace('/**', '')
   .replace('*/', '')
   .replace(/\n\s*\* ?/g, '\n')
   .replace(/\r/g, '');
   var txtline = category.split('\n');
   var catname = txtline[1];
   var comment = out[1][0].replace('/**', '')
   .replace('*/', '')
   .replace(/\n\s*\* ?/g, '\n')
   .replace(/\r/g, '');
   var lines = comment.split('\n');
   doc = {
    'funargs': funargs,
    'syntax': '',
    'category': catname,
    'name': '',
    'summary': '',
    'description': '',
    'param': [],
    'returns': [],
    'example': {},
    'folder': folder,
    'filename': filename
  }
  var count = 0,
  tagdesc = false,
  tagex = false;
  while (count < lines.length) {
    var line = lines[count];
    if (line === '') {
      line = line.replace('','\n');
    }
    if (line !== '') {
      if (/^@method/.test(line)) {
        var match = line.replace('@method','');
        doc.name = match.trim();
      }
      if (/^@summary/.test(line)) {
        var match = line.replace('@summary','');
        doc.summary = match.trim();
      }
      if (/^@description/.test(line)) {
        var match = line.replace('@description','');
        doc.description = match.trim();
        tagdesc = true;
      } else
      if (tagdesc === true) {
        if (!/^@/.test(line)) {
          doc.description += '  \n' + line.trim();
        }
      }
      if (/^@param/.test(line)) {
        tagdesc = false;
        var match = line.replace('@param','')
        .replace('{','')
        .replace('}','')
        .replace(/\|/g,'/')
        .trim()
        .replace(' ','\n')
        .replace(' ','\n')
        .split('\n');
        doc.param.push(match);
      }
      if (/^@return/.test(line)) {
       var match = line.replace('@return','')
       .replace('{','`')
       .replace('}','`')
       .replace(/\|/g,'/')
       .trim()
       .replace(' ','\n')
       .replace(' ','\n')
       .split('\n');
       doc.returns.push(match);
     }
      if (/^@example/.test(line)) {
        var i = 1, txt = [], vars = [],funs = [];
        while (lines[count + i] !== undefined) {
          var tmp = lines[count + i];
          if (/^var/.test(tmp)) {
           vars.push(tmp.trim());
         }
         if (/^ubique/.test(tmp)) {
           funs.push(tmp.trim());
         }
         txt.push(tmp.trim());
         i++;
       }
       doc.example = {'txt':txt, 'vars': vars, 'funs': funs}
     }
   }
   count++;
 }
 return doc;
}
function gendoc ( filename , folder ) { var path = './../lib/' ; var code = fs . readFileSync ( path + folder + '/' + filename , 'utf8' ) ; var funstr = / \$u[.][^{]+ / . exec ( code ) [ 0 ] . trim ( ) ; var funargs = funstr . split ( 'function' ) [ 1 ] ; var re = / \/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/ / g ; var arr = re . exec ( code ) ; var out = [ ] ; while ( arr !== null ) { out . push ( arr ) ; arr = re . exec ( code ) ; re . lastIndex ; } var category = out [ 0 ] [ 0 ] . replace ( '/**' , '' ) . replace ( '*/' , '' ) . replace ( / \n\s*\* ? / g , '\n' ) . replace ( / \r / g , '' ) ; var txtline = category . split ( '\n' ) ; var catname = txtline [ 1 ] ; var comment = out [ 1 ] [ 0 ] . replace ( '/**' , '' ) . replace ( '*/' , '' ) . replace ( / \n\s*\* ? / g , '\n' ) . replace ( / \r / g , '' ) ; var lines = comment . split ( '\n' ) ; doc = { 'funargs' : funargs , 'syntax' : '' , 'category' : catname , 'name' : '' , 'summary' : '' , 'description' : '' , 'param' : [ ] , 'returns' : [ ] , 'example' : { } , 'folder' : folder , 'filename' : filename } var count = 0 , tagdesc = false , tagex = false ; while ( count < lines . length ) { var line = lines [ count ] ; if ( line === '' ) { line = line . replace ( '' , '\n' ) ; } if ( line !== '' ) { if ( / ^@method / . test ( line ) ) { var match = line . replace ( '@method' , '' ) ; doc . name = match . trim ( ) ; } if ( / ^@summary / . test ( line ) ) { var match = line . replace ( '@summary' , '' ) ; doc . summary = match . trim ( ) ; } if ( / ^@description / . test ( line ) ) { var match = line . replace ( '@description' , '' ) ; doc . description = match . trim ( ) ; tagdesc = true ; } else if ( tagdesc === true ) { if ( ! / ^@ / . test ( line ) ) { doc . description += '  \n' + line . trim ( ) ; } } if ( / ^@param / . test ( line ) ) { tagdesc = false ; var match = line . replace ( '@param' , '' ) . replace ( '{' , '' ) . replace ( '}' , '' ) . replace ( / \| / g , '/' ) . trim ( ) . replace ( ' ' , '\n' ) . replace ( ' ' , '\n' ) . split ( '\n' ) ; doc . param . push ( match ) ; } if ( / ^@return / . test ( line ) ) { var match = line . replace ( '@return' , '' ) . replace ( '{' , '`' ) . replace ( '}' , '`' ) . replace ( / \| / g , '/' ) . trim ( ) . replace ( ' ' , '\n' ) . replace ( ' ' , '\n' ) . split ( '\n' ) ; doc . returns . push ( match ) ; } if ( / ^@example / . test ( line ) ) { var i = 1 , txt = [ ] , vars = [ ] , funs = [ ] ; while ( lines [ count + i ] !== undefined ) { var tmp = lines [ count + i ] ; if ( / ^var / . test ( tmp ) ) { vars . push ( tmp . trim ( ) ) ; } if ( / ^ubique / . test ( tmp ) ) { funs . push ( tmp . trim ( ) ) ; } txt . push ( tmp . trim ( ) ) ; i ++ ; } doc . example = { 'txt' : txt , 'vars' : vars , 'funs' : funs } } } count ++ ; } return doc ; }
Generate document object based on js filename and folder
Generate document object based on js filename and folder
// load js method // function arguments // comments // category // method // summary // description // parameters // returns // examples