UNPKG

2.62 kBJavaScriptView Raw
1
2/**
3 * The helpers module
4 *
5 * @module helpers
6 * @main helpers
7 */
8
9const _ = require('underscore');
10const Handlebars = require('handlebars');
11
12/**
13 * Build file tree
14 * @method renderFileTree
15 */
16// TODO(Yorkie): remove the buildFileTree
17exports.buildFileTree = function onbuildFileTree (items) {
18 var out = '<ul>';
19 _.each(items, function (i, k) {
20 out += '<li>';
21 if (_.isObject(i)) {
22 if (!i.path) {
23 out += k + '/' + onbuildFileTree(i);
24 } else {
25 out += '<a href="../files/' + i.name + '.html">' + k + '</a>';
26 }
27 }
28 out += '</li>';
29 });
30 out += '</ul>';
31 return out;
32};
33exports.renderFileTree = exports.buildFileTree;
34
35/**
36 * Create cross link
37 * @method crossLink
38 */
39exports.crossLink = function oncrossLink (item, options) {
40 var str = '';
41 if (!item) {
42 item = '';
43 }
44 if (item.indexOf('|') > 0) {
45 var parts = item.split('|'),
46 p = [];
47 _.each(parts, function (i) {
48 p.push(this._parseCrossLink.call(this, i));
49 }, this);
50 str = p.join(' | ');
51 } else {
52 var ctx = '';
53 if (typeof options.fn === 'function') {
54 ctx = options.fn(this);
55 }
56 str = this._parseCrossLink.call(this, item, false, ctx);
57 }
58 return str;
59};
60
61/**
62 * Create cross link module
63 * @method crossLinkModule
64 */
65exports.crossLinkModule = function oncrossLinkModule (item, options) {
66 var str = item;
67 if (this.ast.modules[item]) {
68 var content = options.fn(this);
69 if (content === "") {
70 content = item;
71 }
72 str = '<a href="../modules/' + item.replace(/\//g, '_') +
73 '.html">' + content + '</a>';
74 }
75 return str;
76};
77
78/**
79 * Create cross link to raw
80 * @method crossLinkRaw
81 */
82exports.crossLinkRaw = function oncrossLinkRaw (item, options) {
83 var str = '';
84 if (!item) {
85 item = '';
86 }
87 if (item.indexOf('|') > 0) {
88 var parts = item.split('|'),
89 p = [];
90 _.each(parts, function (i) {
91 p.push(this._parseCrossLink.call(this, i, true));
92 }, this);
93 str = p.join(' | ');
94 } else {
95 str = this._parseCrossLink.call(this, item, true);
96 }
97 return str;
98};
99
100exports.shouldShowInherit = function shouldShowInherit (item, options) {
101 var classObj = this.ast.classes[item];
102 if (classObj && !classObj.access) {
103 classObj.access = 'public';
104 }
105 if (classObj && classObj.access !== 'private') {
106 // console.log('show inherit for ' + item);
107 return options.fn(this);
108 } else {
109 // console.log('hide inherit for ' + item);
110 return options.inverse(this);
111 }
112};