Skip to content

Commit 5a97ce8

Browse files
author
fabianmoronzirfas
committed
feat(index): working on index paramters
trying to add logic. Liquid is to verbose for that the checking of optional paramters and all that needs to be done before moving to liquid
1 parent 3478fa6 commit 5a97ce8

File tree

12 files changed

+13363
-3820
lines changed

12 files changed

+13363
-3820
lines changed

.bin/json-transform.js

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,55 @@ 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 Tag = require('./lib/tag');
56
const Category = require('./lib/category');
67
const _ = require('lodash');
78

89

910
let data = [];
10-
1111
api.forEach((e, i, arr)=> {
1212
let entry = new Entry();
13-
// console.log(`\n# Title:\n${e.name}`);
1413
entry.name = e.name;
15-
// //console.log(`# ${JSON.stringify(e.description)}`);
1614
if(e.description instanceof Object) {
1715
let des = e.description.children[0].children[0].value;
18-
// console.log(`## Description:\n${des}`);
1916
entry.description = des;
2017
}
2118
if(e.hasOwnProperty('kind') === true) {
2219
entry.kind = e.kind;
2320
}
24-
2521
if(Array.isArray(e.params)) {
26-
// console.log('\n### Parameters:');
2722
e.params.forEach((ele, ndx, array)=> {
2823
let param = new Parameter();
2924
param.name = ele.name;
3025
let descr = (ele.description instanceof Object) ? ele.description.children[0].children[0].value : '';
3126
param.description = descr;
3227
entry.parameters.push(param);
33-
// console.log(`Argument ${ndx + 1}\nName: ${ele.name}\nDescription:\n ${descr}`);
3428
});
3529
}
3630
if(Array.isArray(e.returns)) {
37-
// console.log('### Returns');
3831
if(e.returns[0].description.children.length > 0) {
3932
let ret = e.returns[0].description.children[0].children[0].value;
4033
entry.returns = ret;
41-
// console.log(ret);
42-
4334
}
4435
}
4536
if(Array.isArray(e.tags)) {
4637
e.tags.forEach((ele, ndx, array)=>{
4738
if(ele.title === 'cat') {
48-
// //console.log(ele.title);
49-
// console.log(`\n### Category:\n${ele.description}`);
5039
entry.category = ele.description;
51-
}
52-
if(ele.title === 'subcat') {
53-
// //console.log(ele.title);
54-
// console.log(`\n### Sub Category:\n${ele.description}`);
40+
} else if(ele.title === 'subcat') {
5541
entry.subcategory = ele.description;
42+
} else {
43+
var tag = new Tag();
44+
tag.name = ele.name;
45+
tag.title = ele.title;
46+
tag.description = ele.description;
47+
tag.type = ele.type !== null ? ele.type : null;
48+
entry.tags.push(tag);
5649
}
57-
// let tag = _.find(ele, 'title');
58-
// //console.log(tag);
59-
// let tag = _.find(ele, (o)=>{
60-
// return o.title === 'cat';
61-
// });
62-
// //console.log(tag.description);
6350
});
6451
}
65-
// for(let k in e) {
66-
// if(e.hasOwnProperty(k)) {
67-
// //console.log(`\t${k}`);
68-
// }
69-
// }
7052
data.push(entry);
71-
// console.log('-----------------\n');
7253
});
73-
74-
// console.log(JSON.stringify(data, null, 2));
7554
// taken from here
7655
// http://stackoverflow.com/questions/23600897/using-lodash-groupby-how-to-add-your-own-keys-for-grouped-output
7756
let sortedByCategory = _.chain(data)
@@ -93,19 +72,16 @@ let sortedBySubCategory = _.chain(data)
9372
}).value();
9473

9574

96-
// console.log(JSON.stringify(sortedBySubCategory, null, 2));
97-
98-
9975
fs.writeFile('./_data/categories.json', JSON.stringify(sortedByCategory, null, 2), (err)=>{
10076
if(err) {
10177
throw err;
10278
}
103-
// //console.log('saved');
79+
10480
});
10581

10682
fs.writeFile('./_data/sub-categories.json', JSON.stringify(sortedBySubCategory, null, 2), (err)=>{
10783
if(err) {
10884
throw err;
10985
}
110-
// //console.log('saved');
86+
11187
});

.bin/lib/entry.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function Entry() {
88
this.subcategory = null;
99
this.parameters = [];
1010
this.kind = null;
11+
this.tags = [];
1112
}
1213

1314
module.exports = Entry;

.bin/lib/parameter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var exports = module.exports = {};
33
function Paramter() {
44
this.name = null;
55
this.description = null;
6+
this.optional = null;
67
}
78

89
module.exports = Paramter;

.bin/lib/tag.js

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

0 commit comments

Comments
 (0)