diff options
Diffstat (limited to 'lib/output')
-rw-r--r-- | lib/output/json/onPage.js | 19 | ||||
-rw-r--r-- | lib/output/modifiers/index.js | 11 | ||||
-rw-r--r-- | lib/output/modifiers/modifyHTML.js | 15 | ||||
-rw-r--r-- | lib/output/writer/index.js | 4 | ||||
-rw-r--r-- | lib/output/writer/writePage.js | 33 |
5 files changed, 70 insertions, 12 deletions
diff --git a/lib/output/json/onPage.js b/lib/output/json/onPage.js index 3ef5c74..a84e297 100644 --- a/lib/output/json/onPage.js +++ b/lib/output/json/onPage.js @@ -1,4 +1,6 @@ +var JSONUtils = require('../../json'); var Modifier = require('../modifier'); +var Writer = require('../writer'); /** Write a page as a json file @@ -7,13 +9,22 @@ var Modifier = require('../modifier'); @param {Page} page */ function onPage(output, page) { - var options = output. - - return Modifier.applyHTMLTransformations(page, [ + return Modifier.modifyHTML(page, [ Modifier.HTML.resolveLinks() ]) - .then(function(newPage) { + .then(function(resultPage) { + // Generate the JSON + var json = JSONUtils.encodeBookWithPage(output.getBook(), resultPage); + // Write it to the disk + return Writer.writePage( + output, + page, + JSON.stringify(json, null, 4), + { + extension: '.json' + } + ); }); } diff --git a/lib/output/modifiers/index.js b/lib/output/modifiers/index.js index 76ce3c2..ced8716 100644 --- a/lib/output/modifiers/index.js +++ b/lib/output/modifiers/index.js @@ -1,9 +1,4 @@ - -function modifyPage() { - - -} - - -module.exports = modifyPage; +module.exports = { + modifyHTML: require('./modifyHTML') +}; diff --git a/lib/output/modifiers/modifyHTML.js b/lib/output/modifiers/modifyHTML.js new file mode 100644 index 0000000..c1dad74 --- /dev/null +++ b/lib/output/modifiers/modifyHTML.js @@ -0,0 +1,15 @@ + + +/** + Apply a list of operations to a page and + output the new page. + + @param {Page} + @param {List<Transformation>} +*/ +function modifyHTML(page, operations) { + +} + + +module.exports = modifyHTML; diff --git a/lib/output/writer/index.js b/lib/output/writer/index.js new file mode 100644 index 0000000..2ef3364 --- /dev/null +++ b/lib/output/writer/index.js @@ -0,0 +1,4 @@ + +module.exports = { + writePage: require('./writePage') +}; diff --git a/lib/output/writer/writePage.js b/lib/output/writer/writePage.js new file mode 100644 index 0000000..23e37d0 --- /dev/null +++ b/lib/output/writer/writePage.js @@ -0,0 +1,33 @@ +var path = require('path'); +var Immutable = require('immutable'); + +var fs = require('../../utils/fs'); +var PathUtils = require('../../utils/path'); + +var WriteOptions = Immutable.Record({ + extension: '.html' +}); + +/** + Write a file to the output folder + + @param {Output} output + @param {Page} page + @param {Buffer|String} content + @return {Promise} +*/ +function writePage(output, page, content, options) { + var file = page.getFile(); + var outputOpts = output.getOptions(); + var rootFolder = outputOpts.get('root'); + + options = WriteOptions(options); + + // Get filename for file to write + var fileName = PathUtils.setExtension(file.getPath(), options.get('extension')); + var filePath = path.join(rootFolder, fileName); + + return fs.writeFile(filePath, content); +} + +module.exports = writePage; |