summaryrefslogtreecommitdiffstats
path: root/lib/models
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-06-06 17:16:53 +0200
committerSamy Pesse <samypesse@gmail.com>2016-06-06 17:16:53 +0200
commit29df73ba72cedc6ff66843dad59ffded9d4aa01b (patch)
tree8e9c77b6ff0eca6144e087a2851b294b84712b4b /lib/models
parentf8676483c1cd913d9788bc79f54e28d9c21bc79f (diff)
downloadgitbook-29df73ba72cedc6ff66843dad59ffded9d4aa01b.zip
gitbook-29df73ba72cedc6ff66843dad59ffded9d4aa01b.tar.gz
gitbook-29df73ba72cedc6ff66843dad59ffded9d4aa01b.tar.bz2
Add method "toText" to config
Diffstat (limited to 'lib/models')
-rw-r--r--lib/models/config.js109
1 files changed, 53 insertions, 56 deletions
diff --git a/lib/models/config.js b/lib/models/config.js
index 99b0f1a..00d2b47 100644
--- a/lib/models/config.js
+++ b/lib/models/config.js
@@ -19,21 +19,27 @@ Config.prototype.getValues = function() {
};
/**
- Change the file for the configuration
+ * Render config as text
+ * @return {Promise<String>}
+ */
+Config.prototype.toText = function() {
+ return JSON.stringify(this.getValues().toJS(), null, 4);
+};
- @param {File} file
- @return {Config}
-*/
+/**
+ * Change the file for the configuration
+ * @param {File} file
+ * @return {Config}
+ */
Config.prototype.setFile = function(file) {
return this.set('file', file);
};
/**
- Return a configuration value by its key path
-
- @param {String} key
- @return {Mixed}
-*/
+ * Return a configuration value by its key path
+ * @param {String} key
+ * @return {Mixed}
+ */
Config.prototype.getValue = function(keyPath, def) {
var values = this.getValues();
keyPath = Config.keyToKeyPath(keyPath);
@@ -46,12 +52,11 @@ Config.prototype.getValue = function(keyPath, def) {
};
/**
- Update a configuration value
-
- @param {String} key
- @param {Mixed} value
- @return {Config}
-*/
+ * Update a configuration value
+ * @param {String} key
+ * @param {Mixed} value
+ * @return {Config}
+ */
Config.prototype.setValue = function(keyPath, value) {
keyPath = Config.keyToKeyPath(keyPath);
@@ -64,10 +69,9 @@ Config.prototype.setValue = function(keyPath, value) {
};
/**
- Return a list of plugin dependencies
-
- @return {List<PluginDependency>}
-*/
+ * Return a list of plugin dependencies
+ * @return {List<PluginDependency>}
+ */
Config.prototype.getPluginDependencies = function() {
var plugins = this.getValue('plugins');
@@ -79,11 +83,10 @@ Config.prototype.getPluginDependencies = function() {
};
/**
- Return a plugin dependency by its name
-
- @param {String} name
- @return {PluginDependency}
-*/
+ * Return a plugin dependency by its name
+ * @param {String} name
+ * @return {PluginDependency}
+ */
Config.prototype.getPluginDependency = function(name) {
var plugins = this.getPluginDependencies();
@@ -93,11 +96,10 @@ Config.prototype.getPluginDependency = function(name) {
};
/**
- Update the list of plugins dependencies
-
- @param {List<PluginDependency>}
- @return {Config}
-*/
+ * Update the list of plugins dependencies
+ * @param {List<PluginDependency>}
+ * @return {Config}
+ */
Config.prototype.setPluginDependencies = function(deps) {
var plugins = PluginDependency.listToArray(deps);
@@ -106,11 +108,10 @@ Config.prototype.setPluginDependencies = function(deps) {
/**
- Update values for an existing configuration
-
- @param {Object} values
- @returns {Config}
-*/
+ * Update values for an existing configuration
+ * @param {Object} values
+ * @returns {Config}
+ */
Config.prototype.updateValues = function(values) {
values = Immutable.fromJS(values);
@@ -118,12 +119,11 @@ Config.prototype.updateValues = function(values) {
};
/**
- Update values for an existing configuration
-
- @param {Config} config
- @param {Object} values
- @returns {Config}
-*/
+ * Update values for an existing configuration
+ * @param {Config} config
+ * @param {Object} values
+ * @returns {Config}
+ */
Config.prototype.mergeValues = function(values) {
var currentValues = this.getValues();
values = Immutable.fromJS(values);
@@ -134,12 +134,11 @@ Config.prototype.mergeValues = function(values) {
};
/**
- Create a new config for a file
-
- @param {File} file
- @param {Object} values
- @returns {Config}
-*/
+ * Create a new config for a file
+ * @param {File} file
+ * @param {Object} values
+ * @returns {Config}
+ */
Config.create = function(file, values) {
return new Config({
file: file,
@@ -148,11 +147,10 @@ Config.create = function(file, values) {
};
/**
- Create a new config
-
- @param {Object} values
- @returns {Config}
-*/
+ * Create a new config
+ * @param {Object} values
+ * @returns {Config}
+ */
Config.createWithValues = function(values) {
return new Config({
values: Immutable.fromJS(values)
@@ -161,11 +159,10 @@ Config.createWithValues = function(values) {
/**
- Convert a keyPath to an array of keys
-
- @param {String|Array}
- @return {Array}
-*/
+ * Convert a keyPath to an array of keys
+ * @param {String|Array}
+ * @return {Array}
+ */
Config.keyToKeyPath = function(keyPath) {
if (is.string(keyPath)) keyPath = keyPath.split('.');
return keyPath;