Skip to content

Commit

Permalink
docs: short links to classes without module prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Mar 14, 2017
1 parent ce1df10 commit 912fd0d
Show file tree
Hide file tree
Showing 30 changed files with 2,586 additions and 3,739 deletions.
350 changes: 319 additions & 31 deletions docs/Auto Update.md

Large diffs are not rendered by default.

3,517 changes: 1,217 additions & 2,300 deletions docs/Developer API.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/Multi Platform Build.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Don't expect that you can build app for all platforms on one platform.

* If your app has native dependencies, it can be compiled only on the target platform.
[prebuild](https://www.npmjs.com/package/prebuild) is a solution, but most node modules [don't provide](https://github.com/atom/node-keytar/issues/27) prebuilt binaries.

[prebuild](https://www.npmjs.com/package/prebuild) is a solution, but most node modules [don't provide](https://github.com/atom/node-keytar/issues/27) prebuilt binaries.
By default build from sources is forced, set [npmSkipBuildFromSource](https://github.com/electron-userland/electron-builder/wiki/Options#Config-npmSkipBuildFromSource) to `true` to use prebuild binaries (if available).
* macOS Code Signing works only on macOS. [Cannot be fixed](http://stackoverflow.com/a/12156576).

Don't think that mentioned issues are major, you should use build servers — e.g. [AppVeyor](http://www.appveyor.com/) to build Windows app and [Travis](https://travis-ci.org) to build MacOS/Linux apps.
Expand Down
1,467 changes: 256 additions & 1,211 deletions docs/Options.md

Large diffs are not rendered by default.

325 changes: 322 additions & 3 deletions docs/Publishing Artifacts.md

Large diffs are not rendered by default.

218 changes: 218 additions & 0 deletions jsdoc/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
"use strict"

const dmdHelpers = require("dmd/helpers/ddata")
const catharsis = require("catharsis")

exports.propertyAnchor = function (propertyName, parentName) {
return `<a name="${parentName}-${propertyName}"></a>`
}

exports.listTypes = function (types, delimiter, root) {
return types == null ? "" : types.map(it => "<code>" + link2(catharsis.parse(it, {jsdoc: true}), delimiter, root) + "</code>").join(delimiter)
}

function link(longname, options) {
//noinspection JSUnresolvedFunction
return options.fn(_link(longname, options))
}

exports.link = link
exports.anchorName = anchorName

function _link(input, options) {
if (typeof input !== 'string') {
return null
}

/*
test input for
1. A type expression containing a namepath, e.g. Array.<module:Something>
2. a namepath referencing an `id`
3. a namepath referencing a `longname`
*/
const matches = input.match(/.*?<\(?(.*?)\(?>/)
const namepath = matches ? matches[1].split("|").map(it => it.trim()) : input

let linked = resolveById(namepath)
if (!linked) {
options.hash = {longname: namepath}
linked = _identifier(options)
}

if (!linked) {
return {name: input, url: null}
}

const output = {
name: input.replace(namepath, linked.name),
}

if (isExternal.call(linked)) {
if (linked.description) {
output.url = `#${anchorName.call(linked, options)}`
}
else {
if (linked.see && linked.see.length) {
const firstLink = parseLink(linked.see[0])[0]
output.url = firstLink ? firstLink.url : linked.see[0]
}
else {
output.url = null
}
}
}
else {
let isOnCurrentPage = false
const firstMember = options.data.root[0]
function isOurPage(otherRoot) {
return firstMember.id === otherRoot[0].id
}

for (const page of exports.pages) {
if (isOurPage(page.data)) {
isOnCurrentPage = page.dataMap.has(linked.id)
break
}
}

let pageUrl = ""
if (!isOnCurrentPage) {
for (const page of exports.pages) {
if (!isOurPage(page.data) && page.dataMap.has(linked.id)) {
pageUrl = page.pageUrl
}
}
}
output.url = `${pageUrl}#${anchorName.call(linked, options)}`
}
return output
}


function link2(type, delimiter, root) {
switch (type.type) {
case "NameExpression":
return identifierToLink(type.name, root)

case "NullLiteral":
case "UndefinedLiteral":
return type.typeExpression

case "FunctionType":
return type.typeExpression

case "TypeUnion":
return type.elements
.map(it => link2(it, delimiter, root))
.join(delimiter)

case "TypeApplication":
return link2(type.expression, delimiter, root) + "&lt;" + type.applications.map(it => link2(it, delimiter, root)).join(", ") + "&gt;"

default:
throw new Error(`Unsupported type ${type.type}`)
}
}

function identifierToLink(id, root) {
let linked = resolveById(id)
if (!linked) {
if (id.startsWith("module")) {
console.warn(`Unresolved member ${id}`)
}
return id
}

if (isExternal.call(linked)) {
if (linked.description) {
output.url = `#${anchorName.call(linked, options)}`
}
else {
if (linked.see && linked.see.length) {
const firstLink = parseLink(linked.see[0])[0]
output.url = firstLink ? firstLink.url : linked.see[0]
}
else {
output.url = null
}
}
return output
}

let isOnCurrentPage = false
const firstMember = root[0]

function isOurPage(otherRoot) {
return firstMember.id === otherRoot[0].id
}

for (const page of exports.pages) {
if (isOurPage(page.data)) {
isOnCurrentPage = page.dataMap.has(linked.id)
break
}
}

let pageUrl = ""
if (!isOnCurrentPage) {
for (const page of exports.pages) {
if (!isOurPage(page.data) && page.dataMap.has(linked.id)) {
pageUrl = page.pageUrl
}
}
}
return `[${linked.name}](${pageUrl}#${anchorName.call(linked)})`
}

function resolveById(id) {
for (const page of exports.pages) {
const member = page.dataMap.get(id)
if (member != null) {
return member
}
}
return null
}

function isExternal() {
return this.kind === "external"
}

function anchorName() {
if (!this.id) {
throw new Error(`[anchorName helper] cannot create a link without a id: ${JSON.stringify(this)}`)
}

if (this.inherited) {
const inherits = resolveById(this.inherits)
return inherits ? anchorName.call(inherits) : ""
}

if (this.kind === "class" || this.kind === "interface" || this.kind === "enum") {
return this.name
}

let result = this.isExported ? "exp_" : ""
if (this.kind === "constructor") {
result += "new_"
}
result +=
this.id
.replace(/:/g, "_")
.replace(/~/g, "..")
.replace(/\(\)/g, "_new")
.replace(/#/g, "+")
return result
}

function _identifier(options) {
return _identifiers(options)[0]
}

function _identifiers (options) {
return dmdHelpers._identifiers(options)
}

function parseLink(text) {
return dmdHelpers.parseLink(text)
}
1 change: 1 addition & 0 deletions jsdoc/linked-type-list.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{{listTypes types delimiter @root}}}
2 changes: 1 addition & 1 deletion jsdoc/properties-table.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{{#tableRow properties "name" "type" "defaultvalue" "description" ~}}
| {{#if @col1}}{{#unless optional}}**{{/unless~}}{{name}}{{#unless optional}}**{{/unless~}}{{#if defaultvalue}} = {{>defaultvalue}}{{/if~}} | {{/if~}}
{{#if @col2}}{{>linked-type-list types=type.names delimiter=" &#124; " }} | {{/if~}}
{{#if @col2}}{{>linked-type-list types=type.names delimiter=" \| " }} | {{/if~}}
{{#if @col4}}{{{propertyAnchor name ../../name }}}{{{stripNewlines (inlineLinks description)}}} |{{/if}}
{{/tableRow}}

Expand Down
3 changes: 0 additions & 3 deletions jsdoc/property-link.js

This file was deleted.

16 changes: 16 additions & 0 deletions jsdoc/sig-name.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{!-- do not add parent for class --}}
{{#if virtual}}*{{/if}}{{#with (parentObject)}}{{#if virtual}}*{{/if~}}{{/with~}}
{{#if name}}{{#sig~}}
{{{@depOpen}~}}
{{{@codeOpen}~}}
{{#if @prefix}}{{@prefix}} {{/if~}}
{{#unless (equal kind "class")}}{{#unless (equal kind "interface")}}{{@parent~}}{{@accessSymbol}}{{/unless~}}{{/unless~}}
{{#if (isEvent)}}"{{{name}}}"{{else}}{{{name}}}{{/if~}}
{{#if @methodSign}}{{#if (isEvent)}} {{@methodSign}}{{else}}{{@methodSign}}{{/if}}{{/if~}}
{{{@codeClose}~}}
{{#if @returnSymbol}} {{@returnSymbol}}{{/if~}}
{{#if @returnTypes}} {{>linked-type-list types=@returnTypes delimiter=" &#124; " }}{{/if~}}
{{#if @suffix}} {{@suffix}}{{/if~}}
{{{@depClose}~}}
{{~/sig}}{{/if~}}
{{#if virtual}}*{{/if}}{{#with (parentObject)}}{{#if virtual}}*{{/if~}}{{/with~}}
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test-all": "node ./test/vendor/yarn.js pretest && node ./test/out/helpers/runTests.js",
"test-linux": "docker run --rm -ti -v ${PWD}: /project -v ${PWD##*/}-node-modules:/project/node_modules -v ~/.electron:/root/.electron electronuserland/electron-builder:wine /bin/bash -c \"node ./test/vendor/yarn.js && node ./test/vendor/yarn.js test\"",
"//": "Update wiki if docs changed. Update only if functionalily are generally available (latest release, not next)",
"update-wiki": "git subtree split -b wiki --prefix docs/ && git push -f wiki wiki:master",
"update-wiki": "(git branch -D wiki || true) && git subtree split -b wiki --prefix docs/ && git push -f wiki wiki:master",
"whitespace": "whitespace 'src/**/*.ts'",
"docker-images": "docker/build.sh",
"test-deps-mac": "brew install rpm dpkg mono lzip gnu-tar graphicsmagick xz && brew install wine --without-x11",
Expand All @@ -28,15 +28,15 @@
"///": "all dependencies for all packages (hoisted)",
"dependencies": {
"7zip-bin": "^2.0.4",
"ajv": "^5.0.3-beta.0",
"ajv": "^5.0.4-beta.0",
"ajv-keywords": "^2.0.1-beta.1",
"archiver": "^1.3.0",
"aws-sdk": "^2.27.0",
"aws-sdk": "^2.28.0",
"bluebird-lst": "^1.0.1",
"chalk": "^1.1.3",
"chromium-pickle-js": "^0.2.0",
"cuint": "^0.2.2",
"debug": "^2.6.2",
"debug": "^2.6.3",
"electron-download-tf": "4.0.0",
"electron-macos-sign": "~1.6.0",
"fs-extra-p": "^4.0.2",
Expand All @@ -56,7 +56,7 @@
"sanitize-filename": "^1.6.1",
"semver": "^5.3.0",
"stat-mode": "^0.2.2",
"ts-jsdoc": "^1.0.6",
"ts-jsdoc": "^1.0.7",
"tunnel-agent": "^0.6.0",
"update-notifier": "^2.1.0",
"uuid-1345": "^0.99.6",
Expand All @@ -65,7 +65,7 @@
"devDependencies": {
"@types/electron": "^1.4.33",
"@types/ini": "^1.3.29",
"@types/jest": "^19.2.1",
"@types/jest": "^19.2.2",
"@types/js-yaml": "^3.5.29",
"@types/node-forge": "^0.6.7",
"@types/source-map-support": "^0.2.28",
Expand All @@ -76,6 +76,7 @@
"babel-plugin-transform-es2015-parameters": "^6.23.0",
"babel-plugin-transform-es2015-spread": "^6.22.0",
"babel-plugin-transform-inline-imports-commonjs": "^1.2.0",
"catharsis": "^0.8.8",
"convert-source-map": "^1.4.0",
"decompress-zip": "^0.3.0",
"depcheck": "^0.6.7",
Expand All @@ -86,7 +87,7 @@
"jest-junit": "^1.3.0",
"jsdoc-to-markdown": "^3.0.0",
"path-sort": "^0.1.0",
"source-map-support": "^0.4.11",
"source-map-support": "^0.4.12",
"ts-babel": "^2.0.0",
"tslint": "^4.5.1",
"typescript": "^2.2.1",
Expand Down
Loading

0 comments on commit 912fd0d

Please sign in to comment.