Skip to content

Commit 6fbd837

Browse files
author
fabianmoronzirfas
committed
feat(added pages and index as include):
1 parent 5a97ce8 commit 6fbd837

File tree

246 files changed

+13286
-17990
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

246 files changed

+13286
-17990
lines changed

.bin/files-and-folders.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,20 @@ data.forEach((element, index, array)=>{
1717
let file = `./${element.cat.toLowerCase()}/${e.name}.md`;
1818
let frontmatter = YAML.stringify({
1919
layout: 'entry',
20-
title: e.name + (e.kind === 'function' ? '()' : ''),
20+
title: e.name,
21+
codetitle: e.codetitle,
2122
description: e.description,
2223
category: e.category,
2324
subcategory: e.subcategory,
2425
returns: e.returns,
25-
parameters: e.parameters
26+
parameters: e.parameters,
27+
kind: e.kind
2628
}, 2);
27-
fs.outputFile(file, `---\n${frontmatter}\n---\n${e.description}`, (error)=>{
29+
fs.outputFile(file, `---\n${frontmatter}\n---\n`, (error)=>{
2830
if(error) {
2931
console.log(error);
3032
}
3133
});
3234
});
33-
// test if the folder exists
34-
// try{
35-
// fs.accessSync(dir);
36-
// console.log(`folder ${dir} exists`);
37-
// }catch(error) {
38-
// if (error && error.code === 'ENOENT') {
39-
// console.log(`folder '${dir}' does not exist`);
40-
// try{
41-
42-
// fs.mkdirSync(dir);
43-
// }catch(e)
44-
// }
45-
46-
// }
4735
}
4836
});

.bin/json-transform.js

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ const fs = require('fs');
22
const api = require('../_data/api.json');
33
const Entry = require('./lib/entry');
44
const Parameter = require('./lib/parameter');
5+
const Return = require('./lib/returns');
56
const Tag = require('./lib/tag');
67
const Category = require('./lib/category');
78
const _ = require('lodash');
9+
const generator = require('./lib/generator');
810

911

1012
let data = [];
@@ -18,15 +20,15 @@ api.forEach((e, i, arr)=> {
1820
if(e.hasOwnProperty('kind') === true) {
1921
entry.kind = e.kind;
2022
}
21-
if(Array.isArray(e.params)) {
22-
e.params.forEach((ele, ndx, array)=> {
23-
let param = new Parameter();
24-
param.name = ele.name;
25-
let descr = (ele.description instanceof Object) ? ele.description.children[0].children[0].value : '';
26-
param.description = descr;
27-
entry.parameters.push(param);
28-
});
29-
}
23+
// if(Array.isArray(e.params)) {
24+
// e.params.forEach((ele, ndx, array)=> {
25+
// let param = new Parameter();
26+
// param.name = ele.name;
27+
// let descr = (ele.description instanceof Object) ? ele.description.children[0].children[0].value : '';
28+
// param.description = descr;
29+
// entry.parameters.push(param);
30+
// });
31+
// }
3032
if(Array.isArray(e.returns)) {
3133
if(e.returns[0].description.children.length > 0) {
3234
let ret = e.returns[0].description.children[0].children[0].value;
@@ -39,7 +41,61 @@ api.forEach((e, i, arr)=> {
3941
entry.category = ele.description;
4042
} else if(ele.title === 'subcat') {
4143
entry.subcategory = ele.description;
42-
} else {
44+
} else if (ele.title === 'param') {
45+
var param = new Parameter();
46+
param.name = ele.name;
47+
param.description = ele.description;
48+
// console.log(ele);
49+
if (ele.hasOwnProperty('type')) {
50+
if (ele.type !== null) {
51+
if (ele.type.hasOwnProperty('type')) {
52+
if(ele.type.type === 'NameExpression') {
53+
// argument not otional
54+
// no multiples
55+
param.type.push(ele.type.name);
56+
}else if(ele.type.type === 'OptionalType') {
57+
param.optional = true;
58+
if(ele.type.expression.name === 'UnionType') {
59+
ele.type.expression.elements.forEach((element, index)=>{
60+
param.type.push(element.name);
61+
});
62+
}else{
63+
param.type.push(ele.type.expression.name);
64+
65+
}
66+
}else if (ele.type.type === 'UnionType') {
67+
ele.type.elements.forEach((element, index)=>{
68+
param.type.push(element.name);
69+
70+
});
71+
}
72+
}
73+
}
74+
}
75+
entry.parameters.push(param);
76+
} else if (ele.title === 'method') {
77+
entry.kind = 'function';
78+
}else if (ele.title === 'constant' || ele.title === 'property') {
79+
entry.kind = 'constant';
80+
81+
} else if (ele.title === 'return' || ele.title === 'returns') {
82+
let returnValue = new Return();
83+
returnValue.description = ele.description;
84+
if(ele.hasOwnProperty('type')) {
85+
if (ele.type !== null) {
86+
if (ele.type.hasOwnProperty('type')) {
87+
if(ele.type.type === 'NameExpression') {
88+
returnValue.type.push(ele.type.name);
89+
}else if(ele.type.type === 'UnionType') {
90+
ele.type.elements.forEach((element)=>{
91+
returnValue.type.push(element.name);
92+
});
93+
}
94+
}
95+
}
96+
}
97+
entry.returns = returnValue;
98+
}else {
4399
var tag = new Tag();
44100
tag.name = ele.name;
45101
tag.title = ele.title;
@@ -51,6 +107,8 @@ api.forEach((e, i, arr)=> {
51107
}
52108
data.push(entry);
53109
});
110+
111+
data = generator(data);
54112
// taken from here
55113
// http://stackoverflow.com/questions/23600897/using-lodash-groupby-how-to-add-your-own-keys-for-grouped-output
56114
let sortedByCategory = _.chain(data)
@@ -76,12 +134,10 @@ fs.writeFile('./_data/categories.json', JSON.stringify(sortedByCategory, null, 2
76134
if(err) {
77135
throw err;
78136
}
79-
80137
});
81138

82139
fs.writeFile('./_data/sub-categories.json', JSON.stringify(sortedBySubCategory, null, 2), (err)=>{
83140
if(err) {
84141
throw err;
85142
}
86-
87143
});

.bin/lib/generator.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Generates data from existing one
3+
*
4+
*/
5+
var exports = module.exports = {};
6+
7+
8+
function generator(data) {
9+
data.forEach((element)=>{
10+
element.codetitle = null;
11+
if(element.kind.toString() === 'function') {
12+
let params = '';
13+
element.parameters.forEach((ele, ndx, arr)=>{
14+
let name = (ele.optional === true) ? `[${ele.name}]` : ele.name;
15+
let sep = (ndx + 1 !== arr.length) ? ', ' : '';
16+
params += name + sep;
17+
});
18+
19+
element.codetitle = `b.${element.name}(${params})`;
20+
console.log(element);
21+
22+
}else if (element.kind.toString() === 'constant') {
23+
element.codetitle = `b.${element.name}`;
24+
} else if(element.kind.toString() === 'class') {
25+
element.codetitle = `${element.name}`;
26+
}
27+
});
28+
return data;
29+
}
30+
31+
module.exports = generator;

.bin/lib/parameter.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ var exports = module.exports = {};
33
function Paramter() {
44
this.name = null;
55
this.description = null;
6-
this.optional = null;
6+
this.optional = false;
7+
this.type = [];
78
}
89

910
module.exports = Paramter;

.bin/lib/returns.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var exports = module.exports = {};
2+
3+
function Return() {
4+
this.name = null;
5+
this.description = null;
6+
this.type = [];
7+
}
8+
9+
module.exports = Return;

0 commit comments

Comments
 (0)