Skip to content

Commit

Permalink
Merge pull request #748 from matuzalemsteles/GenerateAPIDocs
Browse files Browse the repository at this point in the history
Generate API Documents
  • Loading branch information
jbalsas authored Mar 28, 2018
2 parents c99848e + d5c6ee2 commit baf9040
Show file tree
Hide file tree
Showing 15 changed files with 912 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/clay-charts/src/BubbleChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ BubbleChart.STATE = {
* The variety of chart that will be rendered.
* @default donut
* @instance
* @memberof DonutChart
* @memberof BubbleChart
* @type {?(string|undefined)}
*/
type: Config.string().value('bubble'),
Expand Down
1 change: 1 addition & 0 deletions packages/clay-charts/src/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import templates from './Chart.soy.js';
*/
class Chart extends DataComponent {}

Object.setPrototypeOf(ChartBase, DataComponent.prototype);
Object.assign(Chart.prototype, ChartBase);
Chart.STATE = Object.assign({}, ChartBase.STATE);

Expand Down
2 changes: 1 addition & 1 deletion packages/clay-charts/src/ChartBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ ChartBase.STATE = {
* @default undefined
* @instance
* @memberof ChartBase
* @type {?Object|undefined}
* @type {?(Object|undefined)}
*/
grid: Config.shapeOf({
// Cross reference this with source code, have a feeling this info is wrong
Expand Down
23 changes: 22 additions & 1 deletion packages/clayui.com/electric.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if (clayPath) {
}

const excludedComponents = /.*(pagination|isomorphic)/g;
const metalComponents = ['electric-quartz-components']
const metalComponents = ['electric-clay-components']
.concat(fs.readdirSync('../').filter(f => f.match(/^clay-.*/) && !f.match(excludedComponents)));
const pathSrc = 'src';
const ignoreDirs = ['components', 'layouts', 'pages', 'partials', 'styles'];
Expand All @@ -50,10 +50,31 @@ module.exports = {
},
codeMirrorLanguages: ['xml', 'htmlmixed', 'soy'],
metalComponents: metalComponents,
apiConfig: {
layout: 'main',
project: {
docsConfig: {
inferPrivate: '^_',
shallow: true,
},
refs: ['v2.0.0-rc.10', 'v2.0.0-rc.9'],
repo: 'clay',
soyAPIEntitiesPath: '../../../partials/ElectricAPIEntities.soy.js',
src: [
'packages/clay-*!(isomorphic)/src/Clay*.js',
'packages/clay-charts/src/*.js'
],
srcPath: 'packages',
user: 'liferay',
},
},
resolveModules: ['../../node_modules'],
sassOptions: {
includePaths: ['node_modules', clayIncludePaths],
},
entryPoints: {
electricAPI: path.join(__dirname, 'src/partials/ElectricAPIBundle.js'),
},
staticStc: staticSrc,
vendorSrc: [
{
Expand Down
4 changes: 2 additions & 2 deletions packages/clayui.com/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"devDependencies": {
"concurrently": "^3.5.0",
"countries-list": "^2.0.0",
"electric-cli": "^3.0.1",
"electric-quartz-components": "alpha",
"electric-cli": "^3.0.4",
"electric-clay-components": "^3.0.1",
"gulp": "^3.9.1",
"gulp-sass": "^3.1.0",
"gulp-storage": "^1.0.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/clayui.com/src/assets/world-low-res.geo.json

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions packages/clayui.com/src/pages/api/index.soy
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: "Api"
url: "/api/v2.0.0-rc.10"
layout: false
---

{namespace pageApiIndex}

/**
*/
{template .render}
{@param page: ?}

<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="0; URL='{$page.url}'">
</head>
</html>
{/template}
3 changes: 3 additions & 0 deletions packages/clayui.com/src/pages/index.soy
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ description: "This is Clay. A web implementation of the Lexicon Experience Langu
<span class="title align-middle">Clay</span>
</div>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link ml-3" href="/api/v2.0.0-rc.10">API</a>
</li>
<li class="nav-item">
<a class="nav-link ml-3" href="/docs/components/alerts.html">Components Library</a>
</li>
Expand Down
128 changes: 128 additions & 0 deletions packages/clayui.com/src/partials/ElectricAPI.soy
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{namespace ElectricApi}

{template .render}
{@param apiData: ?}
{@param project: ?}
{@param site: ?}
{@param? entityData: ?}

<div class="api">
<script src="/js/bundles/electricApi.js"></script>
<div class="navbar navbar-mobile navbar-expand-lg navbar-header">
<a class="navbar-brand d-flex" href="/">
<img class="logo mr-2" src="/images/clay_logo_w.png" alt="" />
<span class="title h1 font-weight-bold mb-0 p-1">{$site.title} </span>
</a>

<button class="navbar-toggler sidebar-toggler p-3" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<svg aria-hidden="true" class="lexicon-icon lexicon-icon-bars">
<use xlink:href="/vendor/lexicon/icons.svg#bars" />
</svg>
</button>
</div>

<nav class="sidebar-toggler-content sidenav-fixed sidenav-menu-slider" id="clay-sidebar">
<div class="sidebar sidebar-clay-site sidenav-menu d-flex flex-column">
<div class="sidebar-header">
<div class="navbar navbar-expand-lg navbar-header">
<a class="navbar-brand" href="/">
<img class="logo mr-2" src="/images/clay_logo_w.png" alt="{$site.title}" />
<span class="title">{$site.title} </span>
<small>by Liferay</small>
</a>
<div class="btn-group">
<button aria-expanded="false" aria-haspopup="true" class="btn btn-sm btn-version dropdown-toggle" data-toggle="dropdown" type="button">
{$project.ref}
<svg aria-hidden="true" class="lexicon-icon lexicon-icon-caret-bottom ml-1">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/vendor/lexicon/icons.svg#caret-bottom"></use>
</svg>
</button>
<div class="dropdown-menu mt-2">
{foreach $ref in $project.refs}
{let $classes kind="text"}
dropdown-item
{if $project.ref == $ref}
{sp}active
{/if}
{/let}

<a class="{$classes}" href="/api/{$ref}">{$ref}</a>
{/foreach}
</div>
</div>
</div>
</div>

<div class="sidebar-body mb-auto">
<div class="sidebar-search">
<div class="page-autocomplete">
<div class="form-group">
<div class="input-group">
<input autocomplete="off" class="form-control" name="query" placeholder="Search API" ref="input" type="text" aria-activedescendant="" aria-autocomplete="list" aria-haspopup="true" aria-owns="autocomplete-6" role="combobox">
<span class="input-group-addon">
<svg class="lexicon-icon">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/vendor/lexicon/icons.svg#search"></use>
</svg>
</span>
</div>
</div>
</div>
</div>

<ul class="nav nav-nested nav-pills nav-stacked">
{foreach $entity in $apiData}
<li class="{if $entityData.name == $entity.name} active{/if}">
<a class="align-middle" href="/api/{$project.ref}/{$entity.name}.html">
<span>{$entity.name}</span>
</a>
</li>
{/foreach}
</ul>
</div>
<ul class="nav-icons">
<li class="d-block mb-3">
<a class="rounded-circle sticker sticker-secondary" href="https://github.com/liferay/clay/issues" target="_blank">
<svg aria-hidden="true" class="lexicon-icon lexicon-icon-bars">
<use xlink:href="/vendor/lexicon/icons.svg#comments" />
</svg>
</a>
</li>
<li class="d-block">
<a class="rounded-circle sticker sticker-secondary" href="https://github.com/liferay/clay" target="_blank">
<img class="lexicon-icon" src="/images/home/GitHub-Mark-64px.svg" alt="">
</a>
</li>
</ul>
</div>
</nav>

<div class="sidebar-offset">
<div class="clay-site-container container-fluid">
{if $entityData and $entityData.name}
{call ElectricAPIEntities.render}
{param entityData: $entityData /}
{param project: $project /}
{/call}
{else}
<div class="docs-home-top">
<div class="row">
<div class="col-md-12">
<h1 class="docs-home-top-title">{$project.ref}</h1>
</div>
</div>
</div>
{/if}
</div>
</div>

<script type="text/javascript">
window.electricPageComponent = new pageComponent.default({lb}
project: {lb}
ref: '{$project.ref}',
repo: '{$project.repo}',
user: '{$project.user}'
{rb}
{rb});
</script>
</div>
{/template}
140 changes: 140 additions & 0 deletions packages/clayui.com/src/partials/ElectricAPIAutocomplete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
'use strict';

import {isServerSide} from 'metal';
import Ajax from 'metal-ajax';
import Autocomplete from 'metal-autocomplete';
import Component from 'metal-component';
import core from 'metal';
import Promise from 'metal-promise';

class ElectricAPIAutocomplete extends Component {
attached() {
if (isServerSide()) {
return;
}

this.autocomplete = new Autocomplete({
autoBestAlign: false,
data: this.search_.bind(this),
format: this.format_.bind(this),
inputElement: this.input,
select: function(event) {
window.location = event.url;
}
});
}

disposed() {
let autocomplete = this.autocomplete;

if (autocomplete) {
autocomplete.dispose();
}
}

format_(data) {
let url = this.formatURL_(data);

return {
textPrimary: `<a class="autocomplete-link" href="${url}">
<div class="autocomplete-result">
<p class="autocomplete-title">${data.name}</p>
<p class="autocomplete-text">${data.memberof}</p>
</div>
</a>`,
url: url
};
}

formatURL_(data) {
let memberof = data.memberof;
let name = data.name;

let url = `/api/${this.project.ref}/${memberof || name}.html`;

if (memberof && name !== memberof) {
url += '#' + name;
}

return url;
}

matchesQuery_(entity, query) {
let name = entity.name;

name = name ? name.toLowerCase() : '';

return name.indexOf(query) > -1;
}

filterResults_(data, query) {
let instance = this;
let results = [];

data.forEach(function(entity) {
if (instance.matchesQuery_(entity, query)) {
results.push(entity);
}

if (entity.members) {
results = results.concat(instance.filterResults_(entity.members.instance, query));
results = results.concat(instance.filterResults_(entity.members.static, query));
}
});

return results;
}

search_(query) {
let instance = this;

return Promise.resolve(this.data)
.then(function(data) {
if (data) {
return data;
}
else {
return Ajax.request(instance.dataSource)
}
})
.then(function(data) {
if (data.response) {
data = JSON.parse(data.response);

instance.data = data;
}

let results = [];

if (data && query) {
results = instance.filterResults_(data, query.toLowerCase());

if (results.length > instance.maxResults) {
results = results.slice(0, instance.maxResults);
}
}

return results;
});
}
}

ElectricAPIAutocomplete.STATE = {
dataSource: {
validator: core.isString
},

maxResults: {
validator: core.isNumber
},

project: {
validator: core.isObject
},

input: {
validator: core.isElement
}
};

export default ElectricAPIAutocomplete;
Loading

0 comments on commit baf9040

Please sign in to comment.