From c008dd1f2cad05ade1c10ea567a4d322f14b92f3 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 16 May 2018 18:18:44 -0500 Subject: [PATCH] Starting point for docs --- package.json | 3 +- site/.eslintrc | 1 + site/src/layouts/index.js | 1 + site/src/pages/docs.js | 67 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 site/src/pages/docs.js diff --git a/package.json b/package.json index 1f59b087a3..ccfc0977b5 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "serve-examples": "mkdir -p build/examples && webpack --config examples/webpack/config.js --mode development --watch & serve build/examples", "build-examples": "webpack --config examples/webpack/config.js --mode production", "build-index": "node tasks/generate-index", - "build-site": "cd site && npm install && npm run build", + "build-site": "node tasks/generate-info.js && cd site && npm install && npm run build", "prebuild": "npm run build-index", "build": "rollup --config config/rollup.js", "presrc-closure": "npm run prebuild", @@ -40,6 +40,7 @@ "css/ol.css" ], "dependencies": { + "babel-eslint": "^8.2.3", "pbf": "3.1.0", "pixelworks": "1.1.0", "rbush": "2.0.2" diff --git a/site/.eslintrc b/site/.eslintrc index d216aa8846..58ff861d79 100644 --- a/site/.eslintrc +++ b/site/.eslintrc @@ -1,5 +1,6 @@ { "extends": "openlayers/react", + "parser": "babel-eslint", "globals": { "graphql": false } diff --git a/site/src/layouts/index.js b/site/src/layouts/index.js index e6d74ebcee..37691da722 100644 --- a/site/src/layouts/index.js +++ b/site/src/layouts/index.js @@ -29,6 +29,7 @@ const Layout = ({children}) => ( OpenLayers
+ docs  examples
diff --git a/site/src/pages/docs.js b/site/src/pages/docs.js new file mode 100644 index 0000000000..f5525e7086 --- /dev/null +++ b/site/src/pages/docs.js @@ -0,0 +1,67 @@ +import React, {Component} from 'react'; + +import info from '../../../build/info.json'; + +const modules = []; +const moduleLookup = {}; +info.modules.forEach(mod => { + moduleLookup[mod.path] = mod; + modules.push(mod); +}); + +info.symbols.forEach(symbol => { + const mod = moduleLookup[symbol.path]; + if (!mod) { + throw new Error(`No module for symbol ${symbol.name}`); + } + const kind = symbol.kind; + if (!mod[kind]) { + mod[kind] = []; + } + mod[kind].push(symbol); +}); + +function getModuleName(longname) { + return longname.slice(7); +} + +function getClassName(longname) { + return longname.split('~').pop(); +} + +function slugify(name) { + return name.replace(/[#~\.]/g, '-'); +} + +class Docs extends Component { + renderModule = mod => { + const slug = slugify(mod.name); + return ( +
+ +

{getModuleName(mod.name)}

+

Classes

+ {mod.class.map(cls => this.renderClass(cls, mod))} +
+
+ ); + }; + + renderClass(cls, mod) { + return ( +

+ + import {getClassName(cls.name)} from '{getModuleName(mod.name)}'; + +

+ ); + } + + render() { + return ( +
{modules.filter(mod => !!mod.class).map(this.renderModule)}
+ ); + } +} + +export default Docs;