Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

**5.0.3** - Sept 22, 2016
* compatible anyother fileSystem to read the file

**5.0.2** - Sept 14, 2016
* fix escaping of `</script>` tags in inlined js content

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Inline and compress tags that contain the `inline` attribute. Supports `<script>
`htmlpath` can be either a filepath *or* a string of html content.

Available `options` include:
- `fs`: attribute used to change fileSystem (default is node fileSystem)
- `attribute`: attribute used to parse sources (default `inline`)
- `compress`: enable/disable compression of inlined content (default `true`)
- `handlers`: specify custom handlers (default `[]`) [see [custom handlers](#custom-handlers)]
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var context = require('./lib/context');
var fs = require('fs');
var path = require('path');
var parse = require('./lib/parse');
var run = require('./lib/run');
Expand All @@ -18,6 +17,8 @@ module.exports = function inlineSource (htmlpath, options, fn) {
fn = options;
options = {};
}
//compatible memory fs
var fs = options.fs || require('fs');

var ctx = context.create(options);
var next = function (html) {
Expand Down Expand Up @@ -53,6 +54,9 @@ module.exports = function inlineSource (htmlpath, options, fn) {
*/
module.exports.sync = function inlineSourceSync (htmlpath, options) {
options = options || {};

//compatible memory fs
var fs = options.fs || require('fs');

var ctx = context.create(options);

Expand Down
3 changes: 1 addition & 2 deletions lib/load.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
'use strict';

const fs = require('fs');

/**
* Load content for 'source'
* @param {Object} source
* @param {Object} context
* @param {Function} [next]
*/
module.exports = function load (source, context, next) {
var fs = context.fs || require('fs');
if (!source.fileContent && source.filepath) {
// Raw buffer if image and not svg
var encoding = (source.type == 'image' && source.format != 'svg+xml')
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "inline-source",
"description": "Inline all flagged js, css, image source files",
"version": "5.0.2",
"version": "5.0.3",
"author": "popeindustries <alex@pope-industries.com>",
"keywords": [
"inline",
Expand All @@ -19,6 +19,7 @@
},
"devDependencies": {
"expect.js": "*",
"memory-fs": "^0.3.0",
"mocha": "*"
},
"main": "index.js",
Expand Down
14 changes: 14 additions & 0 deletions test/5-inline-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const expect = require('expect.js');
const inline = require('..');
const inlineSync = require('..').sync;
const path = require('path');
const MemoryFileSystem = require('memory-fs');

describe('inline', function () {
before(function () {
Expand Down Expand Up @@ -258,6 +259,19 @@ describe('inline', function () {
done();
});
});
it('should inline sources from memory file system.', function (done) {
const test = '<script src="memory.js" inline ></script>';
const mfs = new MemoryFileSystem();
const memoryJs = 'console.log(123);';
mfs.mkdirpSync(process.cwd());
mfs.writeFileSync(process.cwd() + '/memory.js', memoryJs, 'utf8');

inline(test, { compress: true, fs: mfs }, function (err, html) {
expect(err).to.be(null);
expect(html).to.eql('<script>console.log(123);</script>');
done();
});
});
});

describe('sync', function () {
Expand Down