diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-05-12 11:15:13 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-05-12 11:15:13 +0200 |
commit | 8aa2f3075c81161746cd63a388ce0eddc536ac15 (patch) | |
tree | a33ac0df67023a69b985b650e3b33af7e12ae117 /lib/parse | |
parent | 839ee0385af2e6a9917826b07dd61c851244e6e0 (diff) | |
download | gitbook-8aa2f3075c81161746cd63a388ce0eddc536ac15.zip gitbook-8aa2f3075c81161746cd63a388ce0eddc536ac15.tar.gz gitbook-8aa2f3075c81161746cd63a388ce0eddc536ac15.tar.bz2 |
Fix #1294: multilingual book should extend the book's config
Diffstat (limited to 'lib/parse')
-rw-r--r-- | lib/parse/__tests__/parseBook.js | 35 | ||||
-rw-r--r-- | lib/parse/parseConfig.js | 16 |
2 files changed, 45 insertions, 6 deletions
diff --git a/lib/parse/__tests__/parseBook.js b/lib/parse/__tests__/parseBook.js index 912d32d..b1236c9 100644 --- a/lib/parse/__tests__/parseBook.js +++ b/lib/parse/__tests__/parseBook.js @@ -27,6 +27,41 @@ describe('parseBook', function() { }); }); + it('should extend configuration for multilingual book', function() { + var fs = createMockFS({ + 'LANGS.md': '# Languages\n\n* [en](en)\n* [fr](fr)', + 'book.json': '{ "title": "Test", "author": "GitBook" }', + 'en': { + 'README.md': 'Hello', + 'book.json': '{ "title": "Test EN" }' + }, + 'fr': { + 'README.md': 'Bonjour' + } + }); + var book = Book.createForFS(fs); + + return parseBook(book) + .then(function(resultBook) { + var books = resultBook.getBooks(); + + expect(resultBook.isMultilingual()).toBe(true); + expect(books.size).toBe(2); + + var en = books.get('en'); + var fr = books.get('fr'); + + var enConfig = en.getConfig(); + var frConfig = fr.getConfig(); + + expect(enConfig.getValue('title')).toBe('Test EN'); + expect(enConfig.getValue('author')).toBe('GitBook'); + + expect(frConfig.getValue('title')).toBe('Test'); + expect(frConfig.getValue('author')).toBe('GitBook'); + }); + }); + it('should parse book in a directory', function() { var fs = createMockFS({ 'book.json': JSON.stringify({ diff --git a/lib/parse/parseConfig.js b/lib/parse/parseConfig.js index 5200de2..39d57f0 100644 --- a/lib/parse/parseConfig.js +++ b/lib/parse/parseConfig.js @@ -1,7 +1,5 @@ var Promise = require('../utils/promise'); -var Config = require('../models/config'); -var File = require('../models/file'); var validateConfig = require('./validateConfig'); var CONFIG_FILES = require('../constants/configFiles'); @@ -13,6 +11,7 @@ var CONFIG_FILES = require('../constants/configFiles'); */ function parseConfig(book) { var fs = book.getFS(); + var config = book.getConfig(); return Promise.some(CONFIG_FILES, function(filename) { // Is this file ignored? @@ -38,13 +37,18 @@ function parseConfig(book) { }) .then(function(result) { - var file = result? result.file : File(); var values = result? result.values : {}; - values = validateConfig(values); - var config = Config.create(file, values); - return book.set('config', config); + // Set the file + if (result.file) { + config = config.setFile(result.file); + } + + // Merge with old values + config = config.mergeValues(values); + + return book.setConfig(config); }); } |