Skip to content

Commit

Permalink
use new tree access
Browse files Browse the repository at this point in the history
  • Loading branch information
lipp committed Jan 21, 2016
1 parent 93bb508 commit debe36e
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 534 deletions.
20 changes: 17 additions & 3 deletions assets/style.css
Expand Up @@ -73,11 +73,28 @@ body {
color: #F0F0F0;
}

.api nav ul ul {
padding-left: 1em
}

.api nav > ul, .api nav > ul > li > ul {
padding-left: 0
}

.api nav li {
overflow: hidden;
text-overflow: ellipsis;
}

.kind {
margin-left: 0.5em;
padding: 0.0em 0.2em;
font-size: 10px;
border: 1px solid;
font-weight: 100;
border-radius: 3px;
}

::-webkit-scrollbar {
display: none;
}
Expand Down Expand Up @@ -145,9 +162,6 @@ body {
margin: 0 0;
}

.main .args {
margin-left: -0.6em;
}

.args:before {
content: '(';
Expand Down
147 changes: 35 additions & 112 deletions lib/structure.js
Expand Up @@ -3,65 +3,6 @@ var marked = require('marked')
var urlParser = require('url')
var flat = require('flat')

var modules = {}
var classes = {}

var initModules = function (doclets) {
var createModule = function (doclet) {
var module = {
classes: [],
interfaces: [],
functions: [],
constants: [],
typedefs: [],
externals: [],
members: [],
namespaces: [],
doclet: doclet,
kind: function () {
// console.log(doclets)
var subdoclets = _.filter(doclets, function (cand) {
return cand.longname === doclet.longname && cand.kind !== 'module'
})
if (subdoclets.length === 1) {
if (subdoclets[0].kind === 'member') {
return 'module'
} else {
return subdoclets[0].kind
}
} else {
return doclet.type && doclet.type.names[0] || 'module'
}
}
}
return module
}
modules = _.chain(doclets)
.filter(function (doclet) {
return doclet.kind === 'module'
})
.indexBy('longname')
.mapObject(function (doclet) {
return createModule(doclet)
})
.value()

// for doclets which are NOT part of a module
modules._GLOBAL = createModule()
}

var initClasses = function (doclets) {
classes = _.chain(doclets)
.filter(function (doclet) {
return doclet.kind === 'class' || doclet.kind === 'interface'
})
.each(function (classDoclet) {
classDoclet.members = []
})
.indexBy('longname')
.value()
}

var isPublic = module.exports.isPublic = function (doclet) {
if (doclet.access && doclet.access !== 'public') {
return false
Expand All @@ -77,41 +18,6 @@ var isPublic = module.exports.isPublic = function (doclet) {
return true
}

var categories = {
'class': 'classes',
'interface': 'interfaces',
'function': 'functions',
'constant': 'constants',
'callback': 'callbacks',
'typedef': 'typedefs',
'external': 'externals',
'member': 'members',
'namespace': 'namespaces'
}

var addToParent = function (doclets, category, pred) {
_.chain(doclets)
.filter(function (doclet) {
return pred(doclet)
})
.each(function (docletOfKind) {
if (docletOfKind.scope === 'global') {
modules._GLOBAL[category].push(docletOfKind)
} else {
if (modules[docletOfKind.memberof]) {
modules[docletOfKind.memberof][category].push(docletOfKind)
} else if (classes[docletOfKind.memberof]) {
classes[docletOfKind.memberof].members.push(docletOfKind)
} else if (docletOfKind.kind !== 'member' && docletOfKind.memberof === undefined && modules[docletOfKind.longname]) {
// the module itself IS a class, function, etc
modules[docletOfKind.longname][categories[docletOfKind.kind]].push(docletOfKind)
} else {
console.log('unassigned', docletOfKind.longname, docletOfKind.kind, docletOfKind.memberof)
}
}
})
}

var fileRootFromGitHubUrl = function (url, branch) {
return url + '/blob/' + branch + '/'
}
Expand All @@ -120,7 +26,7 @@ var rawRootFromGitHubUrl = function (url, branch) {
return url + '/raw/' + branch + '/'
}

var addUrlToDoclets = module.exports.addUrlToDoclets = function (doclets, githubUrl, branch) {
module.exports.addUrlToDoclets = function (doclets, githubUrl, branch) {
var fileBaseUrl = fileRootFromGitHubUrl(githubUrl, branch)
_.each(doclets, function (doclet) {
try {
Expand All @@ -131,19 +37,13 @@ var addUrlToDoclets = module.exports.addUrlToDoclets = function (doclets, github
})
}

module.exports.buildHierarchy = function (data, repoUrl, repoBranch) {
var doclets = _.filter(data.doclets, isPublic)
addUrlToDoclets(doclets, repoUrl, repoBranch)

initModules(doclets)
initClasses(doclets)

_.each(_.keys(categories), function (kind) {
addToParent(doclets, categories[kind], function (doclet) {
return doclet.kind === kind
})
var clearAnonymous = module.exports.clearAnonymous = function (doclets) {
_.each(doclets, function (doclet) {
var match = doclet.longname.match(/<anonymous>(~|\.|#)(.+)/)
if (match) {
doclet.longname = match[2]
}
})
return modules
}

var isRelativeLink = module.exports.isRelativeLink = function (href) {
Expand Down Expand Up @@ -194,13 +94,32 @@ var Node = function (doclet, module) {
}

module.exports.childs = function (node) {
return _.pick(node, function (val, key) {
return key.indexOf('__') !== 0
})
return _.chain(node)
.pick(function (val, key) {
return key.indexOf('__') !== 0
})
.mapObject(function (value, key) {
return {
name: key,
node: value
}
})
.toArray()
.sortBy('name')
.value()
}

module.exports.flat = function (doclets) {
return _.chain(doclets)
.filter(isPublic)
.sortBy('longname')
.value()
}

module.exports.tree = function (doclets) {
clearAnonymous(doclets)
var modules = _.chain(doclets)
.filter(isPublic)
.where({kind: 'module'})
.map(function (module) {
var flatTree = _.chain(doclets)
Expand All @@ -223,6 +142,7 @@ module.exports.tree = function (doclets) {
.value()

var globalTree = _.chain(doclets)
.filter(isPublic)
.filter(function (doclet) {
return doclet.longname.indexOf('module:') === -1
})
Expand All @@ -232,8 +152,11 @@ module.exports.tree = function (doclets) {
.indexBy('__id')
.value()

modules._GLOBAL = {
childs: flat.unflatten(globalTree, {delimiter: /~|\.|#/})
if (_.keys(globalTree).length > 0) {
modules.push({
longname: 'globals',
childs: flat.unflatten(globalTree, {delimiter: /~|\.|#/})
})
}

return modules
Expand Down
9 changes: 7 additions & 2 deletions lib/view-params.js
Expand Up @@ -80,8 +80,11 @@ var getDescription = module.exports.getDescription = function (doclet) {
}

module.exports.getApiParams = function (doclet) {
structure.addUrlToDoclets(doclet.data.doclets, doclet._repo && doclet._repo.url, doclet.version)
return {
modules: structure.buildHierarchy(doclet.data, doclet.repo.url, doclet.version),
tree: structure.tree(doclet.data.doclets),
flat: structure.flat(doclet.data.doclets),
childs: structure.childs,
articles: doclet.data.articles,
repo: doclet.repo,
owner: doclet.owner,
Expand All @@ -104,9 +107,11 @@ module.exports.getArticleParams = function (doclet, article) {
})
var html = structure.buildArticleHtml(article, doclet.repo.url, doclet.version)
return {
modules: structure.buildHierarchy(data, doclet.repo.url, doclet.version),
tree: structure.tree(data.doclets),
childs: structure.childs,
articles: data.articles,
repo: doclet.repo,
owner: doclet.owner,
contentHtml: html,
'_': _,
tools: tools,
Expand Down

0 comments on commit debe36e

Please sign in to comment.