Skip to content

Commit

Permalink
feat(main): expose preformatted data in formatAll
Browse files Browse the repository at this point in the history
  • Loading branch information
voxpelli committed Jul 21, 2015
1 parent 4c8b007 commit f0fd23f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions index.js
Expand Up @@ -252,6 +252,7 @@ Formatter.prototype.formatAll = function (data) {
that.formatURL(formattedData, that.relativeTo),
that.format(formattedData),
formattedData.files,
formattedData,
]);
})
.then(function (result) {
Expand All @@ -260,6 +261,7 @@ Formatter.prototype.formatAll = function (data) {
url: result[1],
content: result[2],
files: result[3],
raw: result[4],
};
});
};
Expand Down
31 changes: 24 additions & 7 deletions test/formatter.spec.js
Expand Up @@ -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,
}
]
};
Expand All @@ -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/',
Expand All @@ -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'],
}

});
});

Expand Down

0 comments on commit f0fd23f

Please sign in to comment.