Example #1
0
File: doc.js Project: earl/ringojs
/**
 * Write documentation page for a module to directory. corresponds to actions:module
 *
 * @param {String} directory
 * @param {String} repository path
 * @param {String} moduleId
 */
function writeModuleDoc(target, repository, moduleId){

    var moduleDirectory = target;
    var modules = [];
    moduleDirectory = join(target, moduleId);
    makeTree(moduleDirectory);
    modules = moduleList(repository.path);

    var docs = moduleDoc(repository.path, moduleId);
    if (docs == null) {
        throw new Error('Could not parse JsDoc for ' + repository.path + moduleId);
    }

    var slashCount = strings.count(moduleId, '/');
    var relativeRoot = '../' + strings.repeat('../', slashCount);

    var moduleHtml = render('skins/module.html',
        objects.merge(defaultContext, {
            rootPath: relativeRoot,
            repositoryName: repository.name,
            moduleId: moduleId,
            modules: modules,
            item: structureModuleDoc(docs),
        })
    );

    var moduleFile = join(moduleDirectory, 'index.html');
    write(moduleFile, moduleHtml);
    return;
};
Example #2
0
/**
 * Write html page documenting one module to the directory.
 *
 * @param {String} directory
 * @param {Object} repository repository descriptor
 * @param {Object} module module descriptor
 */
function writeModuleDoc(directory, repository, module){

    var moduleDirectory = directory;
    var modules = [];
    moduleDirectory = fs.join(directory, module.id);
    fs.makeTree(moduleDirectory);
    modules = moduleList(repository);

    var slashCount = strings.count(module.id, '/');
    var relativeRoot = '../' + strings.repeat('../', slashCount);

    function toLink(target) {
        // if link target roughly matches "foo/bar#xxx.yyy"
        // format as API reference link
        if (target.match(/^[\w\/\.#]+$/)) {
            var [module, hash] = target.split("#");
            if (!module) {
                return [target, target.slice(1)];
            } else {
                var href = relativeRoot + module + "/" + defaultContext.indexhtml;
                if (hash) href += "#" + hash;
                return [href, target.replace("#", ".")];
            }
        }
        return null;
    }

    var docs = moduleDoc(repository.path, module, toLink);
    if (docs == null) {
        throw new Error('Could not parse JsDoc for ' + repository.path + module.id);
    }

    var context = objects.merge(defaultContext, {
        rootPath: relativeRoot,
        repositoryName: repository.name,
        title: module.name + ' - ' + repository.name,
        moduleId: module.id,
        modules: modules,
        item: structureModuleDoc(docs),
        iterate: function(value) {
            return value && value.length ? {each: value} : null;
        },
        debug: function(value) {
            print(value.toSource());
            return null;
        },
        commaList: function(value) {
            return value && value.length ? value.join(', ') : '';
        }
    });

    var moduleHtml = (templates.getTemplate('module.html')).render(context);
    var moduleFile = fs.join(moduleDirectory, 'index.html');
    fs.write(moduleFile, moduleHtml);
}