-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
50 lines (39 loc) · 1.42 KB
/
script.js
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
new Vue({
el : '#app',
data : {
prefix : '',
css : '',
before : ''
},
computed : {
php : function () {
if (this.prefix && this.css) {
return this.generatePHP(this.prefix.trim(), this.css, this.before);
}
}
},
methods : {
beforeClassPrefix : function (e) {
this.before = event.target.getAttribute('before').trim();
},
generatePHP : function (prefix, css, before) {
var match,
phpcode = [],
$comments = /\/\*(?:(?!\*\/)[\s\S])*\*\//g,
$pattern = `.(${prefix}([^:|^"]+)):before`,
$regexp = new RegExp($pattern, "ig");
css = css.replace($comments, '');
while ((match = $regexp.exec(css)) !== null) {
if (match[1].indexOf(".") == -1 || match[1].indexOf(",") == -1) {
let name = match[2].replace(/-/g, ' ').replace(/(\b\w)/gi, function (m) {return m.toUpperCase();});
let icon = `${before} ${match[1]}`.trim();
phpcode.push(`\t'${icon}'=>'${name}'`);
if (before == 'dashicons' && match[1] == 'dashicons-before') {
phpcode.shift();
}
}
}
return `<?php \nreturn array(\n${phpcode.join(",\n")}\n);`;
}
}
});