From bfff24f16e9f295dc4f722e8835d382ae6e65b77 Mon Sep 17 00:00:00 2001 From: ashaffer Date: Fri, 7 Mar 2014 17:59:56 -0800 Subject: [PATCH] Update index.js --- index.js | 66 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/index.js b/index.js index a056202..523ac62 100644 --- a/index.js +++ b/index.js @@ -8,54 +8,54 @@ var path = require('path'); var url = require('url'); function isLocal(link) { - return link && ! url.parse(link).hostname; + return link && ! url.parse(link).hostname; } module.exports = function() { - // create a stream through which each file will pass - return through.obj(function(file, enc, callback) { + // create a stream through which each file will pass + return through.obj(function(file, enc, callback) { - if (file.isNull()) { - this.push(file); // do nothing if no contents - return callback(); - } + if (file.isNull()) { + this.push(file); // do nothing if no contents + return callback(); + } - if (file.isStream()) { - this.emit('error', new gutil.PluginError('gulp-smoosher', 'Streaming not supported')); - return callback(); - } + if (file.isStream()) { + this.emit('error', new gutil.PluginError('gulp-smoosher', 'Streaming not supported')); + return callback(); + } - if (file.isBuffer()) { + if (file.isBuffer()) { - var rePattern = /([\s\S]*?)/g; + var rePattern = /([\s\S]*?)/g; - var input = String(file.contents); + var input = String(file.contents); - var output = input.replace(rePattern, function(match) { + var output = input.replace(rePattern, function(match) { - var $ = cheerio.load(match); + var $ = cheerio.load(match); - $('link').each(function(index, element) { - var href = $(element).attr('href'); - isLocal(href) && $(element).replaceWith(''); - }); + $('link').each(function(index, element) { + var href = $(element).attr('href'); + isLocal(href) && $(element).replaceWith(''); + }); - $('script').each(function(index, element) { - var src = $(element).attr('src'); - if(isLocal(src)) { - $(element).attr('src', '') - .text(fs.readFileSync(path.join(file.base, src))); - } - }); + $('script').each(function(index, element) { + var src = $(element).attr('src'); + if(isLocal(src)) { + $(element).attr('src', '') + .text(fs.readFileSync(path.join(file.base, src))); + } + }); - return $.html(); - }).replace(/\n|\n/g, ''); + return $.html(); + }).replace(/\n|\n/g, ''); - file.contents = new Buffer(output); + file.contents = new Buffer(output); - return callback(null, file); - } + return callback(null, file); + } - }); + }); };