Skip to content

Commit 72ace0e

Browse files
committed
【API】 jsdoc优化引入外部类型
1 parent 24a21ca commit 72ace0e

File tree

9 files changed

+39
-13
lines changed

9 files changed

+39
-13
lines changed

build/jsdocs/leaflet/categories.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

build/jsdocs/mapboxgl/categories.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

build/jsdocs/openlayers/categories.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

build/jsdocs/plugins/linkdoc.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
var logger = require('jsdoc/util/logger');
44
var env = require('jsdoc/env');
5+
var typeLinks = require('../template/typeLinkExt').typeLinks;
56
exports.handlers = {
67
newDoclet: function (e) {
78
if (e.doclet.augments) {
@@ -23,14 +24,24 @@ exports.handlers = {
2324
if (e.doclet.params) {
2425
for (var i = 0; i < e.doclet.params.length; i++) {
2526
var a = e.doclet.params[i].description;
26-
if (a && a.indexOf("@linkdoc")) {
27+
if (a && a.indexOf("@linkdoc") > -1) {
2728
var reg = new RegExp("@(linkdoc.*?)/");
2829
var match = a.match(reg);
2930
if (match) {
30-
var str="@" + match[1] + "/";
31-
e.doclet.params[i].description = a.replace(new RegExp(str,'g'), "@link "+ env.conf.tags[match[1]]);
31+
var str = "@" + match[1] + "/";
32+
e.doclet.params[i].description = a.replace(new RegExp(str, 'g'), "@link " + env.conf.tags[match[1]]);
33+
}
34+
} else if (a && a.indexOf("@link") > -1) {
35+
var patt = /{@link (\S*)}/g;
36+
var result;
37+
while ((result = patt.exec(a)) != null) {
38+
var link = result[1];
39+
if (link && typeLinks[link]) {
40+
e.doclet.params[i].description = e.doclet.params[i].description.replace(result[0], "[" + link + "]{@link " + typeLinks[result[1]] + "}");
41+
}
3242
}
3343
}
44+
3445
}
3546
}
3647
}

build/jsdocs/template/publish.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ var template = require('jsdoc/template'),
77
handle = require('jsdoc/util/error').handle,
88
helper = require('jsdoc/util/templateHelper'),
99
logger = require('jsdoc/util/logger'),
10-
10+
typeLinks= require('./typeLinkExt').typeLinks,
11+
1112
_ = require('underscore'),
1213
htmlsafe = helper.htmlsafe,
1314
linkto = helper.linkto,
@@ -365,7 +366,7 @@ exports.publish = function (taffyData, opts, tutorials) {
365366

366367
var globalUrl = helper.getUniqueFilename('global');
367368
helper.registerLink('global', globalUrl);
368-
369+
view.typeLinks=typeLinks;
369370
// set up templating
370371
view.layout = 'layout.tmpl';
371372

build/jsdocs/template/tmpl/container.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@
5050

5151
<?js if (doc.augments && doc.augments.length) { ?>
5252
<h3 class="subsection-title">Extends</h3>
53-
5453
<ul><?js doc.augments.forEach(function(a) { ?>
5554
<?js if (a) { ?>
5655
<?js array=a.split('{'); ?>
5756
<?js if (array.length == 1) { ?>
58-
<li><?js= self.linkto(a, a) ?></li>
57+
<?js var url=self.typeLinks[a]||a; ?>
58+
<li><?js= self.linkto(url, a) ?></li>
5959
<?js }else{ ?>
6060
<li><?js= self.linkto(array[1].substring(0,array[1].length-1),array[0]) ?></li>
6161
<?js } ?>

build/jsdocs/template/tmpl/type.tmpl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
var data = obj;
33
var self = this;
44
data.forEach(function(name, i) { ?>
5-
<span class="param-type"><?js= self.linkto(name, self.htmlsafe(name)) ?></span>
5+
<span class="param-type"><?js=
6+
function(){
7+
if(name&&self.typeLinks&&self.typeLinks[name]){
8+
return self.linkto(self.typeLinks[name],name);
9+
} else{
10+
return self.linkto(name, self.htmlsafe(name))
11+
}
12+
}()
13+
?></span>
614
<?js if (i < data.length-1) { ?>|<?js } ?>
715
<?js }); ?>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var olapi = "https://openlayers.org/en/latest/apidoc/";
2+
var typeLinks = {
3+
"ol.Map": olapi + "ol.Map.html",
4+
"ol.View": olapi + "ol.View.html"
5+
}
6+
exports.typeLinks = typeLinks;

src/openlayers/overlay/vectortile/MapboxStyles.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import {
1919
* @param {Object} options 初始化参数。<br>
2020
* @param {string | undefined} options.url - iServer UGCV5(MVT) 地图服务地址,例如 `http://localhost:8090/iserver/services/map-mvt-test/rest/maps/test` , 与 `options.style` 互斥,优先级低于 `options.style`。
2121
* @param {Object | undefined} options.style - Mapbox style 对象。 与 `options.url` 互斥,优先级高于 `options.url`。
22-
* @param {Array.<number>} options.resolutions - 地图分辨率数组,用于映射zoom值。通常情況与地图的 [ol.View]{@linkdoc-openlayers/ol.View} 的分辨率一致。</br>
22+
* @param {Array.<number>} options.resolutions - 地图分辨率数组,用于映射zoom值。通常情況与地图的 {@link ol.View} 的分辨率一致。</br>
2323
* 默认值为`[78271.51696402048,39135.75848201024, 19567.87924100512,9783.93962050256,4891.96981025128,2445.98490512564, 1222.99245256282,611.49622628141,305.748113140705,152.8740565703525, 76.43702828517625,38.21851414258813,19.109257071294063,9.554628535647032, 4.777314267823516,2.388657133911758,1.194328566955879,0.5971642834779395, 0.29858214173896974,0.14929107086948487,0.07464553543474244]`。
2424
* @param {!(string|Array.<string>)} options.source - Mapbox Style `source` key值或者 `layer`的 id 数组。
2525
* 当配置`source` key值时,source为该值的layer会被加载;
2626
* 当配置为`layer`的 id 数组时,指定的layer会被加载,注意被指定的layer需要有相同的source。
27-
* @param {ol.Map} options.map - {ol.supermap.VectorTileStyles}Openlayers 地图对象,仅用于填充Mapbox Style中的 `background`,如没有配置`background`可不设置该参数。
27+
* @param {ol.Map} options.map - Openlayers 地图对象,仅用于填充Mapbox Style中的 `background`,如没有配置`background`可不设置该参数。
2828
* @example
2929
* var mbStyle = new ol.supermap.MapboxStyles({
3030
url: url,

0 commit comments

Comments
 (0)