Skip to content

Commit

Permalink
tabs to spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
popeindustries committed Feb 26, 2016
1 parent d2051cc commit d7b2a4b
Show file tree
Hide file tree
Showing 16 changed files with 1,605 additions and 1,587 deletions.
88 changes: 44 additions & 44 deletions index.js
@@ -1,11 +1,11 @@
'use strict';

var context = require('./lib/context')
, fs = require('fs')
, path = require('path')
, parse = require('./lib/parse')
, run = require('./lib/run')
, utils = require('./lib/utils');
, fs = require('fs')
, path = require('path')
, parse = require('./lib/parse')
, run = require('./lib/run')
, utils = require('./lib/utils');

/**
* Inline sources found in 'htmlpath'
Expand All @@ -14,35 +14,35 @@ var context = require('./lib/context')
* @param {Function} fn(err, html)
*/
module.exports = function inlineSource (htmlpath, options, fn) {
if ('function' == typeof options) {
fn = options;
options = {};
}
if ('function' == typeof options) {
fn = options;
options = {};
}

var ctx = context.create(options)
, next = function (html) {
ctx.html = html;
parse(ctx, function (err) {
if (err) return fn(err);
if (ctx.sources.length) {
run(ctx, ctx.sources, ctx.swallowErrors, fn);
} else {
return fn(null, ctx.html);
}
});
};
var ctx = context.create(options)
, next = function (html) {
ctx.html = html;
parse(ctx, function (err) {
if (err) return fn(err);
if (ctx.sources.length) {
run(ctx, ctx.sources, ctx.swallowErrors, fn);
} else {
return fn(null, ctx.html);
}
});
};

if (utils.isFilepath(htmlpath)) {
ctx.htmlpath = path.resolve(htmlpath);
fs.readFile(ctx.htmlpath, 'utf8', function (err, content) {
if (err) return fn(err);
next(content);
});
if (utils.isFilepath(htmlpath)) {
ctx.htmlpath = path.resolve(htmlpath);
fs.readFile(ctx.htmlpath, 'utf8', function (err, content) {
if (err) return fn(err);
next(content);
});

// Passed file content instead of path
} else {
next(htmlpath);
}
// Passed file content instead of path
} else {
next(htmlpath);
}
};

/**
Expand All @@ -52,22 +52,22 @@ module.exports = function inlineSource (htmlpath, options, fn) {
* @returns {String}
*/
module.exports.sync = function inlineSourceSync (htmlpath, options) {
options = options || {};
options = options || {};

var ctx = context.create(options);
var ctx = context.create(options);

if (utils.isFilepath(htmlpath)) {
ctx.htmlpath = path.resolve(htmlpath);
ctx.html = fs.readFileSync(ctx.htmlpath, 'utf8');
if (utils.isFilepath(htmlpath)) {
ctx.htmlpath = path.resolve(htmlpath);
ctx.html = fs.readFileSync(ctx.htmlpath, 'utf8');

// Passed file content instead of path
} else {
ctx.html = htmlpath;
}
// Passed file content instead of path
} else {
ctx.html = htmlpath;
}

parse(ctx);
parse(ctx);

return (ctx.sources.length)
? run(ctx, ctx.sources, ctx.swallowErrors)
: ctx.html;
return (ctx.sources.length)
? run(ctx, ctx.sources, ctx.swallowErrors)
: ctx.html;
};
64 changes: 32 additions & 32 deletions lib/context.js
@@ -1,46 +1,46 @@
'use strict';

var css = require('./css')
, inline = require('./inline')
, js = require('./js')
, img = require('./img')
, load = require('./load')
, merge = require('lodash/object/merge')
, path = require('path')
, utils = require('./utils')
, wrap = require('./wrap')
var assign = require('lodash/assign')
, css = require('./css')
, inline = require('./inline')
, js = require('./js')
, img = require('./img')
, load = require('./load')
, path = require('path')
, utils = require('./utils')
, wrap = require('./wrap')

, DEFAULT = {
attribute: 'inline',
compress: true,
ignore: [],
pretty: false,
swallowErrors: false,
svgAsImage: false
};
, DEFAULT = {
attribute: 'inline',
compress: true,
ignore: [],
pretty: false,
swallowErrors: false,
svgAsImage: false
};

/**
* Retrieve context from 'options'
* @param {Object} options
* @returns {Object}
*/
exports.create = function (options) {
options = options || {};
options = options || {};

var context = merge({
html: '',
htmlpath: '',
rootpath: process.cwd(),
sources: []
}, DEFAULT, options);
var context = assign({
html: '',
htmlpath: '',
rootpath: process.cwd(),
sources: []
}, DEFAULT, options);

if (options.rootpath) context.rootpath = path.resolve(options.rootpath);
if (options.pretty == true && context.compress == false) context.pretty = true;
context.re = utils.getTagRegExp(context.attribute);
// Prepare stack
context.stack = [load];
if (options.handlers) context.stack = context.stack.concat(options.handlers);
context.stack.push(js, css, img, wrap, inline);
if (options.rootpath) context.rootpath = path.resolve(options.rootpath);
if (options.pretty == true && context.compress == false) context.pretty = true;
context.re = utils.getTagRegExp(context.attribute);
// Prepare stack
context.stack = [load];
if (options.handlers) context.stack = context.stack.concat(options.handlers);
context.stack.push(js, css, img, wrap, inline);

return context;
return context;
};
38 changes: 19 additions & 19 deletions lib/css.js
@@ -1,7 +1,7 @@
'use strict';

var csso = require('csso')
, noop = require('./utils').noop;
, noop = require('./utils').noop;

/**
* Handle CSS content
Expand All @@ -10,23 +10,23 @@ var csso = require('csso')
* @param {Function} [next(err)]
*/
module.exports = function css (source, context, next) {
// Handle sync
next = next || noop;
// Handle sync
next = next || noop;

if (source.fileContent
&& !source.content
&& (source.type == 'css')) {
try {
source.content = source.compress
? csso.minify(source.fileContent)
: source.fileContent;
// Change tag type
source.tag = 'style';
next();
} catch (err) {
return next(err);
}
} else {
next();
}
if (source.fileContent
&& !source.content
&& (source.type == 'css')) {
try {
source.content = source.compress
? csso.minify(source.fileContent)
: source.fileContent;
// Change tag type
source.tag = 'style';
next();
} catch (err) {
return next(err);
}
} else {
next();
}
};

0 comments on commit d7b2a4b

Please sign in to comment.