added {sig:kind->prop} macro to render function signatures

This commit is contained in:
Peli de Halleux 2015-07-15 08:07:04 -07:00
Родитель b210dd24b2
Коммит d7c65e2dea
6 изменённых файлов: 59 добавлений и 11 удалений

Просмотреть файл

@ -1308,6 +1308,10 @@ module TDev {
getArrow():string;
showIntelliButton():boolean;
}
export interface IPropertyWithNamespaces extends IProperty {
getNamespaces(): string[];
}
export interface IPropertyWithCache
extends IProperty

Просмотреть файл

@ -1685,7 +1685,7 @@ module TDev.AST {
export class Action
extends PropertyDecl
implements IProperty
implements IPropertyWithNamespaces
{
constructor() {
super()

Просмотреть файл

@ -718,6 +718,33 @@ module TDev {
if (track) return track;
return tracks[0];
}
private sig(arg: string) {
var m = arg.split(/->/);
var property: IProperty = undefined;
if (m) {
// find type / property
var kindName = m[0];
var propertyName = m[1];
if (kindName && propertyName) {
if (Script) {
var lib = Script.librariesAndThis().filter(lib => lib.getName() == kindName)[0];
if (lib) {
var action = lib.getPublicActions().filter(action => action.getName() == propertyName)[0];
if (action) {
// bingo!
var r = "<div class=notranslate translate=no dir=ltr><div class='md-snippet'>";
r += this.renderer.renderPropertySig(action, false, true);
r += "</div></div>";
return r;
}
}
}
}
}
return lf("could not find decl '{0}'", m);
}
private apiList(arg:string)
{
@ -826,12 +853,12 @@ module TDev {
if (!Script) return MdComments.error(lf("import can only be used from a script context"));
var r = "";
[
{name:'npm', url:'https://www.npmjs.com/package/{0:q}', pkgs:Script.imports.npmModules},
{name:'cordova', url:'http://plugins.cordova.io/#/package/{0:q}/', pkgs:Script.imports.cordovaPlugins},
{name: 'bower', url: 'https://www.npmjs.com/package/{0:q}/', pkgs: Script.imports.bowerModules },
{name:'client', url: '{0}', pkgs: Script.imports.clientScripts },
{name:'pip', url:'https://pypi.python.org/pypi/{0:q}/', pkgs:Script.imports.pipPackages},
{name:'touchdevelop', url:'#pub:{0:q}', pkgs:Script.imports.touchDevelopPlugins}
{ name: 'npm', url: 'https://www.npmjs.com/package/{0:q}', pkgs: Script.imports.npmModules },
{ name: 'cordova', url: 'http://plugins.cordova.io/#/package/{0:q}/', pkgs: Script.imports.cordovaPlugins },
{ name: 'bower', url: 'https://www.npmjs.com/package/{0:q}/', pkgs: Script.imports.bowerModules },
{ name: 'client', url: '{0}', pkgs: Script.imports.clientScripts },
{ name: 'pip', url: 'https://pypi.python.org/pypi/{0:q}/', pkgs: Script.imports.pipPackages },
{ name: 'touchdevelop', url: '#pub:{0:q}', pkgs: Script.imports.touchDevelopPlugins }
].forEach(imports => {
var keys = Object.keys(imports.pkgs);
if (keys.length > 0) {
@ -899,6 +926,8 @@ module TDev {
else return "";
} else if (macro == "api") {
return this.apiList(arg);
} else if (macro == "sig") {
return this.sig(arg);
} else if (macro == "youtube") {
if (!this.allowVideos) return "";
if (this.blockExternal()) return this.blockLink("")

Просмотреть файл

@ -74,6 +74,7 @@ module TDev
public kw0(k:string) { return Renderer.tspan("kw", k); }
public greyKw(k:string) { return Renderer.tspan("greyed", " " + k + " "); }
public id(kw:string) { return Util.htmlEscape(kw); }
public name(name: string) { return Renderer.tspan("name", Util.htmlEscape(name));}
public kind(k:Kind) { return Util.htmlEscape(k.toString()); }
public op(kw:string) { return Util.htmlEscape(Renderer.spacedText(kw)); }
public st(kw:string) { return Renderer.tspan("st", kw); }
@ -1045,11 +1046,15 @@ module TDev
if (withKind) {
if (prop.parentKind.singleton)
hd += topicLink(prop.parentKind.singleton.getName())
else
hd += "(" + kindLink(prop.parentKind) + ")";
else {
var ns: string = (<IPropertyWithNamespaces>prop).getNamespaces ? (<IPropertyWithNamespaces>prop).getNamespaces()[0] : undefined;
this.id
if (ns) hd += this.name(ns);
else hd += "(" + kindLink(prop.parentKind) + ")";
}
hd += "\u200A\u2192\u00A0";
}
hd += this.id(prop.getName())
hd += this.name(prop.getName())
var parms = prop.getParameters().slice(1).map((p) =>
(withLinks ? "<br/>" : "") +
@ -1085,6 +1090,8 @@ module TDev
".greyed { color:#444; }\n" +
".api-kind { border: 1px dotted #BBB; padding: 0.4em; clear: both; font-size: 1.2em; margin-bottom: 0.6em; }\n" +
".md-snippet { border: 1px dotted #bbb; padding: 0.4em 0; clear: both; line-height: 1.3em; page-break-inside:avoid; }\n" +
".md-snippet .signature { padding:0em 0.2em 0em 0.2em; }\n" +
".md-snippet .name { font-weight: bold;}\n" +
".md-img { margin:0.5em; clear:both; width:100%; text-align:center; position:relative; }\n" +
".md-img-inner { position:relative; display:inline-block; width:100%; }\n" +
".md-img .caption { font-size:0.8em; }\n" +

Просмотреть файл

@ -1983,7 +1983,7 @@ module TDev
toks.pushRange(this.findDefault(parms[0]));
} else if (p.parentKind instanceof AST.LibraryRefKind) {
var ns: string;
if ((<any>p).getNamespaces && (ns = (<any>p).getNamespaces()[0])) {
if ((<IPropertyWithNamespaces>p).getNamespaces && (ns = (<IPropertyWithNamespaces>p).getNamespaces()[0])) {
toks.push(AST.mkThing(ns));
} else {
toks.push(AST.mkThing(AST.libSymbol))

Просмотреть файл

@ -5031,6 +5031,14 @@ h1.stepid > span {
clear:both;
}
.md-snippet .signature {
padding:0em 0.2em 0em 0.2em;
}
.md-snippet .name {
font-weight: bold;
}
.md-snippet .code-button,
.md-snippet .wall-button {
position: absolute;