var ejs = require('ejs');
var path = require('path');
var _ = require('underscore');

// Routes store
var routesStore;
var defaultConfig = {
    title: 'Express API Documentation',
    cache: true
};

function renderTemplate(routes, callback) {
    var tmpl = path.join(__dirname, './template.ejs');
    var data = { routes: routes };

    ejs.renderFile(tmpl, data, {}, function(err, html) {
        if (err) throw err;
        callback(html);
    });
}

function getRoutes(routes) {
    // Array of routers
    if (_.isArray(routes)) {
        return _.reduce(routes, function(result, item) {
            return result.concat(buildRoutes(item.stack));
        }, []);

    // App default router
    } else if (routes._router) {
        return buildRoutes(routes._router.stack);
    }

    // Single route
    return buildRoutes(routes.stack);
}

function buildRoutes(routes) {
    return _.map(routes, function(route) {
        return {
            path: route.route.path,
            methods: _.keys(route.route.methods)
        };
    });
}

module.exports = function(routes, callback, options) {
    var opt = _.extend({}, defaultConfig, options);

    if (!opt.cache || !routesStore) {
        routesStore = getRoutes(routes);
    }

    renderTemplate(routesStore, callback);
};

@@ -234,16 +234,25 @@
 callback
+, options
 ) %7B%0A    
@@ -318,16 +318,24 @@
 data = %7B
+%0A       
  routes:
@@ -341,16 +341,50 @@
 : routes
+,%0A        title: options.title%0A   
  %7D;%0A%0A   
@@ -1126,39 +1126,38 @@
 utes, callback, 
-options
+config
 ) %7B%0A    var opt 
@@ -1155,16 +1155,20 @@
  var opt
+ions
  = _.ext
@@ -1190,23 +1190,22 @@
 Config, 
-options
+config
 );%0A%0A    
@@ -1212,16 +1212,20 @@
 if (!opt
+ions
 .cache %7C
@@ -1330,14 +1330,23 @@
 callback
+, options
 );%0A%7D;%0A

Fix title config