-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
196 lines (189 loc) · 9.15 KB
/
index.js
File metadata and controls
196 lines (189 loc) · 9.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
var escape = require('escape-html');
var markdown = require('gitbook-markdown');
var gl_class_name = '';
module.exports = {
book: {
assets: './assets',
css: [
'website.css'
]
},
ebook: {
assets: './assets',
css: [
'ebook.css'
]
},
blocks: {
phpclassdisplayerReset:{
process: function(parentBlock) {
gl_class_name = '';
return '';
}
},
PHPclassDisplayer: {
process: function(parentBlock) {
if(parentBlock){
var blocks = [parentBlock].concat(parentBlock.blocks);
if (!parentBlock.args[0]) {
throw new Error('`phpclassdisplayer` requires a argument as class-name');
}
var class_name = parentBlock.args[0];
gl_class_name = class_name;
var class_desc = parentBlock.body.trim();
var anchor_body = '';
if(this.config.options.pluginsConfig.phpclassdisplayer.anchors === true){
anchor_body = '<a name="'+escape(class_name)+'"></a>';
}
return '<div class="phpclassdisplayer-class">'+
anchor_body+
'<div class="phpcd-title">Class <b>'+escape(class_name)+'</b></div>'+
'<div class="phpcd-desc">' + escape(class_desc) + '<div>' +
'</div>';
}
}
},
PHPconstDisplayer: {
process: function(parentBlock) {
var blocks = [parentBlock].concat(parentBlock.blocks);
if (!parentBlock.args[0]) {
throw new Error('`PHPconstDisplayer` requires a argument as constant-name');
}
var const_name = parentBlock.args[0];
var const_desc = parentBlock.body.trim();
var anchor = escape(const_name);
var classSwitch = '';
var scope = this.config.options.pluginsConfig.phpclassdisplayer.scope;
if(gl_class_name !== ''){
anchor = escape(gl_class_name)+scope+escape(const_name);
classSwitch = 'gl-';
}
var anchor_body = '';
if(this.config.options.pluginsConfig.phpclassdisplayer.anchors === true){
anchor_body = '<a name="'+anchor+'"></a>';
}
return '<div class="phpclassdisplayer-'+classSwitch+'const">'+
anchor_body+
'<div class="phpcd-title"><em>constant</em> <b>'+escape(const_name)+'</b></div>'+
'<div class="phpcd-desc">'+escape(const_desc)+'<div>'+
'</div>';
}
},
PHPmethodDisplayer: {
blocks: ['hint','param','return'],
process: function(parentBlock) {
var HINT_CLASSES = {
info:'info',
tip:'success',
danger:'danger',
working:'warning'
};
var hint_icon_info = this.config.options.pluginsConfig.phpclassdisplayer.hint_icon_info;
var hint_icon_tip = this.config.options.pluginsConfig.phpclassdisplayer.hint_icon_tip;
var hint_icon_danger = this.config.options.pluginsConfig.phpclassdisplayer.hint_icon_danger;
var hint_icon_working = this.config.options.pluginsConfig.phpclassdisplayer.hint_icon_working;
var hint_iconsize = this.config.options.pluginsConfig.phpclassdisplayer.hint_iconsize;
var hint_iconcenter = this.config.options.pluginsConfig.phpclassdisplayer.hint_iconcenter;
var HINT_ICONS = {
info: '<i class="fa fa-'+hint_icon_info+' '+hint_iconsize+'" aria-hidden="true"></i> ',
tip: '<i class="fa fa-'+hint_icon_tip+' '+hint_iconsize+'" aria-hidden="true"></i> ',
danger: '<i class="fa fa-'+hint_icon_danger+' '+hint_iconsize+'" aria-hidden="true"></i> ',
working: '<i class="fa fa-'+hint_icon_working+' '+hint_iconsize+'" aria-hidden="true"></i> '
};
var blocks = [parentBlock].concat(parentBlock.blocks);
if (!parentBlock.args[0]) {
throw new Error('`PHPmethodDisplayer` requires a argument as method/function-name');
}
var method_name = parentBlock.args[0];
method_name = escape(method_name);
method_name_wo_args = method_name.match(/(\w+)/);
method_name = method_name.replace(/(\w+)/, "<b>"+escape("$1")+"</b>");
method_name = method_name.replace(/([$]\w+)/g, "<em>"+escape("$1")+"</em>");
var method_desc = parentBlock.body.trim();
var method_params = '<ul>';
var method_return = '';
var method_hint = '';
var param_count = 0;
blocks.forEach(function(block, i) {
if(block.name == 'hint'){
if(block.body.trim() !== ''){
var style = block.kwargs.style || 'info';
var hint_body = block.body.trim();
var hint_center = '';
if(hint_iconcenter === true){
hint_center = 'align="middle"';
}
hint_body = markdown.page(hint_body).content;
method_hint = '<div class="phpcd-alert alert alert-'+HINT_CLASSES[style]+'" role="alert">' +
HINT_ICONS[style]+
hint_body.replace(/<p>|<\/p>/gi, '')+
'</div>';
}
}else if(block.name == 'param'){
if (!block.args[0]) {
throw new Error('`PHPmethodDisplayer` requires for `param` a argument parameter-name');
}
if (!block.kwargs.type) {
throw new Error('`PHPmethodDisplayer` requires for `param` a "type" property');
}
param_count++;
var param_body = block.body.trim();
param_body = markdown.page(param_body).content.replace(/<p>|<\/p>/gi, '');
method_params += '<li>'+
'<b>'+escape(block.args[0])+'</b> '+
'(<em>'+escape(block.kwargs.type)+'</em>) '+
' - '+param_body+
'</li>';
}else if(block.name == 'return'){
if(block.body.trim() !== ''){
return_body = block.body.trim();
return_body = markdown.page(return_body).content.replace(/<p>|<\/p>/gi, '');
method_return = '<tr>' +
'<td width="20%" class="phpcd-return-title">' +
'<b>Returns:</b>'+
'</td>' +
'<td class="phpcd-return-text">' +
return_body+
'</td>' +
'</tr>';
}
}
});
method_params += '</ul>';
var classSwitch = 'function';
var anchor = escape(method_name_wo_args[0]);
var scope = this.config.options.pluginsConfig.phpclassdisplayer.scope;
if(gl_class_name !== ''){
classSwitch = 'method';
anchor = escape(gl_class_name)+scope+escape(method_name_wo_args[0]);
}
var params = '';
if(param_count !== 0){
params = '<tr>' +
'<td width="20%" valign="top" class="phpcd-params-title">' +
'<b>Parameters:</b>'+
'</td>' +
'<td class="phpcd-params-list">' +
method_params+
'</td>' +
'</tr>';
}
var anchor_body = '';
if(this.config.options.pluginsConfig.phpclassdisplayer.anchors === true){
anchor_body = '<a name="'+anchor+'"></a>';
}
return '<div class="phpclassdisplayer-'+classSwitch+'">' +
anchor_body+
'<div class="phpcd-title">' + method_name + '</div>' +
'<div class="phpcd-desc">' + markdown.page(method_desc).content +
'<table>' +
params +
method_return +
'</table>' +
method_hint +
'</div>' +
'</div>';
}
},
}
};