/** internal, section: Plugins
 *  Renderers.json(NDoc) -> Void
 *
 *  Registers JSON renderer as `json`.
 *
 *
 *  ##### Example
 *
 *      NDoc.render('json', ast, options, function (err) {
 *        // ...
 *      });
 *
 *
 *  ##### Options
 *
 *  - **index** (String): Intro text.
 *  - **output** (String): File where to output rendered documentation.
 *  - **title** (String): Page title template. You can use `{package.*}`
 *    variables here.
 *    Default: `'{package.name} {package.version} API documentation'`
 **/


'use strict';


// stdlib
var fs = require('fs');


// 3rd-party
var _ = require('underscore');


////////////////////////////////////////////////////////////////////////////////


var renderer_func = function (ndoc, options, callback) {
  var list = {}, id, d;

  for (id in ndoc.list) {
    if (ndoc.list.hasOwnProperty(id)) {
      d = ndoc.list[id];
      list[id] = {
        id: d.id,
        type: d.type,
        name: d.name,
        path: d.path,
        parent: d.parent,
        section: d.section,
      };
    }
  }

  fs.writeFile(options.output, JSON.stringify(_.extend({}, options, {
    list: ndoc.list,
    tree: ndoc.tree,
    date: (new Date()).toUTCString(),
  })), callback);
};


////////////////////////////////////////////////////////////////////////////////


module.exports = function (NDoc) {
  NDoc.registerRenderer('json', renderer_func);
};

@@ -245,46 +245,8 @@
 %0A *%0A
- *  - **index** (String): Intro text.%0A
  *  
@@ -317,173 +317,8 @@
 on.%0A
- *  - **title** (String): Page title template. You can use %60%7Bpackage.*%7D%60%0A *    variables here.%0A *    Default: %60'%7Bpackage.name%7D %7Bpackage.version%7D API documentation'%60%0A
  **/
@@ -376,54 +376,8 @@
 ;%0A%0A%0A
-// 3rd-party%0Avar _ = require('underscore');%0A%0A%0A
 ////
@@ -459,358 +459,124 @@
 /%0A%0A%0A
-var renderer_func = function (ndoc, options, callback) %7B%0A  var list = %7B%7D, id, d;%0A%0A  for (id in ndoc.list) %7B%0A    if (ndoc.list.hasOwnProperty(id)) %7B%0A      d = ndoc.list%5Bid%5D;%0A      list%5Bid%5D = %7B%0A        id: d.id,%0A        type: d.type,%0A        name: d.name,%0A        path: d.path,%0A        parent: d.parent,%0A        section: d.section,%0A      %7D;%0A    %7D%0A  %7D%0A%0A
+module.exports = function (NDoc) %7B%0A  NDoc.registerRenderer('json', function render_json(ast, options, callback) %7B%0A  
   fs
@@ -621,32 +621,12 @@
 ify(
-_.extend(%7B%7D, options, 
 %7B%0A
+  
     
@@ -635,19 +635,20 @@
 st: 
-ndoc
+ast
 .list,%0A
+  
     
@@ -657,19 +657,20 @@
 ee: 
-ndoc
+ast
 .tree,%0A
+  
     
@@ -705,15 +705,15 @@
 ng()
-,
 %0A
+  
   %7D)
-)
 , ca
@@ -725,176 +725,11 @@
 k);%0A
-%7D;%0A%0A%0A////////////////////////////////////////////////////////////////////////////////%0A%0A%0Amodule.exports = function (NDoc) %7B%0A  NDoc.registerRenderer('json', renderer_func
+  %7D
 );%0A%7D

Refactor JSON renderer