diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/models/output.js | 27 | ||||
-rw-r--r-- | lib/output/ebook/index.js | 12 | ||||
-rw-r--r-- | lib/output/ebook/onFinish.js | 19 | ||||
-rw-r--r-- | lib/output/ebook/onInit.js | 21 | ||||
-rw-r--r-- | lib/output/ebook/onPage.js | 8 | ||||
-rw-r--r-- | lib/output/modifiers/__tests__/fetchRemoteImages.js | 25 | ||||
-rw-r--r-- | lib/output/modifiers/__tests__/svgToImg.js | 25 | ||||
-rw-r--r-- | lib/output/website/createTemplateEngine.js | 1 | ||||
-rw-r--r-- | lib/output/website/onPage.js | 2 |
9 files changed, 121 insertions, 19 deletions
diff --git a/lib/models/output.js b/lib/models/output.js index c11017e..43e36f8 100644 --- a/lib/models/output.js +++ b/lib/models/output.js @@ -62,23 +62,32 @@ Output.prototype.getRoot = function() { }; /** - Return logegr for this output (same as book) + Update state of output - @return {Logger} + @param {Map} newState + @return {Output} */ -Output.prototype.getLogger = function() { - return this.getBook().getLogger(); +Output.prototype.setState = function(newState) { + return this.set('state', newState); }; /** - Update state of output + Update options - @param {Output} output - @param {Map} newState + @param {Map} newOptions @return {Output} */ -Output.updateState = function(output, newState) { - return output.set('state', newState); +Output.prototype.setOptions = function(newOptions) { + return this.set('options', newOptions); +}; + +/** + Return logegr for this output (same as book) + + @return {Logger} +*/ +Output.prototype.getLogger = function() { + return this.getBook().getLogger(); }; module.exports = Output; diff --git a/lib/output/ebook/index.js b/lib/output/ebook/index.js index 46a94e3..3aaa7e7 100644 --- a/lib/output/ebook/index.js +++ b/lib/output/ebook/index.js @@ -1,5 +1,9 @@ +var extend = require('extend'); +var websiteGenerator = require('../website'); -module.exports = { - - -}; +module.exports = extend({}, websiteGenerator, { + name: 'ebook', + onInit: require('./onInit'), + onPage: require('./onPage'), + onFinish: require('./onFinish') +}); diff --git a/lib/output/ebook/onFinish.js b/lib/output/ebook/onFinish.js new file mode 100644 index 0000000..5ea5148 --- /dev/null +++ b/lib/output/ebook/onFinish.js @@ -0,0 +1,19 @@ +var websiteGenerator = require('../website'); + +/** + Finish the generation, generate the ebook file using ebook-convert + + @param {Output} + @return {Output} +*/ +function onFinish(output) { + return websiteGenerator.onFinish(output) + .then(function(resultOutput) { + + // todo + + return resultOutput; + }); +} + +module.exports = onFinish; diff --git a/lib/output/ebook/onInit.js b/lib/output/ebook/onInit.js new file mode 100644 index 0000000..9cee141 --- /dev/null +++ b/lib/output/ebook/onInit.js @@ -0,0 +1,21 @@ +var websiteGenerator = require('../website'); + +/** + Initialize the generator + + @param {Output} + @return {Output} +*/ +function onInit(output) { + return websiteGenerator.onInit(output) + .then(function(resultOutput) { + var options = resultOutput.getOptions(); + + options = options.set('directoryIndex', false); + options = options.set('prefix', 'ebook'); + + return resultOutput.setOptions(options); + }); +} + +module.exports = onInit; diff --git a/lib/output/ebook/onPage.js b/lib/output/ebook/onPage.js index ab15133..13edf17 100644 --- a/lib/output/ebook/onPage.js +++ b/lib/output/ebook/onPage.js @@ -1,18 +1,18 @@ var website = require('../website'); -var Modifier = require('../modifier'); +var Modifiers = require('../modifiers'); /** Write a page for ebook output @param {Output} output - @param {Page} page + @param {Output} */ function onPage(output, page) { var options = output.getOptions(); // Inline assets - return Modifier.modifyHTML(page, [ - Modifier.inlineAssets(options.get('root')) + return Modifiers.modifyHTML(page, [ + Modifiers.inlineAssets(options.get('root')) ]) // Write page using website generator diff --git a/lib/output/modifiers/__tests__/fetchRemoteImages.js b/lib/output/modifiers/__tests__/fetchRemoteImages.js new file mode 100644 index 0000000..543aca0 --- /dev/null +++ b/lib/output/modifiers/__tests__/fetchRemoteImages.js @@ -0,0 +1,25 @@ +var cheerio = require('cheerio'); +var tmp = require('tmp'); + +describe('fetchRemoteImages', function() { + var dir; + var fetchRemoteImages = require('../fetchRemoteImages'); + + beforeEach(function() { + dir = tmp.dirSync(); + }); + + pit('should download image file', function() { + var $ = cheerio.load('<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png" />'); + + return fetchRemoteImages(dir.name, $) + .then(function() { + var $img = $('img'); + var src = '.' + $img.attr('src'); + + expect(dir.name).toHaveFile(src); + }); + }); +}); + + diff --git a/lib/output/modifiers/__tests__/svgToImg.js b/lib/output/modifiers/__tests__/svgToImg.js new file mode 100644 index 0000000..762a02e --- /dev/null +++ b/lib/output/modifiers/__tests__/svgToImg.js @@ -0,0 +1,25 @@ +var cheerio = require('cheerio'); +var tmp = require('tmp'); + +describe('svgToImg', function() { + var dir; + var svgToImg = require('../svgToImg'); + + beforeEach(function() { + dir = tmp.dirSync(); + }); + + pit('should write svg as a file', function() { + var $ = cheerio.load('<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" version="1.1"><rect width="200" height="100" stroke="black" stroke-width="6" fill="green"/></svg>'); + + return svgToImg(dir.name, $) + .then(function() { + var $img = $('img'); + var src = '.' + $img.attr('src'); + + expect(dir.name).toHaveFile(src); + }); + }); +}); + + diff --git a/lib/output/website/createTemplateEngine.js b/lib/output/website/createTemplateEngine.js index 7d87248..24990b6 100644 --- a/lib/output/website/createTemplateEngine.js +++ b/lib/output/website/createTemplateEngine.js @@ -35,7 +35,6 @@ function createTemplateEngine(output, currentFile) { var i18n = state.getI18n(); var config = book.getConfig(); var summary = book.getSummary(); - var pages = output.getPages(); var outputFolder = output.getRoot(); // Search paths for templates diff --git a/lib/output/website/onPage.js b/lib/output/website/onPage.js index ddae986..751a430 100644 --- a/lib/output/website/onPage.js +++ b/lib/output/website/onPage.js @@ -53,7 +53,7 @@ function onPage(output, page) { gitbook: context.gitbook, basePath: basePath, book: { - language: null // context.book.language + language: book.getLanguage() } }; } |