include('helma/webapp/response');
include('helma/engine');
include('helma/jsdoc');
require('core/array');

exports.index = function index(req, module) {
    var repo = new ScriptRepository(getRepositories()[1]);
    if (module && module != "/") {
        var jsdoc = [];
        var res = repo.getScriptResource(module);
        var currentDoc;
        parseScriptResource(res, function(node) {
            if (node.jsDoc) {
                currentDoc = extractTags(node.jsDoc)
                // print(currentDoc[0][1]);
                jsdoc.push(currentDoc);
            } else {
                // print(getTypeName(node) + " // " + getName(node));
                if (isName(node) && getName(node) != "exports" && currentDoc && !currentDoc.name) {
                    Object.defineProperty(currentDoc, 'name', {value: getName(node)});
                }
            }
            return true;
        });
        return new SkinnedResponse(getResource('./skins/module.html'), {
            title: "Module " + res.moduleName,
            jsdoc: jsdoc
        });
    } else {
        var modules = repo.getScriptResources(true).sort(function(a, b) {return a.relativePath > b.relativePath});
        return new SkinnedResponse(getResource('./skins/index.html'), {
            title: "API Documentation",
            modules: modules
        });
    }
}



@@ -1145,16 +1145,29 @@
 (a, b) %7B
+%0A            
 return a
@@ -1196,16 +1196,35 @@
 tivePath
+ ? 1 : -1;%0A        
 %7D);%0A    

Fix resource sorting function