Skip to content

Commit

Permalink
generalize docs data (#63)
Browse files Browse the repository at this point in the history
* restore props tables!
ensure docs tasks run after sources are compiled

* generalize releases and versions
they both accept an `IPackageInfo`, which now includes `url` field.
resolve the URLs at require time (means we can use regular links
for documentation versions).

* add resolveInterface prop
functions similarly to the other `resolve*` props.
we provide a `PropsStore` class that can intelligently resolve props
including inheritance.
this is necessary because the previous impl used a relative path
that does not exist in internal repo.
  • Loading branch information
giladgray authored Nov 10, 2016
1 parent cb0ef62 commit 8984b08
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 48 deletions.
4 changes: 2 additions & 2 deletions gulp/aliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ module.exports = (gulp) =>{
gulp.task("docs", ["docs-interfaces", "docs-kss", "docs-versions", "docs-releases"]);

// perform a full build of the code and then finish
gulp.task("build", (done) => rs("clean", ["compile", "docs"], "webpack-compile-docs", done));
gulp.task("build", (done) => rs("clean", "compile", "docs", "webpack-compile-docs", done));

// build code, run unit tests, terminate
// NOTE: `npm test` runs each of these tasks separately to free up memory between them
gulp.task("test", (done) => rs("karma", "test-typescript-2.0", done));

// compile code and start watching for development
gulp.task("default", (done) => rs("clean", ["compile", "docs"], "watch", done));
gulp.task("default", (done) => rs("clean", "compile", "docs", "watch", done));
};
29 changes: 0 additions & 29 deletions packages/docs/src/common/props.tsx

This file was deleted.

30 changes: 30 additions & 0 deletions packages/docs/src/common/propsStore.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { IInterfaceEntry, IPropertyEntry } from "ts-quick-docs/src/interfaces";

export class PropsStore {
constructor(private props: IInterfaceEntry[]) {}

public getProps = (name: string): IPropertyEntry[] => {
const entry = this.props.filter((props) => props.name === name)[0];
if (entry == null) {
return [];
} else if (entry.extends == null) {
return entry.properties;
} else {
// dirty deduplication for overridden/inherited props
const props: {[name: string]: IPropertyEntry} = {};
entry.extends.map(this.getInheritedProps).forEach((inherited) => {
inherited.forEach((prop) => props[prop.name] = prop);
});
entry.properties.forEach((prop) => props[prop.name] = prop);
// return a sorted array of unique props
return Object.keys(props).sort().map((n) => props[n]);
}
}

private getInheritedProps = (name: string) => {
return this.getProps(name).map((p) => {
p.inheritedFrom = name;
return p;
});
}
}
16 changes: 5 additions & 11 deletions packages/docs/src/components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ export interface INavbarProps {
useDarkTheme: boolean;
}

/* tslint:disable-next-line:max-line-length */
const NPM_URL_BASE = "https://www.npmjs.com/package";

@PureRender
@HotkeysTarget
export class Navbar extends React.Component<INavbarProps, {}> {
Expand Down Expand Up @@ -79,7 +76,7 @@ export class Navbar extends React.Component<INavbarProps, {}> {
private renderReleasesMenu() {
const menuItems = this.props.releases.map((version: IPackageInfo, index: number) => (
<MenuItem
href={`${NPM_URL_BASE}/${version.name}`}
href={version.url}
key={index}
label={version.version}
target="_blank"
Expand All @@ -105,16 +102,12 @@ export class Navbar extends React.Component<INavbarProps, {}> {
}
}

function handleVersionChange(release: string) {
return () => location.href = `https://palantir.github.io/blueprint/${release}`;
}

export const NavbarLeft: React.SFC<{ versions: string[] }> = ({ versions }) => {
export const NavbarLeft: React.SFC<{ versions: IPackageInfo[] }> = ({ versions }) => {
const match = /releases\/([^\/]+)\/build/.exec(location.href);
// default to latest release if we can't find a tag in the URL
const currentRelease = (match == null ? versions[0] : match[1]);
const currentRelease = (match == null ? versions[0].version : match[1]);
const releaseItems = versions.map((rel, i) => (
<MenuItem key={i} onClick={handleVersionChange(rel)} text={rel} />
<MenuItem key={i} href={rel.url} text={rel.version} />
));
const menu = <Menu className="docs-version-list">{releaseItems}</Menu>;

Expand All @@ -130,3 +123,4 @@ export const NavbarLeft: React.SFC<{ versions: string[] }> = ({ versions }) => {
</div>
);
};
NavbarLeft.displayName = "Docs.NavbarLeft";
4 changes: 2 additions & 2 deletions packages/docs/src/components/section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import * as PureRender from "pure-render-decorator";
import * as React from "react";
import { IPropertyEntry } from "ts-quick-docs/src/interfaces";

import { getProps } from "../common/props";
import { ExampleComponentClass } from "../common/resolveExample";
import { getTheme } from "../common/theme";
import { ModifierTable } from "./modifierTable";
Expand Down Expand Up @@ -59,6 +58,7 @@ export class Section extends React.Component<ISectionProps, {}> {
key={s.reference}
resolveDocs={this.props.resolveDocs}
resolveExample={this.props.resolveExample}
resolveInterface={this.props.resolveInterface}
section={s}
/>
));
Expand Down Expand Up @@ -89,7 +89,7 @@ export class Section extends React.Component<ISectionProps, {}> {

public componentWillMount() {
// compute this once since it'll never change and is potentially expensive with inheritance
this.interfaceProps = getProps(this.props.section.interfaceName);
this.interfaceProps = this.props.resolveInterface(this.props.section.interfaceName);
}

private maybeRenderModifiers() {
Expand Down
14 changes: 12 additions & 2 deletions packages/docs/src/components/styleguide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as classNames from "classnames";
import * as PureRender from "pure-render-decorator";
import * as React from "react";
import { IPropertyEntry } from "ts-quick-docs/src/interfaces";

import { Hotkey, Hotkeys, HotkeysTarget, IHotkeysDialogProps, setHotkeysDialogProps } from "@blueprintjs/core";

Expand All @@ -16,6 +17,9 @@ import { Navigator } from "./navigator";
import { NavMenu } from "./navMenu";
import { Section } from "./section";

// these interfaces are essential to the docs app, so it's helpful to re-export here
export { IInterfaceEntry, IPropertyEntry } from "ts-quick-docs/src/interfaces";

const DARK_THEME = "pt-dark";
const LIGHT_THEME = "";

Expand Down Expand Up @@ -45,7 +49,9 @@ export interface IStyleguideSection {
}

export interface IPackageInfo {
name: string;
/** Name of package. Ignored for documentation site versions. */
name?: string;
url: string;
version: string;
}

Expand All @@ -55,6 +61,9 @@ export interface IStyleguideExtensionProps {

/** Given a section, returns the example component that should be rendered for it. */
resolveExample(section: IStyleguideSection): IResolvedExample;

/** Given an interface name, returns an array of properties defined on the interface. */
resolveInterface(name: string): IPropertyEntry[];
}

export interface IStyleguideProps extends IStyleguideExtensionProps {
Expand All @@ -68,7 +77,7 @@ export interface IStyleguideProps extends IStyleguideExtensionProps {
pages: IStyleguideSection[];

/** Release versions for published documentation. */
versions: string[];
versions: IPackageInfo[];

/** Latest release versions for published projects. */
releases: IPackageInfo[];
Expand Down Expand Up @@ -140,6 +149,7 @@ export class Styleguide extends React.Component<IStyleguideProps, IStyleguideSta
<Section
resolveDocs={this.props.resolveDocs}
resolveExample={this.props.resolveExample}
resolveInterface={this.props.resolveInterface}
section={activePage}
/>
</article>
Expand Down
17 changes: 15 additions & 2 deletions packages/docs/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@ import "dom4";
import { FocusStyleManager } from "@blueprintjs/core";
import * as React from "react";
import * as ReactDOM from "react-dom";
import { IInterfaceEntry } from "ts-quick-docs/src/interfaces";

import { PropsStore } from "./common/propsStore";
import { resolveDocs } from "./common/resolveDocs";
import { resolveExample } from "./common/resolveExample";
import { IPackageInfo, IStyleguideSection, Styleguide } from "./components/styleguide";

/* tslint:disable:no-var-requires */
const pages = require<IStyleguideSection[]>("./generated/docs.json");
const releases = require<IPackageInfo[]>("./generated/releases.json");
const versions = require<string[]>("./generated/versions.json").reverse();
const releases = require<IPackageInfo[]>("./generated/releases.json")
.map((pkg) => {
pkg.url = `https://www.npmjs.com/package/${pkg.name}`;
return pkg;
});
const versions = require<string[]>("./generated/versions.json").reverse()
.map((version) => ({
url: `https://palantir.github.io/blueprint/docs/${version}`,
version,
} as IPackageInfo));

const propsStore = new PropsStore(require<IInterfaceEntry[]>("./generated/props.json"));
/* tslint:enable:no-var-requires */

// This function is called whenever the documentation page changes and should be used to
Expand All @@ -34,6 +46,7 @@ ReactDOM.render(
<Styleguide
resolveDocs={({ reactDocs }) => resolveDocs(reactDocs)}
resolveExample={({ reactExample }) => resolveExample(reactExample)}
resolveInterface={propsStore.getProps}
pages={pages}
onUpdate={updateExamples}
releases={releases}
Expand Down

1 comment on commit 8984b08

@blueprint-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generalize docs data (#63)

Preview: docs Coverage: core | datetime

Please sign in to comment.