Skip to content

Commit

Permalink
Use API from evil-icons package
Browse files Browse the repository at this point in the history
  • Loading branch information
madyankin committed Jan 17, 2015
1 parent 3574634 commit 502f437
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 50 deletions.
46 changes: 1 addition & 45 deletions index.js
Expand Up @@ -14,57 +14,13 @@ var icons = require("evil-icons");
var PluginError = gutil.PluginError;


function buildParamsFromString(string) {
var paramsString;
var params = {};
var string = string.trim().replace(/['"]/gi, '');

string.split(' ').forEach(function(param){
var param = param.split('=');
var key = param[0];
var value = param[1];

params[key] = value;
});

return params;
}


function replaceIconTags(src) {
var match, tag, params, icon, name;
var html = src.toString();
var iconRegexp = /<icon\s+([-=\w\d'"\s]+)\s*\/?>(<\/icon>)?/gi;

while (match = iconRegexp.exec(html)) {
tag = match[0];
params = buildParamsFromString(match[1]);
name = params.name;

delete params.name;

icon = icons.icon(name, params)
html = html.replace(tag, icon);
}

return html;
}


function iconize(src) {
var html = src.toString();
html = html.replace(/<body.*?>/, function(match) { return match + icons.sprite });
return replaceIconTags(html);
}


function gulpEvilIcons() {
return through.obj(function(file, enc, cb) {
if (file.isNull()) {
cb(null, file);
}

var html = iconize(file.contents);
var html = icons.iconizeHtml(file.contents);

if (file.isBuffer()) {
file.contents = new Buffer(html);
Expand Down
8 changes: 3 additions & 5 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "gulp-evil-icons",
"version": "0.1.4",
"version": "0.1.5",
"description": "Gulp plugin to use Evil Icons in your project",
"main": "index.js",
"scripts": {
Expand All @@ -23,9 +23,7 @@
"homepage": "https://github.com/outpunk/gulp-evil-icons",
"dependencies": {
"gulp-util": "^3.0.1",
"through2": "^0.6.3"
},
"peerDependencies": {
"evil-icons": "^1.4.0"
"through2": "^0.6.3",
"evil-icons": "^1.5.0"
}
}

0 comments on commit 502f437

Please sign in to comment.