Skip to content
This repository has been archived by the owner on Aug 14, 2021. It is now read-only.

support export declarations #57

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ module.exports = function(grunt)
themeDefault: {
tsconfig: './tsconfig.json',
options: {
// Required because of https://github.com/TypeStrong/grunt-ts/issues/432
// Required because of https://github.com/TypeStrong/grunt-ts/issues/432
// Wouldn't be needed if lunr fixed https://github.com/olivernn/lunr.js/issues/324
additionalFlags: '--alwaysStrict false'
}
},
themeDefaultHelpers: {
tsconfig: 'src/default/helpers/tsconfig.json'
}
},
uglify: {
Expand Down Expand Up @@ -106,6 +109,11 @@ module.exports = function(grunt)
cwd: 'src/default/partials',
src: ['**/*.hbs'],
dest: 'bin/minimal/partials'
}, {
expand: true,
cwd: 'bin/default/helpers',
src: ['**/*.js'],
dest: 'bin/minimal/helpers',
}]
},
themeMinimal: {
Expand Down Expand Up @@ -151,6 +159,6 @@ module.exports = function(grunt)
grunt.loadNpmTasks('grunt-ts');

grunt.registerTask('css', ['sass', 'autoprefixer']);
grunt.registerTask('js', ['ts:themeDefault', 'uglify']);
grunt.registerTask('default', ['copy', 'css', 'js', 'string-replace']);
grunt.registerTask('js', ['ts:themeDefault', 'uglify', 'ts:themeDefaultHelpers']);
grunt.registerTask('default', ['copy', 'css', 'js', 'copy:themeDefault2Minimal', 'string-replace']);
};
13 changes: 13 additions & 0 deletions src/default/helpers/get-reflection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Get a reflection object form a reflection id.
*
* @returns The filtered array.
*/
export function getReflection(id: number, options: any): any {
const refl = options.data.root.project.reflections[id];
if (!refl) {
throw new Error(`cannot find reflection with id ${id}`);
}

return refl;
}
66 changes: 66 additions & 0 deletions src/default/helpers/relevant-flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// The order of the flags in this list is important. It determines the
// order in which the theme processes the flags. It should reflect the
// order in which the keywords can appear in the TS source.
//
// Some combinations are impossible. In such case, the relative order
// of such impossible combinations does not matter. (e.g. a symbol
// cannot be both private and protected, or abstract and static.)
const relevantFlagList = [
"Private",
"Protected",
"Abstract",
"Static",
"ExportAssignment",
"Optional",
"DefaultValue",
"Rest",
"Let",
"Const",
];

const relevantFlagListWithExport =
["Export"].concat(relevantFlagList);

/**
* Filter the flag names that are set on a reflection to only those
* names relevant to this theme.
*
* Templates that iterate over the flags of reflections should
* **always** use this helper to filter the flags, because what flags
* are relevant varies depending on the settings used when rendering
* with the theme and on the reflection being examined.
*
* @returns The filtered array.
*/
export function relevantFlags(this: any, options: any): string[] {

// When excludeNotExported is set, we don't want to produce labels
// for "Exported" because everything is exported and thus the
// labels are pointless.
const list = options.data.root.settings.excludeNotExported ?
relevantFlagList :
relevantFlagListWithExport;

// We filter the list of relevant flags so that the flags are
// produce in the order set by that list instead of the order the
// flags happen to be set on the reflection.
const flags = this.flags;
return list.filter((x) => flags.indexOf(x) !== -1);
}

/**
* Checks whether a relevant flag is set. If the flag is deemed
* irrelevant, then the flag is considered to be unset.
*
* It is generally better to use this helper than accessing flags
* directly, because some flags may be set and yet be irrelevant due
* to the settings used when rendering with the theme.
*
* @param name The name of the flag to check.
*
* @returns Whether the flag is set.
*/
export function hasRelevantFlag(this: any, name: string,
options: any): boolean {
return relevantFlags.call(this, options).indexOf(name) !== -1;
}
12 changes: 12 additions & 0 deletions src/default/helpers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../../tsconfig-common",
"compilerOptions": {
"sourceMap": false,
"module": "commonjs",
"declaration": false,
"outDir": "../../../bin/default/helpers"
},
"include": [
"*.ts"
]
}
1 change: 1 addition & 0 deletions src/default/partials/flag.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<span class="tsd-flag ts-flag{{#if useForClass}}{{useForClass}}{{else}}{{this}}{{/if}}">{{#if useForName}}{{useForName}}{{else}}{{this}}{{/if}}</span>
25 changes: 14 additions & 11 deletions src/default/partials/header.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,20 @@
{{#with model}}{{> breadcrumb}}{{/with}}
</ul>
<h1>{{#compact}}
{{model.kindString}}&nbsp;
{{model.name}}
{{#if model.typeParameters}}
&lt;
{{#each model.typeParameters}}
{{#if @index}},&nbsp;{{/if}}
{{name}}
{{/each}}
&gt;
{{/if}}
{{#with model}}
{{#if (hasRelevantFlag "Export")}}{{> flag useForClass="Export" useForName="Export"}}&nbsp;{{/if}}
{{kindString}}&nbsp;
{{name}}
{{#if typeParameters}}
&lt;
{{#each typeParameters}}
{{#if @index}},&nbsp;{{/if}}
{{name}}
{{/each}}
&gt;
{{/if}}
{{/with}}
{{/compact}}</h1>
</div>
</div>
</header>
</header>
12 changes: 8 additions & 4 deletions src/default/partials/index.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{{#if groups}}
<section class="tsd-panel-group tsd-index-group">
<h2>Index</h2>
{{#if settings.excludeNotExported}}
<h2>Index of Exported Symbols</h2>
{{else}}
<h2>Index</h2>
{{/if}}
<section class="tsd-panel tsd-index-panel">
<div class="tsd-index-content">
{{#each groups}}
Expand All @@ -10,15 +14,15 @@
<h3>{{#if title}}{{title}} {{/if}}{{../title}}</h3>
<ul class="tsd-index-list">
{{#each children}}
<li class="{{cssClasses}}"><a href="{{relativeURL url}}" class="tsd-kind-icon">{{#if name}}{{{wbr name}}}{{else}}<em>{{{wbr kindString}}}</em>{{/if}}</a></li>
<li class="{{cssClasses}}"><a href="{{relativeURL url}}" class="tsd-kind-icon">{{#if (hasRelevantFlag "Export")}}{{> flag useForClass="Export" useForName="x"}}&nbsp;{{/if}}{{#if name}}{{{wbr name}}}{{else}}<em>{{{wbr kindString}}}</em>{{/if}}</a></li>
{{/each}}
</ul>
{{/each}}
{{else}}
<h3>{{title}}</h3>
<ul class="tsd-index-list">
{{#each children}}
<li class="{{cssClasses}}"><a href="{{relativeURL url}}" class="tsd-kind-icon">{{#if name}}{{{wbr name}}}{{else}}<em>{{{wbr kindString}}}</em>{{/if}}</a></li>
<li class="{{cssClasses}}"><a href="{{relativeURL url}}" class="tsd-kind-icon">{{#if (hasRelevantFlag "Export")}}{{> flag useForClass="Export" useForName="x"}}&nbsp;{{/if}}{{#if name}}{{{wbr name}}}{{else}}<em>{{{wbr kindString}}}</em>{{/if}}</a></li>
{{/each}}
</ul>
{{/if}}
Expand All @@ -27,4 +31,4 @@
</div>
</section>
</section>
{{/if}}
{{/if}}
14 changes: 7 additions & 7 deletions src/default/partials/member.hbs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<section class="tsd-panel tsd-member {{cssClasses}}">
<a name="{{anchor}}" class="tsd-anchor"></a>
{{#if name}}
<h3>{{#each flags}}<span class="tsd-flag ts-flag{{this}}">{{this}}</span> {{/each}}{{{wbr name}}}</h3>
{{/if}}

<a name="{{anchor}}" class="tsd-anchor"></a>
<h3>{{#compact}}{{#each (relevantFlags)}}{{> flag}}&nbsp;{{/each}}{{/compact}}{{{wbr name}}}</h3>
{{#if renames}}
Renames {{#with (getReflection renames)}}<a href="{{relativeURL url}}">{{{wbr name}}}</a>{{/with}}
{{else}}
{{#if signatures}}
{{> member.signatures}}
{{else}}{{#if hasGetterOrSetter}}
{{> member.getterSetter}}
{{else}}
{{> member.declaration}}
{{/if}}{{/if}}

{{#each groups}}
{{#each groups}}
{{#each children}}
{{#unless hasOwnDocument}}
{{> member}}
{{/unless}}
{{/each}}
{{/each}}
{{/if}}
</section>
6 changes: 2 additions & 4 deletions src/default/partials/member.signature.body.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
{{#each parameters}}
<li>
<h5>{{#compact}}
{{#each flags}}
<span class="tsd-flag ts-flag{{this}}">{{this}}</span>&nbsp;
{{/each}}
{{#each (relevantFlags)}}{{> flag}}&nbsp;{{/each}}
{{#if flags.isRest}}<span class="tsd-signature-symbol">...</span>{{/if}}
{{name}}:&nbsp;
{{#with type}}{{>type}}{{/with}}
Expand Down Expand Up @@ -53,4 +51,4 @@
{{> parameter}}
{{/with}}
{{/if}}
{{/if}}
{{/if}}
4 changes: 1 addition & 3 deletions src/default/partials/parameter.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
{{> member.signatures}}
{{else}}
<h5>{{#compact}}
{{#each flags}}
<span class="tsd-flag ts-flag{{this}}">{{this}}</span>&nbsp;
{{/each}}
{{#each (relevantFlags)}}{{> flag}}&nbsp;{{/each}}
{{#if flags.isRest}}<span class="tsd-signature-symbol">...</span>{{/if}}
{{{wbr name}}}
<span class="tsd-signature-symbol">
Expand Down
Loading