diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-06-07 10:26:28 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-06-07 10:26:28 +0200 |
commit | 7178ab1f82616862edb3a53291aef155be66a4b7 (patch) | |
tree | 9a92d268eb3020cab29c68d257629beb6d1e2ac2 /lib/models | |
parent | bf895b707e6cc4ca5fdf4ade5bb9235f1b1b99ca (diff) | |
download | gitbook-7178ab1f82616862edb3a53291aef155be66a4b7.zip gitbook-7178ab1f82616862edb3a53291aef155be66a4b7.tar.gz gitbook-7178ab1f82616862edb3a53291aef155be66a4b7.tar.bz2 |
Improve Config.toText to return only the required fields
Diffstat (limited to 'lib/models')
-rw-r--r-- | lib/models/__tests__/config.js | 30 | ||||
-rw-r--r-- | lib/models/config.js | 12 |
2 files changed, 41 insertions, 1 deletions
diff --git a/lib/models/__tests__/config.js b/lib/models/__tests__/config.js index ff04ffd..abad754 100644 --- a/lib/models/__tests__/config.js +++ b/lib/models/__tests__/config.js @@ -55,6 +55,36 @@ describe('Config', function() { expect(world).toBe(2); }); }); + + describe('toReducedVersion', function() { + it('must only return diffs for simple values', function() { + var _config = Config.createWithValues({ + gitbook: '3.0.0' + }); + + var reducedVersion = _config.toReducedVersion(); + + expect(reducedVersion.toJS()).toEqual({ + gitbook: '3.0.0' + }); + }); + + it('must only return diffs for deep values', function() { + var _config = Config.createWithValues({ + structure: { + readme: 'intro.md' + } + }); + + var reducedVersion = _config.toReducedVersion(); + + expect(reducedVersion.toJS()).toEqual({ + structure: { + readme: 'intro.md' + } + }); + }); + }); }); diff --git a/lib/models/config.js b/lib/models/config.js index 00d2b47..6de52f9 100644 --- a/lib/models/config.js +++ b/lib/models/config.js @@ -4,6 +4,7 @@ var Immutable = require('immutable'); var File = require('./file'); var PluginDependency = require('./pluginDependency'); var configDefault = require('../constants/configDefault'); +var reducedObject = require('../utils/reducedObject'); var Config = Immutable.Record({ file: File(), @@ -19,11 +20,20 @@ Config.prototype.getValues = function() { }; /** + * Return minimum version of configuration, + * Basically it returns the current config minus the default one + * @return {Map} + */ +Config.prototype.toReducedVersion = function() { + return reducedObject(configDefault, this.getValues()); +}; + +/** * Render config as text * @return {Promise<String>} */ Config.prototype.toText = function() { - return JSON.stringify(this.getValues().toJS(), null, 4); + return JSON.stringify(this.toReducedVersion().toJS(), null, 4); }; /** |