diff --git a/README.md b/README.md index 676024f..abfda8e 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ formatter.preFormat(micropubDocument) ## Methods -* **formatAll(micropubDocument)** – `preFormat`:s and formats everything. Returns a `Promise`that resolves to an object with the keys `filename`, `url`, `content` and `files`. +* **formatAll(micropubDocument)** – `preFormat`:s and formats everything. Returns a `Promise`that resolves to an object with the keys `filename`, `url`, `content`, `files` and `raw`. * **preFormat(micropubDocument)** – takes a `micropubDocument` and ensures that all necessary parts are there. **Currently required** to run a `micropubDocument` through this method before handing it to the rest of the methods (except `formatAll()`). * **formatFilename(preformattedMicropubDocument)** – returns a filename based on the data in the `micropubDocument`. Includes the relative path to the file – which currently is always `_posts/` * **formatURL(preformattedMicropubDocument)** – returns the url the formatted content is expected to live on when published diff --git a/index.js b/index.js index 59fe54f..c33a674 100644 --- a/index.js +++ b/index.js @@ -252,6 +252,7 @@ Formatter.prototype.formatAll = function (data) { that.formatURL(formattedData, that.relativeTo), that.format(formattedData), formattedData.files, + formattedData, ]); }) .then(function (result) { @@ -260,6 +261,7 @@ Formatter.prototype.formatAll = function (data) { url: result[1], content: result[2], files: result[3], + raw: result[4], }; }); }; diff --git a/test/formatter.spec.js b/test/formatter.spec.js index 0987042..b26cfef 100644 --- a/test/formatter.spec.js +++ b/test/formatter.spec.js @@ -420,11 +420,13 @@ describe('Formatter', function () { describe('formatAll', function () { it('should format everything correctly', function () { + var photoBuffer = new Buffer('sampledata'); + baseMicroformatData.files = { photo: [ { filename: 'bar.png', - buffer: new Buffer('sampledata') + buffer: photoBuffer, } ] }; @@ -433,7 +435,7 @@ describe('Formatter', function () { return formatter.formatAll(baseMicroformatData, 'http://example.com/bar/') .should.eventually - .have.all.keys('filename', 'url', 'content', 'files') + .have.all.keys('filename', 'url', 'content', 'files', 'raw') .that.deep.equals({ filename: '_posts/2015-06-30-awesomeness-is-awesome.md', url: 'http://example.com/bar/2015/06/awesomeness-is-awesome/', @@ -446,12 +448,27 @@ describe('Formatter', function () { ' - \'http://example.com/bar/media/2015-06-awesomeness-is-awesome/bar.png\'\n' + '---\n' + 'hello world\n', - files: [ - { + files: [{ + filename: 'media/2015-06-awesomeness-is-awesome/bar.png', + buffer: photoBuffer, + }], + raw: { + derived: {}, + files: [{ filename: 'media/2015-06-awesomeness-is-awesome/bar.png', - buffer: new Buffer('sampledata'), - } - ], + buffer: photoBuffer, + }], + preFormatted: true, + properties: { + content: ['hello world'], + name: ['awesomeness is awesome'], + photo: ['http://example.com/bar/media/2015-06-awesomeness-is-awesome/bar.png'], + published: [new Date(1435674841000)], + slug: ['awesomeness-is-awesome'], + }, + type: ['h-entry'], + } + }); });