Skip to content

Commit 8b20e0c

Browse files
committed
DashIcons Added
1 parent 7e2fa26 commit 8b20e0c

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

Diff for: index.html

+9-3
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@
4040
display : inline-block;
4141
font-size : 12px;
4242
}
43+
4344
small {
4445

45-
margin: 0 10px;
46+
margin : 0 10px;
4647

47-
}
48+
}
4849
</style>
4950
</head>
5051
<body>
@@ -56,12 +57,14 @@ <h1>Parse CSS and Convert to PHP Array</h1>
5657
<p>for convert icon font css to php array like flaticon / fontawesome etc.</p>
5758
<p>
5859
<small><a target="_blank" href="https://github.com/EmranAhmed/vue-generate-php-font-array">Github</a></small>
59-
60+
6061
<small><a target="_blank" href="https://cdn.materialdesignicons.com/1.7.22/css/materialdesignicons.css">Material Design Icons</a></small>
6162

6263
<small><a target="_blank" href="http://fontawesome.io/assets/font-awesome/css/font-awesome.css">FontAwesome</a></small>
6364

6465
<small><a target="_blank" href="http://www.flaticon.com/">FlatIcon</a></small>
66+
67+
<small><a target="_blank" href="https://raw.githubusercontent.com/WordPress/dashicons/master/css/dashicons.css">DashIcons</a></small>
6568
</p>
6669

6770
<label>
@@ -73,6 +76,9 @@ <h1>Parse CSS and Convert to PHP Array</h1>
7376
<label>
7477
<input type="radio" v-model="prefix" @change="beforeClassPrefix" before="mdi" value="mdi-"> Material Design Icon
7578
</label>
79+
<label>
80+
<input type="radio" v-model="prefix" @change="beforeClassPrefix" before="dashicons" value="dashicons-"> DashIcons
81+
</label>
7682
<textarea v-model="css" cols="30" placeholder="Paste CSS Contents" rows="10"></textarea>
7783
<textarea v-show="php" readonly v-model="php" cols="30" rows="10"></textarea>
7884

Diff for: script.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ new Vue({
33
data : {
44
prefix : '',
55
css : '',
6-
php : '',
76
before : ''
87
},
98

@@ -24,16 +23,27 @@ new Vue({
2423
generatePHP : function (prefix, css, before) {
2524

2625
var match,
27-
phpcode = [],
28-
$pattern = `.(${prefix}([^:|^"]+)):before`,
29-
$regexp = new RegExp($pattern, "ig");
26+
phpcode = [],
27+
$comments = /\/\*(?:(?!\*\/)[\s\S])*\*\//g,
28+
$pattern = `.(${prefix}([^:|^"]+)):before`,
29+
$regexp = new RegExp($pattern, "ig");
30+
31+
css = css.replace($comments, '');
3032

3133
while ((match = $regexp.exec(css)) !== null) {
3234
if (match[1].indexOf(".") == -1 || match[1].indexOf(",") == -1) {
3335
let name = match[2].replace(/-/g, ' ').replace(/(\b\w)/gi, function (m) {return m.toUpperCase();});
34-
phpcode.push(`\t'${before} ${match[1]}'=>'${name}'`);
36+
37+
let icon = `${before} ${match[1]}`.trim();
38+
39+
phpcode.push(`\t'${icon}'=>'${name}'`);
40+
41+
if (before == 'dashicons' && match[1] == 'dashicons-before') {
42+
phpcode.shift();
43+
}
3544
}
3645
}
46+
3747
return `<?php \nreturn array(\n${phpcode.join(",\n")}\n);`;
3848
}
3949
}

0 commit comments

Comments
 (0)