diff options
| author | Michael Williamson <mike@zwobble.org> | 2013-04-18 20:07:23 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2013-04-18 20:07:23 +0100 |
| commit | 554e939ed6f3ce697fca925a333cb9fc14ccbe5a (patch) | |
| tree | a777f5c2fb2b67066196951a7d954c16c6ba12fd /lib | |
| parent | 58d57f995fcf2077c3c4147dfc637cb1759de98b (diff) | |
Return Result from document-to-HTML conversion
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/document-to-html.js | 5 | ||||
| -rw-r--r-- | lib/index.js | 5 | ||||
| -rw-r--r-- | lib/results.js | 6 |
3 files changed, 6 insertions, 10 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js index 64672ee..ef39da8 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -3,6 +3,7 @@ var async = require("async"); var htmlPaths = require("./html-paths"); var HtmlGenerator = require("./html-generator").HtmlGenerator; +var results = require("./results"); exports.DocumentConverter = DocumentConverter; @@ -20,9 +21,7 @@ function DocumentConverter(options) { return q.nfcall(elementToHtml, document, html).then(function() { html.closeAll(); - return { - html: html.asString() - }; + return new results.Result(html.asString(), []); }); } diff --git a/lib/index.js b/lib/index.js index fb734e6..2a772bb 100644 --- a/lib/index.js +++ b/lib/index.js @@ -20,11 +20,8 @@ Converter.prototype.convertToHtml = function(inputOptions) { var documentConverter = this._documentConverter; return docxReader.read(inputOptions) .then(function(documentResult) { - return documentResult.mapThen(function(document) { + return documentResult.flatMapThen(function(document) { return documentConverter.convertToHtml(document); }); - }).then(function(result) { - result.html = result.value.html; - return result; }); } diff --git a/lib/results.js b/lib/results.js index 5bd81c0..d5dd7af 100644 --- a/lib/results.js +++ b/lib/results.js @@ -11,10 +11,10 @@ Result.prototype.map = function(func) { return new Result(func(this.value), this.messages); }; -Result.prototype.mapThen = function(func) { +Result.prototype.flatMapThen = function(func) { var messages = this.messages; - return func(this.value).then(function(resultValue) { - return new Result(resultValue, messages); + return func(this.value).then(function(otherResult) { + return new Result(otherResult.value, messages.concat(otherResult.messages)); }); }; |
